dmd.backend.elfobj

Output to ELF object files

http://www.sco.com/developers/gabi/2003-12-17/ch4.sheader.html

Compiler implementation of the D programming language.

Members

Aliases

reltype_t
alias reltype_t = uint

Correspondence of relocation types 386 32 bit in 64 64 in 64 R_386_32 R_X86_64_32 R_X86_64_64 R_386_GOTOFF R_X86_64_PC32 R_X86_64_ R_386_GOTPC R_X86_64_ R_X86_64_ R_386_GOT32 R_X86_64_ R_X86_64_ R_386_TLS_GD R_X86_64_TLSGD R_X86_64_ R_386_TLS_IE R_X86_64_GOTTPOFF R_X86_64_ R_386_TLS_LE R_X86_64_TPOFF32 R_X86_64_ R_386_PLT32 R_X86_64_PLT32 R_X86_64_ R_386_PC32 R_X86_64_PC32 R_X86_64_

Functions

ELF_COMDAT
bool ELF_COMDAT()

FreeBSD uses ELF, but the linker crashes with Elf comdats with the following message: /usr/bin/ld: BFD 2.15 FreeBSD 2004-05-23 internal error, aborting at /usr/src/gnu/usr.bin/binutils/libbfd/../../../../contrib/binutils/bfd/elfcode.h line 213 in bfd_elf32_swap_symbol_out For the time being, just stick with Linux.

ElfObj_addstr
IDXSTR ElfObj_addstr(OutBuffer* strtab, const(char)* str)

Output a string into a string table Input: strtab = string table for entry str = string to add

ElfObj_alias
void ElfObj_alias(const(char)* n1, const(char)* n2)

Output an alias definition record.

ElfObj_allowZeroSize
bool ElfObj_allowZeroSize()

Do we allow zero sized objects?

ElfObj_byte
void ElfObj_byte(int seg, targ_size_t offset, uint byte_)

Output byte to object file.

ElfObj_bytes
size_t ElfObj_bytes(int seg, targ_size_t offset, size_t nbytes, const(void)* p)

Output bytes to object file.

ElfObj_codeseg
int ElfObj_codeseg(char* name, int suffix)

Define a new code segment. Input: name name of segment, if null then revert to default suffix 0 use name as is 1 append "_TEXT" to name Output: cseg segment index of new current code segment Offset(cseg) starting offset in cseg

ElfObj_common_block
int ElfObj_common_block(Symbol* s, targ_size_t size, targ_size_t count)

Output a common block definition. Input: p . external identifier size size in bytes of each elem count number of elems

ElfObj_compiler
void ElfObj_compiler(const(char)* p)

Embed compiler version in .obj file.

ElfObj_data_readonly
int ElfObj_data_readonly(char* p, int len, int* pseg)

Ouput read only data for data. Output: *pseg segment of that data

ElfObj_data_start
int ElfObj_data_start(Symbol* sdata, targ_size_t datasize, int seg)

Update data information about symbol align for output and assign segment if not already specified.

ElfObj_dehinfo
void ElfObj_dehinfo(Symbol* scc)

Stuff pointer to DEH into its own section (deh).

ElfObj_ehsections
void ElfObj_ehsections()

Don't need to generate section brackets, use __start_SEC/__stop_SEC instead.

ElfObj_ehtables
void ElfObj_ehtables(Symbol* sfunc, uint size, Symbol* ehsym)

Stuff the following data in a separate segment: pointer to function pointer to ehsym length of function

ElfObj_exestr
void ElfObj_exestr(const(char)* p)

Embed string in executable.

ElfObj_export_symbol
void ElfObj_export_symbol(Symbol* s, uint argsize)

Export a function name.

ElfObj_external
int ElfObj_external(Symbol* s)

Output an external for existing symbol. Input: s Symbol to do EXTDEF on (Name is to be mangled)

ElfObj_external_def
int ElfObj_external_def(const(char)* name)

Output an external symbol for name. Input: name Name to do EXTDEF on (Not to be mangled)

ElfObj_far16thunk
void ElfObj_far16thunk(Symbol* s)

Generate far16 thunk. Input: s Symbol to generate a thunk for

