-gc-sections丢弃使用的数据 [英] -gc-sections discards used data
问题描述
使用avr-gcc,avr-ld
Using avr-gcc, avr-ld
我试图通过使用fdata-sections -ffunction-sections和gc-sections来严重减小输出文件的大小.当不使用这些选项进行编译时,我的输出为〜63KB,而使用这些选项则为〜30KB,所以看起来很棒.
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.
不幸的是,在加载并测试了输出之后,我注意到它无法正常工作.垃圾回收似乎已远远超出了我的预期,并且检查.map时发现有些关键数据不存在.
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"?
如果不使用-fdata-sections -ffunction-sections -gc-sections,是否可以跟踪符号依赖关系? (要验证gc-sections仅收集了应该收集的内容) -我注意到这这是一个选择,但这非常使用Verax建议的方法对我来说很痛苦
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
编译器和链接器行
avr-ld -mavrxmega6 -gc-sections -T 链接描述文件 文件 libgcc.a -o firmware.elf
avr-ld -mavrxmega6 -gc-sections -Tlinkerscript files libgcc.a -o firmware.elf
avr-gcc -Wall -Wstrict原型-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
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
推荐答案
有一个非常明显的ld选项,称为-print-gc-sections,用于检查被扔掉的东西.
There was a pretty obvious ld option called -print-gc-sections to review what is being tossed out.
我从来没有找到一种跟踪符号依赖关系的方法,但最终不需要查看-print-gc-sections.
I never found a way to trace dependencies on a symbol, but ended up not needing to with reviewing -print-gc-sections.
我发现此描述了魔术部分",我想这与我所看到的相似.有许多自定义链接器节的用法不正确,我使用KEEP来防止这些错误,尽管我确定现在没有删除无效代码,但这可能是我能做到的.
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.
这篇关于-gc-sections丢弃使用的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!