Workaround to linker script "INSERT BEFORE" with GNU gold

82 Views Asked by At

I have a linker script that currently works with GNU ld. I wanted to link using GNU gold but I am hitting an issue because currently GOLD does not support "INSERT BEFORE" in linker scripts, and looks like there is no plan to implement support for it (details here).

The error from gold looks like this:

/usr/bin/ld.gold: error: myscript.ld:20:12: syntax error, unexpected STRING
/usr/bin/ld.gold: fatal error: unable to parse script file myscript.ld

The script looks like this:

 SECTIONS{
        /DISCARD/ :{*(.IP*INFO)}
        .data1          :
        {
             data_section_start = LOADADDR(.data);
             bss_section_start = LOADADDR(.bss);
             rodata_section_start = LOADADDR(.rodata);

             PROVIDE_HIDDEN(mybin_start = .);
             *(.MyBinSegment)
             PROVIDE_HIDDEN(mybin_end = .);
        }
        .mysec1          :
        {
             PROVIDE_HIDDEN(mysec1_start = .);
             *(.mysec1)
             PROVIDE_HIDDEN(mysec1_end = .);
        }
     }
     INSERT BEFORE .data

I was wondering whether there is a better way to write this script to avoid using INSERT BEFORE .data;.

Thanks.

Simone

0

There are 0 best solutions below