I have a Linux Ubuntu(20.04) machine with gcc and clang installed. I figured out the directory containing the default linker script:

/usr/lib/x86_64-linux-gnu/ldscripts$ ls
elf32_x86_64.x     elf32_x86_64.xsw   elf_i386.xr     elf_iamcu.xde   elf_k1om.xc    elf_k1om.xu    elf_l1om.xsc     elf_x86_64.xdwe  i386pep.xn
elf32_x86_64.xbn   elf32_x86_64.xswe  elf_i386.xs     elf_iamcu.xdw   elf_k1om.xce   elf_k1om.xw    elf_l1om.xsce    elf_x86_64.xe    i386pep.xr
elf32_x86_64.xc    elf32_x86_64.xu    elf_i386.xsc    elf_iamcu.xdwe  elf_k1om.xd    elf_k1om.xwe   elf_l1om.xse     elf_x86_64.xn    i386pep.xu
elf32_x86_64.xce   elf32_x86_64.xw    elf_i386.xsce   elf_iamcu.xe    elf_k1om.xdc   elf_l1om.x     elf_l1om.xsw     elf_x86_64.xr    i386pe.x
elf32_x86_64.xd    elf32_x86_64.xwe   elf_i386.xse    elf_iamcu.xn    elf_k1om.xdce  elf_l1om.xbn   elf_l1om.xswe    elf_x86_64.xs    i386pe.xa
elf32_x86_64.xdc   elf_i386.x         elf_i386.xsw    elf_iamcu.xr    elf_k1om.xde   elf_l1om.xc    elf_l1om.xu      elf_x86_64.xsc   i386pe.xbn
elf32_x86_64.xdce  elf_i386.xbn       elf_i386.xswe   elf_iamcu.xs    elf_k1om.xdw   elf_l1om.xce   elf_l1om.xw      elf_x86_64.xsce  i386pe.xe
elf32_x86_64.xde   elf_i386.xc        elf_i386.xu     elf_iamcu.xsc   elf_k1om.xdwe  elf_l1om.xd    elf_l1om.xwe     elf_x86_64.xse   i386pe.xn
elf32_x86_64.xdw   elf_i386.xce       elf_i386.xw     elf_iamcu.xsce  elf_k1om.xe    elf_l1om.xdc   elf_x86_64.x     elf_x86_64.xsw   i386pe.xr
elf32_x86_64.xdwe  elf_i386.xd        elf_i386.xwe    elf_iamcu.xse   elf_k1om.xn    elf_l1om.xdce  elf_x86_64.xbn   elf_x86_64.xswe  i386pe.xu
elf32_x86_64.xe    elf_i386.xdc       elf_iamcu.x     elf_iamcu.xsw   elf_k1om.xr    elf_l1om.xde   elf_x86_64.xc    elf_x86_64.xu
elf32_x86_64.xn    elf_i386.xdce      elf_iamcu.xbn   elf_iamcu.xswe  elf_k1om.xs    elf_l1om.xdw   elf_x86_64.xce   elf_x86_64.xw
elf32_x86_64.xr    elf_i386.xde       elf_iamcu.xc    elf_iamcu.xu    elf_k1om.xsc   elf_l1om.xdwe  elf_x86_64.xd    elf_x86_64.xwe
elf32_x86_64.xs    elf_i386.xdw       elf_iamcu.xce   elf_iamcu.xw    elf_k1om.xsce  elf_l1om.xe    elf_x86_64.xdc   i386pep.x
elf32_x86_64.xsc   elf_i386.xdwe      elf_iamcu.xd    elf_iamcu.xwe   elf_k1om.xse   elf_l1om.xn    elf_x86_64.xdce  i386pep.xa
elf32_x86_64.xsce  elf_i386.xe        elf_iamcu.xdc   elf_k1om.x      elf_k1om.xsw   elf_l1om.xr    elf_x86_64.xde   i386pep.xbn
elf32_x86_64.xse   elf_i386.xn        elf_iamcu.xdce  elf_k1om.xbn    elf_k1om.xswe  elf_l1om.xs    elf_x86_64.xdw   i386pep.xe
  • Can someone explain what is with the extension .x , .xdw , .xe, etc ? What do they tell about the linker script and why do they exist ?

  • How does the default linker script know the sections it must amalgamate ? Is there any documentation/consortium of sort where people gather to identify the list of sections an elf file must contain ? Put it other way: how was it determined that these are the sections any elf based executable/library must have on a Linux system ? I get the .data, .text, .bss but what about the other sections(debug, interp, ini, fini, hash, ctors, dtors, ldata, lbss, stab, etc..) I see listed, who decided to put them in, for what purpose and where is it documented ? Where is the official list of the purpose of each section ?

  • What is the definition of a well formed elf binary ?

  • For lld the linker provided by clang, why is there no list of default linker scripts ? When I compile a simple C program using the lld linker with verbose output I do NOT see the default linker script used as shown when using the ld.

clang main.c -fuse-ld=lld -Wl,--verbose
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crt1.o
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o
ld.lld: /tmp/main-bafb70.o
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/libgcc.a
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/libgcc_s.so
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libgcc_s.so.1
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/libgcc.a
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libc.so
ld.lld: /lib/x86_64-linux-gnu/libc.so.6
ld.lld: /usr/lib/x86_64-linux-gnu/libc_nonshared.a
ld.lld: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/libgcc.a
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/libgcc_s.so
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libgcc_s.so.1
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/libgcc.a
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtend.o
ld.lld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o


$clang main.c -fuse-ld=ld -Wl,--verbose

GNU ld (GNU Binutils for Ubuntu) 2.34
  Supported emulations:
using internal linker script:
/* Script for -z combreloc -z separate-code */
/* Copyright (C) 2014-2020 Free Software Foundation, Inc.
   Copying and distribution of this script, with or without modification,
   are permitted in any medium without royalty provided the copyright
   notice and this notice are preserved.  */
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64",
SEARCH_DIR("=/usr/local/lib/x86_64-linux-gnu"); SEARCH_DIR("=/lib/x86_64-linux-gnu"); SEARCH_DIR("=/usr/lib/x86_64-linux-gnu"); SEARCH_DIR("=/usr/lib/x86_64-linux-gnu64"); SEARCH_DIR("=/usr/local/lib64"); SEARCH_DIR("=/lib64"); SEARCH_DIR("=/usr/lib64"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib"); SEARCH_DIR("=/usr/x86_64-linux-gnu/lib64"); SEARCH_DIR("=/usr/x86_64-linux-gnu/lib");
  PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;
  .interp         : { *(.interp) }
  .note.gnu.build-id  : { *(.note.gnu.build-id) }
  .hash           : { *(.hash) }
  .gnu.hash       : { *(.gnu.hash) }
  • Is the list of sections produced by clang vs gcc universally the same ? Is there any disparity ? Is the list of sections produced toolchain/platform/arch specific ? If so where can I get it from clang/gcc documentation ?
  • 1
    I wonder if this question would be more suitable for Retrocomputing SE...
    – Igor Skochinsky
    Commented Sep 17, 2023 at 16:19
  • Hi and welcome to RE.SE. lld is a completely different beast compared to ld. So are gold and mold. There are overlaps in functionality, but they have quite different internals. Just like clang is always a cross-compiler by default, while for GCC things are quite different and usually specific toolchains have to be built to target different platforms/architectures. You should check out the binutils source if you really want to delve in. You may also want to split up your questions by topic instead of cramming everything into a single "question".
    – 0xC0000022L
    Commented Sep 22, 2023 at 23:02


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.