public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PATCH: Do not use glob on MinGW hosts
@ 2005-02-16 12:03 Mark Mitchell
  2005-02-16 12:18 ` Alan Modra
  2005-02-16 12:28 ` Jakub Jelinek
  0 siblings, 2 replies; 4+ messages in thread
From: Mark Mitchell @ 2005-02-16 12:03 UTC (permalink / raw)
  To: binutils


When building a MinGW-hosted Linux-targeted compiler, we get a
compilation failure in the linker.  The problem is that the linker
wants to use "glob" to handle "#include" directives in /etc/ld.so.conf
(appropriately adjusted for sysroot, of course) -- but Windows does
not have this routine.

This patch avoids the use of glob -- by assuming the the included file
is just a literal pathname rather than a glob pattern.  As #include's
in ld.so.conf are rare, and glob-pattern includes are rarer, this
seems like a satisfactory solution.  

(Ideally, we'd have a version of "glob" in libiberty, but we don't.
And, providing one is a bit complicated int that we really want to
match the GLIBC semantics for "glob", whereas on Windows it might make
sense to use FindFirstFile/FindNextFile, which are somewhat
different.)

OK to apply?

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-02-15  Mark Mitchell  <mark@codesourcery.com>

	* configure.in (AC_CHECK_FUNCS): Add glob.
	* configure: Regenerated.
	* emultempl/elf32.em (<glob.h>): Do not include if HAVE_GLOB is
	not defined.
	(gld${EMULATION_NAME}_parse_ld_so_conf_include): Do not use glob
	if HAVE_GLOB is not defined.
	
Index: ld/configure.in
===================================================================
RCS file: /cvs/src/src/ld/configure.in,v
retrieving revision 1.25
diff -c -5 -p -r1.25 configure.in
*** ld/configure.in	12 Jan 2005 22:12:24 -0000	1.25
--- ld/configure.in	16 Feb 2005 06:12:25 -0000
*************** AC_SUBST(HDEFINES)
*** 117,127 ****
  AC_SUBST(HOSTING_CRT0)
  AC_SUBST(HOSTING_LIBS)
  AC_SUBST(NATIVE_LIB_DIRS)
  
  AC_CHECK_HEADERS(string.h strings.h stdlib.h unistd.h)
! AC_CHECK_FUNCS(sbrk realpath)
  AC_HEADER_DIRENT
  
  BFD_BINARY_FOPEN
  
  BFD_NEED_DECLARATION(strstr)
--- 117,127 ----
  AC_SUBST(HOSTING_CRT0)
  AC_SUBST(HOSTING_LIBS)
  AC_SUBST(NATIVE_LIB_DIRS)
  
  AC_CHECK_HEADERS(string.h strings.h stdlib.h unistd.h)
! AC_CHECK_FUNCS(sbrk realpath glob)
  AC_HEADER_DIRENT
  
  BFD_BINARY_FOPEN
  
  BFD_NEED_DECLARATION(strstr)
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.128
diff -c -5 -p -r1.128 elf32.em
*** ld/emultempl/elf32.em	11 Feb 2005 23:52:03 -0000	1.128
--- ld/emultempl/elf32.em	16 Feb 2005 06:12:25 -0000
*************** EOF
*** 65,75 ****
--- 65,77 ----
  
  if [ "x${USE_LIBPATH}" = xyes ] ; then
    case ${target} in
      *-*-linux-gnu*)
    cat >>e${EMULATION_NAME}.c <<EOF
+ #ifdef HAVE_GLOB
  #include <glob.h>
+ #endif
  EOF
      ;;
    esac
  fi
  
*************** static void
*** 537,547 ****
--- 539,551 ----
  gld${EMULATION_NAME}_parse_ld_so_conf_include
       (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
        const char *pattern)
  {
    char *newp = NULL;
+ #ifdef HAVE_GLOB
    glob_t gl;
+ #endif
  
    if (pattern[0] != '/')
      {
        char *p = strrchr (filename, '/');
        size_t patlen = strlen (pattern) + 1;
*************** gld${EMULATION_NAME}_parse_ld_so_conf_in
*** 550,567 ****
--- 554,576 ----
        memcpy (newp, filename, p - filename + 1);
        memcpy (newp + (p - filename + 1), pattern, patlen);
        pattern = newp;
      }
  
+ #ifdef HAVE_GLOB
    if (glob (pattern, 0, NULL, &gl) == 0)
      {
        size_t i;
  
        for (i = 0; i < gl.gl_pathc; ++i)
  	gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
        globfree (&gl);
      }
+ #else
+   /* If we do not have glob, treat the pattern as a literal filename.  */
+   gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern);
+ #endif
  
    if (newp)
      free (newp);
  }
  

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Do not use glob on MinGW hosts
  2005-02-16 12:03 PATCH: Do not use glob on MinGW hosts Mark Mitchell
