customize linker script fail when use gold linker

Cary Coutant ccoutant@gmail.com
Fri May 14 17:30:37 GMT 2021


> when I migrate to gold linker, it failed with gold don’t recognize ‘INSERT’;
>
> After some google search, this failed means gold linker  has no default script;

Yes, because there is no default linker script, gold does not support
INSERT BEFORE or INSERT AFTER.

> Then I try to dump the default script by : ld —verbose; and put above custom script in the dumped;
>
> which also failed with error:
>
> /usr/bin/ld.gold: error: /data/1/3_2_x_opt-gcc93/rpm/gold.lds:51:22: syntax error, unexpected '('
> /usr/bin/ld.gold: fatal error: unable to parse script file /data/1/3_2_x_opt-gcc93/rpm/gold.lds
>
> It seems the linker script can’t been correctly parsed by gold.

>   .init           :
>   {
>     KEEP (*(SORT_NONE(.init)))
>   }

>   .fini           :
>   {
>     KEEP (*(SORT_NONE(.fini)))
>   }

Gold also does not support SORT_NONE. Try removing that.

Ideally, you should try to find a way to link your code without a
custom linker script at all. If you're using CO_BUFFER_BEGIN and
CO_BUFFER_END as bracketing sections to provide a start and stop
symbol, you can try using the linker-generated __start_COBUFFER and
__stop_COBUFFER symbols instead. Likewise for the COHOOK section.

-cary


More information about the Binutils mailing list