Bug 4437 - ld check all files are present and indicate those missing
Summary: ld check all files are present and indicate those missing
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.17
: P2 enhancement
Target Milestone: ---
Assignee: Nick Clifton
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-29 14:28 UTC by Jonny Grant
Modified: 2010-01-21 22:03 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Patch implementing this change (1.18 KB, patch)
2010-01-19 21:50 UTC, Jonny Grant
Details | Diff
Also continue after missing object files and missing sysrooted libraries (1.71 KB, patch)
2010-01-21 10:24 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jonny Grant 2007-04-29 14:28:01 UTC
Crux
====
I propose for ld to check that all the files it needs to read are available,
including object files and libraries, at present ld exits after finding any
single object file or library missing. Which doesn't indicate the extent of the
missing files.

-- Would a patch be considered for review which added checks that all files exist?

Detailed information
==========
The present behaviour looks like ld drops out with exit(1) when it finds the
first missing library or object file, example follows:

$ g++ -Wall -shared -o t -lFooBar -lMissing -l12346789 -lMathsArc main.cpp
/usr/bin/ld: cannot find -lFooBar
collect2: ld returned 1 exit status

g++ does check that object files exist, but not libraries it appears. If I call
collect2 directly, it calls ld and we can see the missing test.o object file:

$  /usr/lib/gcc/i486-linux-gnu/4.1.2/collect2 --eh-frame-hdr -m elf_i386 -shared
-o t /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crti.o
/usr/lib/gcc/i486-linux-gnu/4.1.2/crtbeginS.o
-L/usr/lib/gcc/i486-linux-gnu/4.1.2 -L/usr/lib/gcc/i486-linux-gnu/4.1.2
-L/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib -L/lib/../lib
-L/usr/lib/../lib test.o test2.o -lFooBar -lMissing -l12346789 -lMathsArc
/tmp/ccIyZv2e.o -lstdc++ -lm -lgcc_s -lc -lgcc_s -lfoo
/usr/lib/gcc/i486-linux-gnu/4.1.2/crtendS.o
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crtn.o
/usr/bin/ld: test.o: No such file: No such file or directory
collect2: ld returned 1 exit status

The proposed revision would change the first example's output to be as follows:

$ g++ -Wall -shared -o t -lFooBar -lMissing -l12346789 -lMathsArc main.cpp
/usr/bin/ld: cannot find -lMissing
/usr/bin/ld: cannot find -l12346789
/usr/bin/ld: cannot find -lMathsArc

collect2: ld returned 1 exit status
Comment 1 mozillist 2009-03-11 07:24:35 UTC
Good suggestion
Comment 2 Jonny Grant 2010-01-19 21:50:37 UTC
Created attachment 4541 [details]
Patch implementing this change

Apply this patch to the ld directory
Comment 3 Jonny Grant 2010-01-19 21:51:08 UTC
I've implemented this feature. Please see attached patch.
Please review, and apply!
Comment 4 Jonny Grant 2010-01-20 17:18:11 UTC
2010-01-19  Jon Grant <jg at jguk org>
	* ldlang.h: Add missing_file flag.
	* ldlang.c: Initialise missing_file flag to FALSE. In addition don't try use
bfd if library was missing. After checking all libraries, exit if missing_file
was set to TRUE.
	* ldfile.c: Set missing_file flag TRUE when library cannot be found.
Comment 5 Nick Clifton 2010-01-21 10:24:01 UTC
Created attachment 4547 [details]
Also continue after missing object files and missing sysrooted libraries
Comment 6 Nick Clifton 2010-01-21 10:25:49 UTC
Hi Jon,

  Thanks for the problem report and patch.  I have taken the liberty of
extending your patch to cover a few more areas (missing object files and missing
sysrooted libraries) as well as fixing up the formatting to conform to the GNU
Coding Standards.  I am going to check in this revised patch shortly.

Cheers
  Nick
Comment 7 Sourceware Commits 2010-01-21 10:31:51 UTC
Subject: Bug 4437

CVSROOT:	/cvs/src
Module name:	src
Changes by:	nickc@sourceware.org	2010-01-21 10:31:32

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

Log message:
	PR 4437
	* ldfile.c: (ldfile_open_file): Do not stop link upon encountering
	a missing file or library.  Instead mark the entry as missing and
	set the global flag to indicate that missing files were
	encountered.
	* ldlang.c (missing_files): New exported variable.
	(load_symbols): Skip loading if the file is missing.
	(open_input_bfds): Terminate link if any input files were
	missing.
	* ldlang.h (struct lang_input_statement_struct): Add missing_file
	field.
	Add export of missing_file variable.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.2100&r2=1.2101
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ldfile.c.diff?cvsroot=src&r1=1.53&r2=1.54
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ldlang.c.diff?cvsroot=src&r1=1.327&r2=1.328
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ldlang.h.diff?cvsroot=src&r1=1.87&r2=1.88

Comment 8 Nick Clifton 2010-01-21 10:34:20 UTC
Patch checked in.
Comment 9 Jonny Grant 2010-01-21 22:03:19 UTC
Hi Nick. Thanks for updating for other files + applying the patch. Cheers, Jon