bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mingw and memcmp


From: Eric Blake
Subject: mingw and memcmp
Date: Thu, 20 Dec 2007 20:22:53 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

I ran into this build failure in m4 when cross-compiling to mingw:

gcc -mno-cygwin -std=gnu99  -gdwarf-2 -Wall -Werror   -o test-avltree_oset.exe 
test-avltree_oset.o libtests.a  ../lib/libm4.a libtests.a   
libtests.a(progname.o): In function `set_program_name':
../../tests/progname.c:44: undefined reference to `_rpl_memcmp'
collect2: ld returned 1 exit status
make[4]: *** [test-avltree_oset.exe] Error 1

I traced it to the fact that AC_FUNC_MEMCMP pessimistically assumes broken 
memcmp when cross-compiling.  And now that m4 depends on memmem, which depends 
on memcmp, but does not depend on progname.o, the link line did:

test-avltree_oset.o does not directly provide or require program_name
test-avltree_oset.o requires gl_avltree_*, provided by ../lib/libm4.a
gl_avltree_* requires error, provided by ../lib/libm4.a
error requires program_name, provided by libtests.a
program_name requires rpl_memcmp, provided by ../lib/libm4.a (oops)

So I'm committing this patch.  Since progname.o already used strncmp, it 
doesn't hurt to use it twice and avoid the memcmp.

(I'm starting to wonder if it is easier to require all test-foo.c programs to 
declare and populate program_name themselves, rather than relying on the 
progname module.)

From: Eric Blake <address@hidden>
Date: Thu, 20 Dec 2007 13:15:27 -0700
Subject: [PATCH] Work around circular library issue when cross-compiling.

* lib/progname.c (set_program_name): Use strncmp, not memcmp, so
that progname.o does not need to pull in rpl_memcmp.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog      |    6 ++++++
 lib/progname.c |    4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 280c7ca..7aacc8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-12-20  Eric Blake  <address@hidden>
+
+       Work around circular library issue when cross-compiling.
+       * lib/progname.c (set_program_name): Use strncmp, not memcmp, so
+       that progname.o does not need to pull in rpl_memcmp.
+
 2007-12-19  Eric Blake  <address@hidden>
 
        Fix memmem to avoid O(n^2) worst-case complexity.
diff --git a/lib/progname.c b/lib/progname.c
index fa5aa8b..47d08c6 100644
--- a/lib/progname.c
+++ b/lib/progname.c
@@ -1,5 +1,5 @@
 /* Program name management.
-   Copyright (C) 2001-2003, 2005-2006 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003, 2005-2007 Free Software Foundation, Inc.
    Written by Bruno Haible <address@hidden>, 2001.
 
    This program is free software: you can redistribute it and/or modify
@@ -41,7 +41,7 @@ set_program_name (const char *argv0)
 
   slash = strrchr (argv0, '/');
   base = (slash != NULL ? slash + 1 : argv0);
-  if (base - argv0 >= 7 && memcmp (base - 7, "/.libs/", 7) == 0)
+  if (base - argv0 >= 7 && strncmp (base - 7, "/.libs/", 7) == 0)
     argv0 = base;
   if (strncmp (base, "lt-", 3) == 0)
     argv0 = base + 3;
-- 
1.5.3.5







reply via email to

[Prev in Thread] Current Thread [Next in Thread]