This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
linker script globbing
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: binutils at sources dot redhat dot com
- Date: Fri, 25 Aug 2006 11:33:20 +0100
- Subject: linker script globbing
Whilst tracking down a separate linker bug I found a problem with input section
filename globbing. Namely, something like:
*crtbegin.o(.ctors) /* 1 */
*(EXCLUDE(*crtend.o) .ctors) /* 2 */
*crtend.o(.ctors) /* 3 */
would behave oddly when the linker is given full pathnames for crtbegin.o and
crtend.o (as it usually is).
Statement #1 would NOT match /path/to/crtbegin.o, because the fnmatch used
explicitly prevents '*' matching '/'. So statement 1 selects no sections.
Statement #2 selects all .o files, because a naked '*' does match everything.
The EXCLUDE clause does match /path/to/crtend.o, because that fnmatch does allow
'*' to glob '/'. So statement 1 selects /path/to/crtbegin.o (because it wasn't
already selected), and any other object files with .ctors sections.
Statement #3 behaves as statement #1, and does not select /path/to/crtend.o, so
crtend.o remains out of the link. Looking at the scripttemplates, they work
around this by writing statement #3 as '*(.ctors)', and thereby catch any
previously unselected .ctors sections -- which should just be the crtend.o one.
Statement #2 works because gcc always provides crtbegin.o early on the link
line, and the linker preserves order. The linker map file so produced, does look
a bit strange in that statement 1 didn't select crtbegin:
*crtbegin*.o(.ctors)
*(EXCLUDE_FILE(*crtend*.o) .ctors)
.ctors 0x00002f90 0x4 /path/to/crtbegin.o
Examining the fnmatch calls in ldlang.c, I find that all but one allow '/' to be
globbed. This patch changes the remaining call to allow such globbing
everywhere, and therefore be consistent.
ok?
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2006-08-25 Nathan Sidwell <nathan@codesourcery.com>
* ldlang.c (walk_wild): Allow * to glob '/' in wildcarded match.
Index: ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.236
diff -c -3 -p -r1.236 ldlang.c
*** ldlang.c 24 Aug 2006 14:59:24 -0000 1.236
--- ldlang.c 25 Aug 2006 10:07:42 -0000
*************** walk_wild (lang_wild_statement_type *s,
*** 791,797 ****
{
LANG_FOR_EACH_INPUT_STATEMENT (f)
{
! if (fnmatch (file_spec, f->filename, FNM_FILE_NAME) == 0)
walk_wild_file (s, f, callback, data);
}
}
--- 791,797 ----
{
LANG_FOR_EACH_INPUT_STATEMENT (f)
{
! if (fnmatch (file_spec, f->filename, 0) == 0)
walk_wild_file (s, f, callback, data);
}
}