-gc-sections discards used data

让人想犯罪 __ 提交于 2020-01-01 11:45:17

问题


Using avr-gcc, avr-ld

I'm attempting to severely reduce the size of the output file by using fdata-sections -ffunction-sections and gc-sections. When compiled without these options I have an output of ~63KB, and with these options its ~30KB, so it seems great.

Unfortunately, after loading and testing the output I notice it doesn't work correctly. Garbage collection seems to have removed far more than I expected, and examining the .map I notice some key data is nonexistent.

Any idea on what at link time is causing these data/functions to be discarded? (I realize this may be too hopeful of a question with how little detail I provided, if any information is needed please ask and I'd do my best to provide it)

Is there a way to trace what symbols were tossed by garbage collection as they were "unused"?

Without using -fdata-sections -ffunction-sections -gc-sections, can I trace a symbol dependencies? (To verify gc-sections only collected what it should) - I noticed this this as an option, but it would be very painful for me to use the method suggested by Verax

EDIT: compiler and linker lines

avr-ld -mavrxmega6 -gc-sections -Tlinkerscript files libgcc.a -o firmware.elf

avr-gcc -Wall -Wstrict-prototypes -g -ffunction-sections -fdata-sections -Os -mmcu=atxmega256a3 -fno-jump-tables -std=gnu99 -fpack-struct -fno-common -mcall-prologues -c -o file.o file.c


回答1:


There was a pretty obvious ld option called -print-gc-sections to review what is being tossed out.

I never found a way to trace dependencies on a symbol, but ended up not needing to with reviewing -print-gc-sections.

I found this that described "magic sections" and I imagine this is similar to what I was seeing. There were many custom linker sections that were discared incorrectly, I used KEEP to prevent gc of these although I'm sure there is dead code not being removed now, but this may be the best I can do.



来源:https://stackoverflow.com/questions/31521326/gc-sections-discards-used-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!