This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Linker script using INSERT AFTER


On Mon, Oct 26, 2009 at 06:07:04PM +0100, Jan Blunck wrote:
> I'm trying to come up with a clever linker scripts, actually as an so-file,
> that is inserting some symbols if they are not provided by the objects being
> linked. Therefore I tried to use INSERT AFTER like this:
[snip]
> I get this error during linking:
> 
> /usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../x86_64-suse-linux/bin/ld:
> warning: /usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../lib64/libust.so
> contains output sections; did you forget -T?

You also got this warning.  ;-)

> /usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../x86_64-suse-linux/bin/ld:
> .data not found for insert
> collect2: ld returned 1 exit status
> make: *** [basic] Error 1

The reason for the error is due to the order of script parsing.  -T
scripts are parsed before the default linker script, and files that
are found to be scripts when opening input files are parsed later.  So
your script is placed after the default script in the linker's
internal representation of script statements.  As the ld info doc
says, INSERT "inserts all prior linker script statements after (or
before) output_section".  In your case, "all prior statements" is the
entirety of the default script plus your script.  The linker can't
find a ".data" statement outside of this set.

> Anyway, since I though that it isn't necessary to add an empty section (if
> __start___markers isnt' there I know that the section will be empty anyway) I
> thought that I can live with the following:
> 
> SECTIONS
> {
> 	PROVIDE_HIDDEN(__start___markers = .);
> 	PROVIDE_HIDDEN(__stop___markers = .);
> 
> 	PROVIDE_HIDDEN(__start___tracepoints = .);
> 	PROVIDE_HIDDEN(__stop___tracepoints = .);
> }
> INSERT AFTER .data;
> 
> That actually works, but it seems to override the hidden symbol that comes
> with on of the objects to link with. Somehow I think this isn't correct due to
> the description of PROVIDE_HIDDEN().

PROVIDE and PROVIDE_HIDDEN should only provide definitions for
undefined or common symbols.  Perhaps you have one of the latter?

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]