Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do not pass --build-id to linker from gcc

Tags:

c

gcc

arm

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?

like image 238
David Wood Avatar asked Mar 09 '13 21:03

David Wood


People also ask

What's the purpose of the Build ID?

Build ID is a unique identification of binaries. It's an identifier of the application for concrete release. It can be 1.0-47/64.

What is GNU build ID?

The build ID is a 160-bit SHA1 string computed over the elf header bits and section contents in the file. It is bundled in the elf file as an entry in the notes section. In the case of the GNU build ID: name is "GNU\0" , which gives us namesz = 4.

How do I find the build ID?

You can find the build ID manually from the game properties in steam and you can also find it by launching steam in console mode and the command app info. Therefore a way to communicate with steam in CLI form would probably also work.

How does linker work Linux?

In computer science, a linker or link editor is a computer program that takes one or more object files generated by a compiler and combines them into a single executable file, library file, or another object file. If you've written at least one program on C in your life, you will have seen files with the *.o extension.


2 Answers

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

like image 105
Samuel Edwin Ward Avatar answered Oct 03 '22 19:10

Samuel Edwin Ward


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!

like image 30
franc0is Avatar answered Oct 03 '22 19:10

franc0is