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
Good suggestion
Created attachment 4541 [details] Patch implementing this change Apply this patch to the ld directory
I've implemented this feature. Please see attached patch. Please review, and apply!
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.
Created attachment 4547 [details] Also continue after missing object files and missing sysrooted libraries
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
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
Patch checked in.
Hi Nick. Thanks for updating for other files + applying the patch. Cheers, Jon