I want to specify alignment for some sections. For ld 2.20.0
the following approach works:
create a linker script containing only the sections that should be aligned, e.g.:
SECTIONS { .data ALIGN(0x40): { *(.data) } .text ALIGN(0x40): { *(.text) } .plt ALIGN(0x10): { *(.plt) } }
then link with:
-rpath-link=/path/to/LinkerScript.ld /path/to/LinkerScript.ld
e.g. include the script in rpath-link and also pass it as one of the object files.
Now, when linking in the same way using gold 2.23.1
, the script is rejected with this error:
LinkerScript.ld: SECTIONS seen after other input files; try -T/--script
So gold wants me to specify a complete linker script, however I only want to change a couple attributes. Is this possible?
I have already tried:
- Passing the script with the
-T
option. This produces a broken executable that fails to start. As I understand this is because-T
only accepts complete linker scripts, while the above is just an "annotation" to the existing script. - In the same vein, when passing the script with the
-T
option told 2.20.0
it fails to link since some sections are unspecified. It is not a "complete" linker script for my use case. - So I have tried obtaining a complete linker script.
ld --verbose
will print the default linker script. I had to remove a couple of symbols that were not understood bygold
, afterwards the executable produced with the-T/path/to/LinkerScript.ld
option didn't work anymore. - Unfortunately
gold
has no option to show its default linker script (it doesn't use any). - The man pages do not specify how to change alignment for the case above with a parameter.
Any help would be greatly appreciated!