Page 1 of 1
gcc/ld with build-id enabled
Posted: Thu Oct 23, 2014 12:43 pm
by dflogeras
I use Gentoo's crossdev to create my toolchains. It seems that since the 4.8.x series of GCC, the default is now for gcc to be built with --enable-linker-build-id. This apparently can help in locating debug files for ELF binaries. I'm not sure if this is of any benefit for ChibiOS projects.
Without any changes, projects that used to compile now give the following
Code: Select all
Linking build/ch.elf
/usr/libexec/gcc/armv7m-softfloat-eabi/ld: error: no memory region specified for loadable section `.note.gnu.build-id'
collect2: error: ld returned 1 exit status
../os/ports/GCC/ARMCMx/rules.mk:210: recipe for target 'build/ch.elf' failed
make: *** [build/ch.elf] Error 1
I have found that you can easily disable this default by appending the following to the compiler options:
However, I was wondering if this is the best solution, or if I should investigate adding support for it in my linker scripts.
Re: gcc/ld with build-id enabled
Posted: Thu Oct 23, 2014 3:52 pm
by Giovanni
I think it should go in the linker script, it is a new loadable section.
Giovanni
Re: gcc/ld with build-id enabled
Posted: Thu Oct 23, 2014 4:08 pm
by dflogeras
Alright,
To my understanding, this build-id is a unique identifier (could be a SHA, or UUID or whatever) that gets injected by the toolchain. I would assume it is read-only. Would you suggest adding a section like the .data section? I'm not sure how to begin, since I've never delved too deep into linker scripts.
Something like this? (I am probably breaking every existing naming scheme, but figured I'd start somewhere)
Code: Select all
.note.gnu.build-id :
{
. = ALIGN(4);
PROVIDE( _note = .);
*(.note.gnu.build-id)
. = ALIGN(4);
*(.note.gnu.build-id.*);
. = ALIGN(4);
PROVIDE( _enote = .);
} > ram AT > flash
Re: gcc/ld with build-id enabled
Posted: Thu Oct 23, 2014 4:12 pm
by Giovanni
Not the data section or it is copied in RAM, put it at the end of the text sections.
Giovanni
Re: gcc/ld with build-id enabled
Posted: Thu Oct 23, 2014 4:14 pm
by Giovanni
Try this:
Code: Select all
.note.gnu.build-id :
{
. = ALIGN(4);
PROVIDE( _note = .);
*(.note.gnu.build-id)
. = ALIGN(4);
*(.note.gnu.build-id.*);
. = ALIGN(4);
PROVIDE( _enote = .);
} > flash
Note, without the "> ram AT". Place it after the text sections.
Giovanni
Re: gcc/ld with build-id enabled
Posted: Thu Oct 23, 2014 4:33 pm
by dflogeras
Yep, that seems to work. According to my map file, I end up with a 36 byte section in flash (in the 0x8000xyz area on my STM32).
I checked, and if building with my old toolchain or explicitly setting --build-id=none, the section is listed in the map file, but is 0x0 bytes long.
I guess if you liked you could put this into the default linker scripts since it seems to be zero cost if you don't need the section. I'll leave that decision up to you

Thanks for the help,
Dave
Re: gcc/ld with build-id enabled
Posted: Thu Oct 23, 2014 5:57 pm
by Giovanni
Hi,
Yes, as soon 4.8.x becomes "official", I am not sure that the problem with LTO has been fully fixed.
Giovanni
Re: gcc/ld with build-id enabled
Posted: Thu Oct 23, 2014 6:29 pm
by dflogeras
Is there something in particular I can watch for with LTO (ie a class of bugs, or behaviour)? I mostly do this for hobby, so I am willing to try out 4.8.x while I play.
Re: gcc/ld with build-id enabled
Posted: Thu Oct 23, 2014 6:31 pm
by Giovanni
It is a compiler failure when you compile using LTO, so nothing that can hurt you at runtime.
This affects ChibiOS 3.0 only because LTO is not supported for 2.6.
Giovanni