Bug 10340

Summary: ld doesn't honor sysroot prefix for ldscripts
Product: binutils Reporter: Sven Rebhan <OdinsHorse>
Component: ldAssignee: Alan Modra <amodra>
Severity: normal CC: bug-binutils, toolchain
Priority: P2    
Version: 2.19   
Target Milestone: ---   
URL: http://sourceware.org/ml/binutils/2012-03/msg00076.html
Host: Target: armv4tl-softfloat-linux-gnueabi
Build: Last reconfirmed:
Attachments: ld should search search in sysroot first

Description Sven Rebhan 2009-06-28 06:53:14 UTC
When ld is configured with a sysroot prefix and test is executed:

echo "Testing with absolute linker script (systems libz)..."
echo "GROUP ( /lib/libz.so )" > "${PWD}/libfoo-script.so"
armv4tl-softfloat-linux-gnueabi-gcc test.c -o test libfoo-script.so

the linking process terminates with

Testing with absolute linker script (systems libz)...
/lib/libz.so: file not recognized: File format not recognized
collect2: ld returned 1 exit status

because the Host's library is linked in. For cross-compilation the desired 
behaviour is different. Here, the lib specified in the linker script should be 
searched in the sysroot first! Patch will be attached.
Comment 1 Sven Rebhan 2009-06-28 06:55:03 UTC
Created attachment 4025 [details]
ld should search search in sysroot first

When ld was configured with a sysroot, it should always search for libraries
with absolute filename in this sysroot first.
Comment 2 Sven Rebhan 2009-06-28 06:56:58 UTC
Comment on attachment 4025 [details]
ld should search search in sysroot first

When ld was configured with a sysroot, it should always search for libraries
with absolute filename in this sysroot first. This patch was tested on
x86_64-pc-linux-gnu without sysroot and armv4tl-softfloat-linux-gnueabi with
sysroot and works ffine on both.
Comment 3 Mike Frysinger 2009-06-28 16:43:19 UTC
background discussion can be found here:
Comment 4 cvs-commit@gcc.gnu.org 2012-03-08 05:29:37 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2012-03-08 05:29:33

Modified files:
	ld             : ChangeLog ldfile.c ldfile.h ldlang.c ldlang.h 
	                 ldlex.h ldlex.l 

Log message:
	PR ld/10340
	* ldfile.c (is_sysrooted_pathname): Remove notsame param.
	(ldfile_add_library_path): Don't set sysrooted flag.
	(ldfile_open_file_search): Likewise, and don't copy them.
	(try_open): Delete exten and code handling such.  Add sysrooted
	param and return whether path is in sysroot.
	(ldfile_find_command_file): Delete extend param.  Add sysrooted
	param.  Rename local var.  Update try_open calls.
	(ldfile_open_command_file_1): Pass sysrooted to lex_push_file.
	* ldfile.h (search_dirs_type): Remove sysrooted field.
	* ldlang.c (new_afile): Always set sysrooted from input_flags.
	(load_symbols): Don't set input_flags.sysrooted.
	* ldlang.h (struct lang_input_statement_flags): Revise sysrooted
	* ldlex.h (lex_push_file): Update prototype.
	* ldlex.l (sysrooted_stack): New array.
	(EOF): Pop input_flags.sysrooted.
	(lex_push_file): Add sysrooted param.  Save and set

Comment 5 Alan Modra 2012-03-08 06:00:39 UTC
More background discussion http://sourceware.org/ml/binutils/2003-02/msg00449.html
Comment 6 Alan Modra 2012-10-18 08:07:34 UTC
Comment 7 Jackie Rosen 2014-02-16 17:44:12 UTC Comment hidden (spam)