16

I'm trying to compile for an embedded arm processor using gcc-arm-linux-gnueabi, and -nostdlib to remove the dependencies on the c libraries and startup files. The chip doesn't have any way of interpreting elf files, so using objcopy -O binary, I can remove the elf headers from it. However, if I leave the build ID in, then the binary has the build ID at the start of the output, and so it fails to run. I can remove the build id in the linker script using /DISCARD/ : { *(.note.gnu.build-id) *(.ARM.attributes) }, however then the linker warns about .note.gnu.build-id section discarded, --build-id ignored.. While this works fine, and the code runs on the chip fine, I'd like to not have to pass and then drop the build ID. Is there any way to instruct gcc to pass commands to the linker without also passing --build-id?

David Wood
  • 335
  • 1
  • 4
  • 9
  • You can use the `-Wl,` if you want to pass a linker option from `gcc`. Is that what you're asking ? – Tuxdude Mar 09 '13 at 22:02
  • You could always use the `--remove-section` option to `objcopy` as well. – caf Mar 09 '13 at 22:11
  • 1
    Or you can stick the build ID somewhere other than the start, if it might end up being useful. – tc. Mar 10 '13 at 17:30

2 Answers2

29

I think these options will do what you want:

-Wl,--build-id=none

Passing none for style disables the setting from any --build-id options earlier on the command line.

ld manual

Samuel Edwin Ward
  • 6,526
  • 3
  • 34
  • 62
5

This is an old post, but it's worth stating for posterity that you don't have to discard the build ID. Your alternative is to move it to another area of flash by editing your linker script.

Simply move the build ID to somewhere after your vector table in your text section:

    .text :
    {
        . = ALIGN(4);
        _stext = .;
        KEEP(*(.vectors .vectors.*))
        KEEP(*(.note.gnu.build-id))
        *(.text .text.*)
        *(.rodata .rodata*)
        . = ALIGN(4);
        _etext = .;
    } > rom

This will keep your vector table at address 0x0 (your MCU likely requires this), but will also allow you to read the build ID from code, which could come in handy!

franc0is
  • 733
  • 9
  • 14
  • 1
    If you can communicate with the device in some way after deploying the code, then you may want to add a symbol that points to the build-id as well so that you can read it from the code itself and send it back for diagnostics. `_build_id = .` after the `KEEP(*(.note.gnu.build-id))` – nonsensickle Oct 01 '19 at 11:16