当前位置: 动力学知识库 > 问答 > 编程问答 >

c - gcc gc-sections option removes crtbegin/crtend objects

问题描述:

I try to optimize the executable using gc-sections, ffunction-sections and fdata-sections. I also give init function with -u (undefined) to the linker. My init function and all used symbols added,and other unused symbols are eliminated successfully. Everything is OK.

But crtbegin,crtend objects are also eliminated which are put by gcc. In that case my executable does not work... Is there any method to keep crtbegin and crtend objects in the executable.

Note: KEEP() directives exist in the linker for crtbegin such as : KEEP(*crtbegin.o(.ctors)) KEEP(*crtbegin?.o(.ctors)) etc.

网友答案:

It is solved. The executable was crashing and giving exception. Since gc-section option was removing the crtbegin functions such as __do_global_dtors_aux call__do_global_dtors_aux,frame_dummy, call_frame_dummy etc. Hence that causes to crash of the program.

But when you keep the init section in the linker : "KEEP(*(.init))", then those function are kept while gc-sections option clears other unused symbols. Then my program runs succesfully without any crash.

分享给朋友:
您可能感兴趣的文章:
随机阅读: