Archive file in linker script input section ignored
Nick Clifton
nickc@redhat.com
Mon May 18 15:17:20 GMT 2020
Hi Tobias,
> # cat test_object.ld
> SECTIONS {
> .rodata : {
> test.o(.testdata)
> }
> }
>
> # cat test_archive.ld
> SECTIONS {
> .rodata : {
> test.a:(.testdata)
> }
> }
>
> # gcc -c test.c -o test.o
> # ar r test.a test.o
> ar: creating test.a
> # ld -T test_object.ld -o test_object.out
This link will not produce the output you have described below since no object
files are actually present. Either you need to link with:
ld -T test_object.ld -o test_object.out test.o
or else add:
INPUT(test.o)
to test_object.ld.
> # ld -T test_archive.ld -o test_archive.out
As already mentioned this fails to produce the output that you desire
because libraries are only included in the final binary if they provide
the definitions of one or more needed symbols. So in order to get this
command to work you need to change it to something like:
ld -T test_archive.ld -o test_archive.out -u data test.a
Again you need to include some sort of input file in order for anything
(significant) to be produced as an output, hence the presence of "test.a"
on the command line above.
Cheers
Nick
More information about the Binutils
mailing list