v/vlib/compiler/x64/elf_obj.v

160 lines
2.4 KiB
V
Raw Normal View History

2020-02-03 05:00:36 +01:00
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
2019-11-19 07:53:52 +01:00
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module x64
/*
This file is unused right now, since binaries without sections
are generated.
But it will be necessary once we have dynamic linking.
*/
2019-12-19 22:29:37 +01:00
2019-11-19 07:53:52 +01:00
enum SectionType {
2019-12-20 00:35:07 +01:00
null = 0
progbits = 1
symtab = 2
strtab = 3
rela = 4
}
2019-11-19 07:53:52 +01:00
struct SectionConfig {
2019-12-19 22:29:37 +01:00
name string
typ SectionType
flags i64
data voidptr
is_saa bool
2019-11-19 07:53:52 +01:00
datalen i64
2019-12-19 22:29:37 +01:00
link int
info int
align i64
2019-11-19 07:53:52 +01:00
entsize i64
2019-12-19 22:29:37 +01:00
}
2019-11-19 07:53:52 +01:00
fn (g mut Gen) section_header(c SectionConfig) {
g.write32(g.sect_header_name_pos)
g.sect_header_name_pos += c.name.len + 1
g.write32(int(c.typ))
g.write64(c.flags)
g.write64(0) // sh_addr
2019-12-19 22:29:37 +01:00
g.write64(g.offset) // offset
g.offset += c.datalen + 1
2019-11-19 07:53:52 +01:00
g.write64(c.datalen)
g.write32(c.link)
g.write32(c.info)
g.write64(c.align)
g.write64(c.entsize)
2019-12-19 22:29:37 +01:00
}
2019-11-19 07:53:52 +01:00
fn genobj() {
/*
// SHN_UNDEF
mut g := Gen{}
nr_sections := 7
g.section_header(SectionConfig{
name: ''
typ: .null
flags:0
data: 0
is_saa: false
link: 0
info:0
align:0
entsize: 0
})
2019-12-20 00:35:07 +01:00
2019-11-19 07:53:52 +01:00
/*
for sect in sections {
g.section_header(SectionConfig{
name:0
typ: sect.typ
flags: sect.flags
data: sect.data
is_saa: true
datalen: sect.len
link: 0
info: 0
align: sect.align
entsize: sect.entsize
})
2019-12-20 00:35:07 +01:00
}
2019-11-19 07:53:52 +01:00
*/
2019-12-20 00:35:07 +01:00
2019-11-19 07:53:52 +01:00
g.section_header(SectionConfig{
name: '.DATA'
typ: .progbits
flags: 0x2
//data: sect.data
is_saa: true
datalen: 0xd
link: 0
info: 0
align: 1
entsize: 0
})
2019-12-20 00:35:07 +01:00
2019-11-19 07:53:52 +01:00
g.section_header(SectionConfig{
name: '.TEXT'
typ: .progbits
flags: 0x2
//data: sect.data
is_saa: true
datalen: 0xd
link: 0
info: 0
align: 1
entsize: 0
})
g.section_header(SectionConfig{
name: '.shstrtab'
typ: .strtab
flags: 0x2
//data: sect.data
is_saa: true
datalen: 0x22
link: 0
info: 0
align: 1
entsize: 0
})
g.section_header(SectionConfig{
name: '.symtab'
typ: .symtab
flags: 0x2
//data: sect.data
is_saa: true
datalen: 0xd
link: 0
info: 0
align: 1
entsize: 0
})
g.section_header(SectionConfig{
name: '.strtab'
typ: .symtab
flags: 0x2
//data: sect.data
is_saa: true
datalen: 0xd
link: 0
info: 0
align: 1
entsize: 0
})
g.section_header(SectionConfig{
name: '.rela.TEXT'
typ: .rela
flags: 0x0
//data: sect.data
is_saa: true
datalen: 0x18
link: 4
info: 2
align: 8
entsize: 0x18
})
*/
}
2019-12-19 22:29:37 +01:00