Injecting sections into GNU ld script; script compatibility between versions of binutils. Injecting sections into GNU ld script; script compatibility between versions of binutils. c c

Injecting sections into GNU ld script; script compatibility between versions of binutils.


I found a satisfying solution for that problem. GNU ld has the INSERT option which makes the externally supported script not override the default script, but simply add new section at position relative to some section that exists in the default script.

So in my case, the script passed to the linker may be as simple as:

SECTIONS{  .rodata.ld_comp_array :  {    *(SORT_BY_NAME(.ld_comp_array*))  }}INSERT AFTER .rodata;

More on the INSERT option: http://sourceware.org/binutils/docs/ld/Miscellaneous-Commands.html#Miscellaneous-Commands