@ 2005-02-16 12:18 ` Alan Modra
  2005-02-16 12:28 ` Jakub Jelinek
  1 sibling, 0 replies; 4+ messages in thread
From: Alan Modra @ 2005-02-16 12:18 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: binutils

On Tue, Feb 15, 2005 at 10:30:09PM -0800, Mark Mitchell wrote:
> 	* configure.in (AC_CHECK_FUNCS): Add glob.
> 	* configure: Regenerated.
> 	* emultempl/elf32.em (<glob.h>): Do not include if HAVE_GLOB is
> 	not defined.
> 	(gld${EMULATION_NAME}_parse_ld_so_conf_include): Do not use glob
> 	if HAVE_GLOB is not defined.

OK.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Do not use glob on MinGW hosts
  2005-02-16 12:03 PATCH: Do not use glob on MinGW hosts Mark Mitchell
  2005-02-16 12:18 ` Alan Modra
@ 2005-02-16 12:28 ` Jakub Jelinek
  2005-02-17  0:21   ` Mark Mitchell
  1 sibling, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2005-02-16 12:28 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: binutils

On Tue, Feb 15, 2005 at 10:30:09PM -0800, Mark Mitchell wrote:
> 
> When building a MinGW-hosted Linux-targeted compiler, we get a
> compilation failure in the linker.  The problem is that the linker
> wants to use "glob" to handle "#include" directives in /etc/ld.so.conf
> (appropriately adjusted for sysroot, of course) -- but Windows does
> not have this routine.
> 
> This patch avoids the use of glob -- by assuming the the included file
> is just a literal pathname rather than a glob pattern.  As #include's
> in ld.so.conf are rare, and glob-pattern includes are rarer, this
> seems like a satisfactory solution.  

Well, they aren't that rare.
E.g. every recent Fedora Core and Red Hat Enterprise Linux installation has
include ld.so.conf.d/*.conf
in /etc/ld.so.conf by default and a bunch of *.conf files in
/etc/ld.so.conf.d/.
So IMHO you should also check for M$ globbing like functions and use them.
Does MinGW have fnmatch?  If yes, you could e.g. loop with
FindFirstFile/FindNextFile and fnmatch on each filename, etc.

> + #ifdef HAVE_GLOB
>     if (glob (pattern, 0, NULL, &gl) == 0)
>       {
>         size_t i;
>   
>         for (i = 0; i < gl.gl_pathc; ++i)
>   	gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
>         globfree (&gl);
>       }
> + #else
> +   /* If we do not have glob, treat the pattern as a literal filename.  */
> +   gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern);
> + #endif

	Jakub

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Do not use glob on MinGW hosts
  2005-02-16 12:28 ` Jakub Jelinek
@ 2005-02-17  0:21   ` Mark Mitchell
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Mitchell @ 2005-02-17  0:21 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: binutils

Jakub Jelinek wrote:

>>This patch avoids the use of glob -- by assuming the the included file
>>is just a literal pathname rather than a glob pattern.  As #include's
>>in ld.so.conf are rare, and glob-pattern includes are rarer, this
>>seems like a satisfactory solution.  
> 
> 
> Well, they aren't that rare.
> E.g. every recent Fedora Core and Red Hat Enterprise Linux installation has
> include ld.so.conf.d/*.conf

Thanks for educating me!

(I'd actually checked one of our RHEL servers, and it's not set up that 
way.)

> So IMHO you should also check for M$ globbing like functions and use them.
> Does MinGW have fnmatch?  If yes, you could e.g. loop with
> FindFirstFile/FindNextFile and fnmatch on each filename, etc.

No, there's no fnmatch in MinGW.  (MinGW is just an interface to 
Microsoft's C library, and that library doesn't have fnmatch.)  However, 
there is "fnmatch" in libiberty, so we could use that.

And FindFirstFile/FindNextFile do accept patterns containing "*" and 
"?".  But, these functions only work within a single directory.  In 
contrast, "glob" can handle things like "/etc/*/*".  So, we would have 
to operate recursively.  Furthermore, it's not clear to me that 
Microsoft's pattern matching exactly matches GLIBC's in particular.

If we really want to make this portable, the way to make it work is to 
write our own implementation of glob which walks recursively through 
directories.  Then, we should use this implementation everywhere -- 
including on GNU/Linux itself -- so that we can be sure to get the same 
semantics.  The same implementation should also be used in the dynamic 
linker so that it is consistent too.  The easiest thing might be to try 
to adopt the GNU libc glob for libiberty, but that's certainly not going 
to be trivial, and we'll have to keep it in sync forever more.

I guess I'm inclined to let someone who needs to solve this problem 
solve it; for our current purposes, the solution I posted is satisfactory.

-- 
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-02-16 17:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-16 12:03 PATCH: Do not use glob on MinGW hosts Mark Mitchell
2005-02-16 12:18 ` Alan Modra
2005-02-16 12:28 ` Jakub Jelinek
2005-02-17  0:21   ` Mark Mitchell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).