How can ld linker script keep some objs' section?

xunxun xunxun1982@gmail.com
Tue Nov 1 08:45:00 GMT 2011


Hi, all

     I want to use ld's --gc-sections option on MinGW.

     Depend on the bug: http://sourceware.org/bugzilla/show_bug.cgi?id=11539
     We can use static build with --gc-sections successfully, but failed 
use it when building and using DLL build.

     I compared the linker map between before and after using 
--gc-sections, and found that --gc-sections will remove the obj's section:

.eh_frame      0x6da05000       0xcc 
e:/mysoft/programmingtools/compiler/mingw/bin/../lib/gcc/i686-w64-mingw32/4.6.2/../../../../i686-w64-mingw32/lib/../lib/dllcrt2.o 


        So I try to keep all .eh_frame sections in pe.sc linker script, 
you can modify *(.eh_frame*) to KEEP (*(.eh_frame))
        then the built dll can be used successfully, but because of all 
.eh_frame sections being kept, the dll size reduced by  --gc-sections 
becomes more smaller, and it will influence static build's size to be 
larger.

        In the end,  I want to know now, are there some methods to only 
keep dllcrt2.o's or some objs' .eh_frame section?
        Or some methods to only keep all .eh_frame sections when 
building DLL, but not static build?

        Many thanks.

-- 
Best Regards,
xunxun



More information about the Binutils mailing list