dmd.backend.elfobj

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

Obj_addstr
IDXSTR Obj_addstr(Outbuffer* strtab, const(char)* str)

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

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

Output an alias definition record.

Obj_allowZeroSize
bool Obj_allowZeroSize()

Do we allow zero sized objects?

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

Output byte to object file.

Obj_bytes
uint Obj_bytes(int seg, targ_size_t offset, uint nbytes, void* p)

Output bytes to object file.

Obj_codeseg
int Obj_codeseg(const 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

Obj_common_block
int Obj_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

Obj_compiler
void Obj_compiler()

Embed compiler version in .obj file.

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

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

Obj_data_start
int Obj_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.

Obj_ehsections
void Obj_ehsections()

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

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

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

Obj_exestr
void Obj_exestr(const(char)* p)

Embed string in executable.

Obj_export_symbol
void Obj_export_symbol(Symbol* s, uint argsize)

Export a function name.

Obj_external
int Obj_external(Symbol* s)

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

Obj_external_def
int Obj_external_def(const(char)* name)

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

Obj_far16thunk
void Obj_far16thunk(Symbol* s)

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

Obj_fltused
void Obj_fltused()

Mark object file as using floating point.

Obj_func_start
void Obj_func_start(Symbol* sfunc)

Update function info before codgen

Obj_func_term
void Obj_func_term(Symbol* sfunc)

Update function info after codgen

Obj_getsegment
int Obj_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.

Obj_gotref
void Obj_gotref(Symbol* s)
Obj_includelib
bool Obj_includelib(const(char)* name)

Output library name.

Obj_init
Obj Obj_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

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

Initialize the start of object output for this particular .o file.

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

Output an iterated data block of 0s.

Obj_linkerdirective
bool Obj_linkerdirective(const(char)* name)

Output linker directive.

Obj_linnum
void Obj_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().

Obj_moduleinfo
void Obj_moduleinfo(Symbol* scc)

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

Obj_pubdef
void Obj_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

Obj_pubdefsize
void Obj_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

Obj_reftocodeseg
void Obj_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

Obj_reftodatseg
void Obj_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

Obj_reftoident
int Obj_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

Obj_setModuleCtorDtor
void Obj_setModuleCtorDtor(Symbol* sfunc, bool isCtor)

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

Obj_setcodeseg
void Obj_setcodeseg(int seg)

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

Obj_startaddress
void Obj_startaddress(Symbol* s)

Set start address

Obj_staticctor
void Obj_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

Obj_staticdtor
void Obj_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

Obj_string_literal_segment
int Obj_string_literal_segment(uint sz)

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

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

Ouput read only data and generate a symbol for it.

Obj_term
void Obj_term(const(char)* objfilename)

Terminate package.

Obj_termfile
void Obj_termfile()

Fixup and terminate object file.

Obj_tlsseg
seg_data* Obj_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.

Obj_tlsseg_bss
seg_data* Obj_tlsseg_bss()

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

Obj_user
void Obj_user(const(char)* p)

Embed string in obj.

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

Output a weak extern record.

Obj_write_byte
void Obj_write_byte(seg_data* pseg, uint byte_)

Append byte to segment.

Obj_write_bytes
void Obj_write_bytes(seg_data* pseg, uint nbytes, void* p)

Append bytes to segment.

Obj_write_zeros
void Obj_write_zeros(seg_data* pseg, targ_size_t count)

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

Obj_writerel
size_t Obj_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

addSegmentToComdat
void addSegmentToComdat(segidx_t seg, segidx_t comdatseg)
dwarf_reftoident
int 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_align
int elf_align(targ_size_t size, int foffset)

Write to the object file

elf_renumbersyms
void* elf_renumbersyms()

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

obj_filename
void obj_filename(const(char)* modname)

Output file name record.

obj_mangle2
char* obj_mangle2(Symbol* s, char* dest, size_t* destlen)

Mangle a name.

objfile_delete
void objfile_delete()

Close and delete .OBJ file.

objfile_term
void objfile_term()

Terminate.

Manifest constants

DMDV2
enum DMDV2;

If set the compiler requires full druntime support of the new section registration.

ELF_COMDAT
enum 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.

USE_INIT_ARRAY
enum 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.

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