excluding a section from the linker --gc-sections option

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Is there any way to use --gc-sections and still keep a specific section?

I have an "application info" section located at a specific address in flash, which is modified with serial#, etc, before uploading the fw to the device. The fw references the array the section consists of, but still the linker throws it away when using --gc-sections. any ideas?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think (but am not sure) you need to tinker a bit with the linker script:

http://sourceware.org/binutils/d...

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks, johan... i'll try that... i still thinks it's weird that it gets thrown out when the code references data in there, but maybe that's because it has a special name in order to be able to relocate it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I pointed to KEEP as I seem to recall this having been mentioned here before. I'm not sure, though. Linker scripts is something I still haven't got firmly under my belt...

Let us know how it goes!

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hooverphonique wrote:
I have an "application info" section located at a specific address in flash, which is modified with serial#, etc, before uploading the fw to the device. The fw references the array the section consists of, but still the linker throws it away when using --gc-sections. any ideas?
What is the "fw"?
Does the linker throw it away?
If not, how is the reference resolved?

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"fw" is the firmware in question (the "hex" file so to speak)..
when --gc-sections is used, the mentioned section is not in the hex file anymore (or possibly not at the address it's supposed to, but that's unlikely).
there is a function in the code that references the array stored in the section.. i guess the function just reads whatever is present in flash at the address where the section is supposed to be located..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BUT gc-sections is a TWO part operation. You build the code files with -function-sections which puts each function into a separately named section (so not .text) then when linked gc-sections is used to "garbage collect unused sections" - in other words don't link in any function that is never referenced. If you want to over-ride this then build the .c file that you don't want discarded (could be a singe function) without function-sections then gc-sections won't touch it as it's already in .text

The .map fie should confirm which sections were discarded and which were linked - trawling about in the .hex is NOT the way to check. Also check the .sym file which is basically avr-nm output of the .elf - look for " T " entries.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

right.. i know it's a 2-part operation, i just wanted to know why a (customly named by me) section containing referenced data is thrown out, but sections customly named by the compiler aren't (the "function" sections). But I guess the sections named by the compiler has some part of their names matched by a KEEP wildcard as mentioned by Johan above.

I'm not trawling the hex file for sections.. We are using a custom piece of software to update the flash over an rs485 interface using a bootloader in the avr. this piece of software manipulates part of the section in question directly in the hex data (to set serial#, etc) before upload.

cheers..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hooverphonique wrote:
"fw" is the firmware in question (the "hex" file so to speak)..
when --gc-sections is used, the mentioned section is not in the hex file anymore (or possibly not at the address it's supposed to, but that's unlikely).
there is a function in the code that references the array stored in the section.. i guess the function just reads whatever is present in flash at the address where the section is supposed to be located..
As mentioned elsewhere,
there aren't any sections in the hex file.
What is in the elf?
Is said function in the elf?
If not, the issue becomes why the function was discarded.
If so, how was the reference resolved?

IIRC --gc-section keeps .text,
KEEPed sections and any sections they reference,
directly or indirectly.
Does your function qualify?

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I figured out what's going on..

Some of the code was copied from an older project (without --gc-sections) from another dev, and he specified the relocation address of the section as a constant, hence the mentioned array was in fact not referenced anywhere..

sorry for the rant...