I'm compiling a static executable like this:
ld.lld out/main.o -o out/sm -Tstatic.ld -static
strip --strip-all out/sm
This is the linker script I'm using:
ENTRY(_start)
SECTIONS
{
. = 0x100e8;
.all : {
*(.bss*)
*(.text*)
*(.data*)
*(.rodata*)
*(COMMON*)
} :code
.shstrtab : {
*(.shstrtab)
}
/DISCARD/ : {
*(*)
}
}
PHDRS
{
code PT_LOAD FILEHDR PHDRS ;
}
The executable works as expected, but the strip command doesn't remove .shstrtab
section from the executable.
If I remove the .shstrtab
section from the linker script, I get this error:
ld.lld out/main.o -o out/.sm -Tstatic.ld -static
ld.lld: error: discarding .shstrtab section is not allowed
Why is the .shstrtab
section necessary? I've replaced all the standard section names and the executable still works as expected, so the program loading code doesn't care about the section names.
As an aside, is it possible to completely exclude the section headers in a linker script, since it isn't needed for a static executable.
note: GNU linkers silently put .shstrtab
in the output executable even if it is discarded.