gcc/ld with build-id enabled

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
dflogeras
Posts: 235
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

gcc/ld with build-id enabled

Post 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:

Code: Select all

-Wl,--build-id=none


However, I was wondering if this is the best solution, or if I should investigate adding support for it in my linker scripts.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: gcc/ld with build-id enabled

Post by Giovanni »

I think it should go in the linker script, it is a new loadable section.

Giovanni
dflogeras
Posts: 235
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: gcc/ld with build-id enabled

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: gcc/ld with build-id enabled

Post by Giovanni »

Not the data section or it is copied in RAM, put it at the end of the text sections.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: gcc/ld with build-id enabled

Post 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
dflogeras
Posts: 235
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: gcc/ld with build-id enabled

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: gcc/ld with build-id enabled

Post 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
dflogeras
Posts: 235
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: gcc/ld with build-id enabled

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: gcc/ld with build-id enabled

Post 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
Post Reply