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

Compiler implementation of the D programming language.

Functions

NameDescription
addSegmentToComdat(seg, comdatseg)
dwarf_reftoident(seg, offset, s, val) Generate fixup specific to .eh_frame and .gcc_except_table sections.
elf_align(size, foffset) Write to the object file
elf_renumbersyms() Renumber symbols so they are ordered as locals, weak and then global
Obj_addstr(strtab, str) Output a string into a string table
Obj_alias(n1, n2) Output an alias definition record.
Obj_allowZeroSize() Do we allow zero sized objects?
Obj_byte(seg, offset, byte_) Output byte to object file.
Obj_bytes(seg, offset, nbytes, p) Output bytes to object file.
Obj_codeseg(name, suffix) Define a new code segment.
Obj_common_block(s, size, count) Output a common block definition.
Obj_compiler() Embed compiler version in .obj file.
Obj_data_readonly(p, len, pseg) Ouput read only data for data.
Obj_data_start(sdata, datasize, seg) Update data information about symbol align for output and assign segment if not already specified.
Obj_ehsections() Don't need to generate section brackets, use _start_SEC/_stop_SEC instead.
Obj_ehtables(sfunc, size, ehsym) Stuff the following data in a separate segment: pointer to function pointer to ehsym length of function
Obj_exestr(p) Embed string in executable.
Obj_export_symbol(s, argsize) Export a function name.
Obj_external(s) Output an external for existing symbol.
Obj_external_def(name) Output an external symbol for name.
Obj_far16thunk(s) Generate far16 thunk.
obj_filename(modname) Output file name record.
Obj_fltused() Mark object file as using floating point.
Obj_func_start(sfunc) Update function info before codgen
Obj_func_term(sfunc) Update function info after codgen
Obj_getsegment(name, suffix, type, flags, align_) Get corresponding seg_data entry for an existing or newly added section.
Obj_gotref(s)
Obj_includelib(name) Output library name.
Obj_init(objbuf, filename, csegname) Perform initialization that applies to all .o output files. Called before any other obj_xxx routines
Obj_initfile(filename, csegname, modname) Initialize the start of object output for this particular .o file.
Obj_lidata(seg, offset, count) Output an iterated data block of 0s.
Obj_linkerdirective(name) Output linker directive.
Obj_linnum(srcpos, seg, offset) Line number support.
obj_mangle2(s, dest, destlen) Mangle a name.
Obj_moduleinfo(scc) Stuff pointer to ModuleInfo into its own section (minfo).
Obj_pubdef(seg, s, offset) Output a public definition.
Obj_pubdefsize(seg, s, offset, symsize) Output a public definition.
Obj_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.
Obj_reftodatseg(seg, offset, val, targetdatum, flags) Refer to address that is in the data segment.
Obj_reftoident(seg, offset, s, val, flags) Refer to an identifier.
Obj_setcodeseg(seg) Reset code seg to existing seg. Used after a COMDAT for a function is done.
Obj_setModuleCtorDtor(sfunc, isCtor) Stuff pointer to function in its own segment. Used for static ctor and dtor lists.
Obj_startaddress(s) Set start address
Obj_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.
Obj_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.
Obj_string_literal_segment(sz) Get segment for readonly string literals. The linker will pool strings in this section.
Obj_sym_cdata(ty, p, len) Ouput read only data and generate a symbol for it.
Obj_term(objfilename) Terminate package.
Obj_termfile() Fixup and terminate object file.
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.
Obj_tlsseg_bss() Define segments for Thread Local Storage.
Obj_user(p) Embed string in obj.
Obj_wkext(s1, s2) Output a weak extern record.
Obj_write_byte(pseg, byte_) Append byte to segment.
Obj_write_bytes(pseg, nbytes, p) Append bytes to segment.
Obj_write_zeros(pseg, count) Append an iterated data block of 0s. (uninitialized data only)
Obj_writerel(targseg, offset, reltype, symidx, val) Write/Append a relocatable value to the given segment and offset.
objfile_delete() Close and delete .OBJ file.
objfile_term() Terminate.

Manifest constants

NameTypeDescription
DMDV2 If set the compiler requires full druntime support of the new section registration.
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 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.

Global variables

NameTypeDescription
relcnt int Output a relocation entry for a segment

Aliases

NameTypeDescription
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_

Authors

Walter Bright

License

Boost License 1.0