ElfObj_filename
void ElfObj_filename(const(char)* modname)

Output file name record.

ElfObj_fltused
void ElfObj_fltused()

Mark object file as using floating point.

ElfObj_func_start
void ElfObj_func_start(Symbol* sfunc)

Update function info before codgen

ElfObj_func_term
void ElfObj_func_term(Symbol* sfunc)

Update function info after codgen

ElfObj_getsegment
segidx_t ElfObj_getsegment(const(char)* name, const(char)* suffix, int type, int flags, int align_)

Get corresponding seg_data entry for an existing or newly added section.

ElfObj_gotref
void ElfObj_gotref(Symbol* s)
ElfObj_includelib
bool ElfObj_includelib(char[] name)

Output library name.

ElfObj_init
Obj ElfObj_init(OutBuffer* objbuf, const(char)* filename, const(char)* csegname)

Perform initialization that applies to all .o output files. Called before any other obj_xxx routines Called by Obj.initialize()

ElfObj_initfile
void ElfObj_initfile(const(char)* filename, const(char)* csegname, const(char)* modname)

Initialize the start of object output for this particular .o file. Called by Obj.initfile()

ElfObj_lidata
void ElfObj_lidata(int seg, targ_size_t offset, targ_size_t count)

Output an iterated data block of 0s.

ElfObj_linkerdirective
bool ElfObj_linkerdirective(const(char)* name)

Output linker directive.

ElfObj_linnum
void ElfObj_linnum(Srcpos srcpos, int seg, targ_size_t offset)

Record file and line number at segment and offset. The actual .debug_line segment is put out by dwarf_termfile().

ElfObj_moduleinfo
void ElfObj_moduleinfo(Symbol* scc)

Stuff pointer to ModuleInfo into its own section (minfo).

ElfObj_pubdef
void ElfObj_pubdef(int seg, Symbol* s, targ_size_t offset)

Output a public definition. Input: seg = segment index that symbol is defined in s . symbol offset = offset of name within segment

ElfObj_pubdefsize
void ElfObj_pubdefsize(int seg, Symbol* s, targ_size_t offset, targ_size_t symsize)

Output a public definition. Input: seg = segment index that symbol is defined in s . symbol offset = offset of name within segment symsize size of symbol

ElfObj_reftocodeseg
void ElfObj_reftocodeseg(int seg, targ_size_t offset, targ_size_t val)

Refer to address that is in the code segment. Only offsets are output, regardless of the memory model. Used to put values in switch address tables. Input: seg = where the address is going (CODE or DATA) offset = offset within seg val = displacement from start of this module

ElfObj_reftodatseg
void ElfObj_reftodatseg(int seg, targ_size_t offset, targ_size_t val, uint targetdatum, int flags)

Refer to address that is in the data segment. Input: seg = where the address is going offset = offset within seg val = displacement from address targetdatum = DATA, CDATA or UDATA, depending where the address is flags = CFoff, CFseg, CFoffset64, CFswitch

ElfObj_reftoident
int ElfObj_reftoident(int seg, targ_size_t offset, Symbol* s, targ_size_t val, int flags)

Refer to an identifier. Input: segtyp = where the address is going (CODE or DATA) offset = offset within seg s = Symbol table entry for identifier val = displacement from identifier flags = CFselfrel: self-relative CFseg: get segment CFoff: get offset CFoffset64: 64 bit fixup CFpc32: I64: PC relative 32 bit fixup

ElfObj_setModuleCtorDtor
void ElfObj_setModuleCtorDtor(Symbol* sfunc, bool isCtor)

Stuff pointer to function in its own segment. Used for static ctor and dtor lists.

ElfObj_setcodeseg
void ElfObj_setcodeseg(int seg)

Reset code seg to existing seg. Used after a COMDAT for a function is done.

ElfObj_startaddress
void ElfObj_startaddress(Symbol* s)

Set start address

ElfObj_staticctor
void ElfObj_staticctor(Symbol* s, int , int )

Symbol is the function that calls the static constructors. Put a pointer to it into a special segment that the startup code looks at. Input: s static constructor function dtor !=0 if leave space for static destructor seg 1: user 2: lib 3: compiler

