Use of crtbegin.o in elf.sc

Ian Lance Taylor iant@google.com
Tue Jul 18 18:27:00 GMT 2006


I just happened to notice that this use of crtbegin.o in elf.sc:

    /* gcc uses crtbegin.o to find the start of
       the constructors, so we make sure it is
       first.  Because this is a wildcard, it
       doesn't matter if the user does not
       actually link against crtbegin.o; the
       linker won't look for a file to match a
       wildcard.  The wildcard also means that it
       doesn't matter which directory crtbegin.o
       is in.  */

    KEEP (*crtbegin*.o(.ctors))

does not work in practice.  This is because crtbegin.o is normally
specified using an absolute path.  However, the comparison is done
using FNM_FILE_NAME in walk_wild:
	  if (fnmatch (file_spec, f->filename, FNM_FILE_NAME) == 0)
The use of FNM_FILE_NAME means that the '*' will not match anything
containing a slash.  Therefore, the *crtbegin*.o will not match, e.g.,
    /usr/lib/gcc/i386-redhat-linux/4.0.2/crtbegin.o

This doesn't normally matter because gcc normally puts crtbegin.o at
the start of the command line anyhow.

Still, it was an interesting discovery.

Ian



More information about the Binutils mailing list