The .comment section added by lld should be removed and made optional. The file size using lld is unacceptable (some still use assembly) for embedded stuff. The default is 1200% larger by default and should be minimal like gnu ld. # /usr/local/bin/ld -s -o porcupine porcupine.o # ld --discard-all -o porcupine.lld -m elf_amd64_fbsd porcupine.o # strip porcupine.lld # objcopy --remove-section .comment porcupine.lld # ls -l porcupine porcupine.lld -rwxr-xr-x 1 root wheel 352 Apr 30 23:41 porcupine -rwxr-xr-x 1 root wheel 4320 Apr 30 23:41 porcupine.lld Specifying `-m elf_amd64_fbsd` or similar shouldn't be necessary and should be the default (depending on platform).
As you note you can remove .comment with objcopy, I suspect the lld authors will feel the complexity of a --comment / --no-comment or similar flag is warranted. lld is inherently a cross-platform linker and intentionally has no built-in default target. Normally the format is identified from the first object file - if your ELF .o has an EI_OSABI of FreeBSD the output will as well. Would you compare readelf -lS porcupine and porcupine.lld?
(In reply to Ed Maste from comment #1) The complexity is not warranted, rather.
# readelf -lS porcupine Elf file type is EXEC (Executable file) Entry point 0x400080 There are 1 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 0x000000000000009c 0x000000000000009c R E 0x200000 Section to Segment mapping: Segment Sections... 00 .text There are 3 section headers, starting at offset 0xb0: Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .text PROGBITS 0000000000400080 00000080 000000000000001c 0000000000000000 AX 0 0 16 [ 2] .shstrtab STRTAB 0000000000000000 0000009c 0000000000000011 0000000000000000 0 0 1 # readelf -lS porcupine.lld Elf file type is EXEC (Executable file) Entry point 0x201000 There are 4 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align PHDR 0x0000000000000040 0x0000000000200040 0x0000000000200040 0x00000000000000e0 0x00000000000000e0 R 0x8 LOAD 0x0000000000000000 0x0000000000200000 0x0000000000200000 0x0000000000000120 0x0000000000000120 R 0x1000 LOAD 0x0000000000001000 0x0000000000201000 0x0000000000201000 0x000000000000001c 0x000000000000001c R E 0x1000 GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 RW 0 Section to Segment mapping: Segment Sections... 00 01 02 .text 03 There are 3 section headers, starting at offset 0x1030: Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .text PROGBITS 0000000000201000 00001000 000000000000001c 0000000000000000 AX 0 0 16 [ 2] .shstrtab STRTAB 0000000000000000 0000101c 0000000000000011 0000000000000000 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific)
Use --strip-all if you don't want .symtab Use --no-rosegment to merge R PT_LOAD and RE PT_LOAD To discard PT_GNU_STACK and .comment, you have to use a linker script, e.g. PHDRS { text PT_LOAD; } SECTIONS { /DISCARD/ : {*(.comment)} .text : {*(.text)} :text } (objcopy options can be combined, e.g. objcopy -S --remove-section=.comment porcupine.lld