View source code
Display the source code in dmd/backend/elfobj.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Module dmd.backend.elfobj

Output to ELF object files



Compiler implementation of the D programming language.


addSegmentToComdat(seg, comdatseg)
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.
elf_dwarf_reftoident(seg, offset, s, val) Generate fixup specific to .eh_frame and .gcc_except_table sections.
elf_renumbersyms() Renumber symbols so they are ordered as locals, weak and then global
ElfObj_addstr(strtab, str) Output a string into a string table
ElfObj_alias(n1, n2) Output an alias definition record.
ElfObj_allowZeroSize() Do we allow zero sized objects?
ElfObj_byte(seg, offset, byte_) Output byte to object file.
ElfObj_bytes(seg, offset, nbytes, p) Output bytes to object file.
ElfObj_codeseg(name, suffix) Define a new code segment.
ElfObj_common_block(s, size, count) Output a common block definition.
ElfObj_compiler(p) Embed compiler version in .obj file.
ElfObj_data_readonly(p, len, pseg) Ouput read only data for data.
ElfObj_data_start(sdata, datasize, seg) Update data information about symbol align for output and assign segment if not already specified.
ElfObj_dehinfo(scc) Stuff pointer to DEH into its own section (deh).
ElfObj_ehsections() Don't need to generate section brackets, use _start_SEC/_stop_SEC instead.
ElfObj_ehtables(sfunc, size, ehsym) Stuff the following data in a separate segment: pointer to function pointer to ehsym length of function
ElfObj_exestr(p) Embed string in executable.
ElfObj_export_symbol(s, argsize) Export a function name.
ElfObj_external(s) Output an external for existing symbol.
ElfObj_external_def(name) Output an external symbol for name.
ElfObj_far16thunk(s) Generate far16 thunk.
ElfObj_filename(modname) Output file name record.
ElfObj_fltused() Mark object file as using floating point.
ElfObj_func_start(sfunc) Update function info before codgen
ElfObj_func_term(sfunc) Update function info after codgen
ElfObj_getsegment(name, suffix, type, flags, align_) Get corresponding seg_data entry for an existing or newly added section.
ElfObj_includelib(name) Output library name.
ElfObj_init(objbuf, filename, csegname) Perform initialization that applies to all .o output files. Called before any other obj_xxx routines Called by Obj.initialize()
ElfObj_initfile(filename, csegname, modname) Initialize the start of object output for this particular .o file. Called by Obj.initfile()
ElfObj_lidata(seg, offset, count) Output an iterated data block of 0s.
ElfObj_linkerdirective(name) Output linker directive.
ElfObj_linnum(srcpos, seg, offset) Line number support.
ElfObj_moduleinfo(scc) Stuff pointer to ModuleInfo into its own section (minfo).
ElfObj_pubdef(seg, s, offset) Output a public definition.
ElfObj_pubdefsize(seg, s, offset, symsize) Output a public definition.
ElfObj_reftocodeseg(seg, offset, 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.
ElfObj_reftodatseg(seg, offset, val, targetdatum, flags) Refer to address that is in the data segment.
ElfObj_reftoident(seg, offset, s, val, flags) Refer to an identifier.
ElfObj_setcodeseg(seg) Reset code seg to existing seg. Used after a COMDAT for a function is done.
ElfObj_setModuleCtorDtor(sfunc, isCtor) Stuff pointer to function in its own segment. Used for static ctor and dtor lists.
ElfObj_startaddress(s) Set start address
ElfObj_staticctor(s, __param_1, __param_2) Symbol is the function that calls the static constructors. Put a pointer to it into a special segment that the startup code looks at.
ElfObj_staticdtor(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.
ElfObj_string_literal_segment(sz) Get segment for readonly string literals. The linker will pool strings in this section.
ElfObj_sym_cdata(ty, p, len) Ouput read only data and generate a symbol for it.
ElfObj_term(objfilename) Finish up creating the object module and putting it in fobjbuf[]. Does not write the file. Pairs with ElfObj_init()
ElfObj_termfile() Fixup and terminate object file. Pairs with ElfObj_initfile()
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.**) } .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.
ElfObj_tlsseg_bss() Define segments for Thread Local Storage.
ElfObj_user(p) Embed string in obj.
ElfObj_wkext(s1, s2) Output a weak extern record.
ElfObj_write_byte(pseg, byte_) Append byte to segment.
ElfObj_write_bytes(pseg, a) Append bytes to segment.
ElfObj_write_zeros(pseg, count) Append an iterated data block of 0s. (uninitialized data only)
ElfObj_writerel(targseg, offset, reltype, symidx, val) Write/Append a relocatable value to the given segment and offset.
elfobjfile_delete() Close and delete .OBJ file.
elfobjfile_term() Terminate.
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.

Manifest constants

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

Global variables

relcnt int Output a relocation entry for a segment


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_


Walter Bright


Boost License 1.0