2

How can I remove a section from ELF during linking stage? Is there any linker option or flag for this? I'm mostly interested on how it can be done with LLVM, but any information about GCC will be appreciated as well.

Thanks!

1 Answers1

0

If you want anything different from the default ELF construction--copy everything--then you will need to write a linker script. files can specify what to include and where to put it. So you would remove this section by not copying it. LLD supports GNU LD style linker scripts. They will look something like:

SECTIONS
{
  . = 0x10000;
  .text : { *(.text) }
  . = 0x8000000;
  .data : { *(.data) }
  .bss : { *(.bss) }
}

They are specified on the lld command line with something like: ld.lld --script=../linker_script xxx.o -o xxx

Olsonist
  • 2,051
  • 1
  • 20
  • 35