ElfObj_staticdtor
void ElfObj_staticdtor(Symbol* s)

Symbol is the function that calls the static destructors. Put a pointer to it into a special segment that the exit code looks at. Input: s static destructor function

ElfObj_string_literal_segment
int ElfObj_string_literal_segment(uint sz)

Get segment for readonly string literals. The linker will pool strings in this section.

ElfObj_sym_cdata
Symbol* ElfObj_sym_cdata(tym_t ty, char* p, int len)

Ouput read only data and generate a symbol for it.

ElfObj_term
void ElfObj_term(const(char)* objfilename)

Finish up creating the object module and putting it in fobjbuf[]. Does not write the file. Pairs with ElfObj_init()

ElfObj_termfile
void ElfObj_termfile()

Fixup and terminate object file. Pairs with ElfObj_initfile()

ElfObj_tlsseg
seg_data* ElfObj_tlsseg()

Define segments for Thread Local Storage. Here's what the elf tls spec says: Field .tbss .tdata sh_name .tbss .tdata sh_type SHT_NOBITS SHT_PROGBITS sh_flags SHF_ALLOC|SHF_WRITE| SHF_ALLOC|SHF_WRITE| SHF_TLS SHF_TLS sh_addr virtual addr of section virtual addr of section sh_offset 0 file offset of initialization image sh_size size of section size of section sh_link SHN_UNDEF SHN_UNDEF sh_info 0 0 sh_addralign alignment of section alignment of section sh_entsize 0 0 We want _tlsstart and _tlsend to bracket all the D tls data. The default linker script (ld -verbose) says: .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } so if we assign names: _tlsstart .tdata symbols .tdata. symbols .tbss _tlsend .tbss. this should work. Don't care about sections emitted by other languages, as we presume they won't be storing D gc roots in their tls. Output: seg_tlsseg set to segment number for TLS segment.

ElfObj_tlsseg_bss
seg_data* ElfObj_tlsseg_bss()

Define segments for Thread Local Storage. Output: seg_tlsseg_bss set to segment number for TLS segment.

ElfObj_user
void ElfObj_user(const(char)* p)

Embed string in obj.

ElfObj_wkext
void ElfObj_wkext(Symbol* s1, Symbol* s2)

Output a weak extern record.

ElfObj_write_byte
void ElfObj_write_byte(seg_data* pseg, uint byte_)

Append byte to segment.

ElfObj_write_bytes
void ElfObj_write_bytes(seg_data* pseg, const(void[]) a)

Append bytes to segment.

ElfObj_write_zeros
void ElfObj_write_zeros(seg_data* pseg, targ_size_t count)

Append an iterated data block of 0s. (uninitialized data only)

ElfObj_writerel
size_t ElfObj_writerel(int targseg, size_t offset, reltype_t reltype, IDXSYM symidx, targ_size_t val)

Write/Append a relocatable value to the given segment and offset. Input: targseg = the target segment for the relocation offset = offset within target segment reltype = ELF relocation type R_ARCH_XXXX symidx = symbol base for relocation val = addend or displacement from symbol

USE_INIT_ARRAY
bool USE_INIT_ARRAY()

If set, produce .init_array/.fini_array instead of legacy .ctors/.dtors . OpenBSD added the support in Aug 2016. Other supported platforms has supported .init_array for years.

addSegmentToComdat
void addSegmentToComdat(segidx_t seg, segidx_t comdatseg)
elf_dwarf_reftoident
int elf_dwarf_reftoident(int seg, targ_size_t offset, Symbol* s, targ_size_t val)

Generate fixup specific to .eh_frame and .gcc_except_table sections.

elf_renumbersyms
void* elf_renumbersyms()

Renumber symbols so they are ordered as locals, weak and then global

elfobjfile_delete
void elfobjfile_delete()

Close and delete .OBJ file.

elfobjfile_term
void elfobjfile_term()

Terminate.

Static variables

relcnt
int relcnt;

Output a relocation entry for a segment Input: seg = where the address is going offset = offset within seg type = ELF relocation type R_ARCH_XXXX index = Related symbol table index val = addend or displacement from address

Meta