longest backtrack: 17 (code: 156) Shared 29773 out of 59469 states by creating 7857 new states, saving 21916 /src/gcc-trunk/gcc/selftest.c: In function 'void selftest::assert_strndup_eq(const char*, const char*, size_t)': /src/gcc-trunk/gcc/selftest.c:209:30: error: 'strndup' was not declared in this scope char *buf = strndup (src, n); ^ make[3]: *** [selftest.o] Error 1 make[3]: *** Waiting for unfinished jobs.... make[2]: *** [all-stage1-gcc] Error 2 make[1]: *** [stage1-bubble] Error 2 The bootstrap compiler has a sysroot suitable for Darwin10 (which doesn't have strndup, strnlen etc.)
If I'm reading things right, it looks like libiberty provides an implementation of strndup if it's not available, but it doesn't provide a decl for it.
(In reply to David Malcolm from comment #1) > If I'm reading things right, it looks like libiberty provides an > implementation of strndup if it's not available, but it doesn't provide a > decl for it. indeed $ grep strndup include/libiberty.h extern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL; not sure exactly what the phasing is supposed to be.
trying this (after regnerating gcc/configure and gcc/config.in) $ git diff gcc/configure.ac include/libiberty.h diff --git a/gcc/configure.ac b/gcc/configure.ac index 703250f..ece1ffa 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -1306,7 +1306,7 @@ AC_CHECK_DECLS([basename(const char*), strstr(const char*,const char*)], , ,[ #include "system.h"]) gcc_AC_CHECK_DECLS(getenv atol atoll asprintf sbrk abort atof getcwd getwd \ - madvise stpcpy strnlen strsignal strverscmp \ + madvise stpcpy strnlen strndup strsignal strverscmp \ strtol strtoul strtoll strtoull setenv unsetenv \ errno snprintf vsnprintf vasprintf malloc realloc calloc \ free getopt clock getpagesize ffs gcc_UNLOCKED_FUNCS, , ,[ diff --git a/include/libiberty.h b/include/libiberty.h index 605ff56..0401dac 100644 --- a/include/libiberty.h +++ b/include/libiberty.h @@ -670,6 +670,10 @@ extern int vsnprintf (char *, size_t, const char *, va_list) ATTRIBUTE_PRINTF(3, extern size_t strnlen (const char *, size_t); #endif +#if defined (HAVE_DECL_STRNDUP) && !HAVE_DECL_STRNDUP +extern size_t strndup (const char *, size_t); +#endif + #if defined(HAVE_DECL_STRVERSCMP) && !HAVE_DECL_STRVERSCMP /* Compare version strings. */ extern int strverscmp (const char *, const char *);
(In reply to Iain Sandoe from comment #3) > trying this (after regnerating gcc/configure and gcc/config.in) > > $ git diff gcc/configure.ac include/libiberty.h > diff --git a/gcc/configure.ac b/gcc/configure.ac > index 703250f..ece1ffa 100644 > --- a/gcc/configure.ac > +++ b/gcc/configure.ac > @@ -1306,7 +1306,7 @@ AC_CHECK_DECLS([basename(const char*), strstr(const > char*,const char*)], , ,[ > #include "system.h"]) > > gcc_AC_CHECK_DECLS(getenv atol atoll asprintf sbrk abort atof getcwd getwd \ > - madvise stpcpy strnlen strsignal strverscmp \ > + madvise stpcpy strnlen strndup strsignal strverscmp \ > strtol strtoul strtoll strtoull setenv unsetenv \ > errno snprintf vsnprintf vasprintf malloc realloc calloc \ > free getopt clock getpagesize ffs gcc_UNLOCKED_FUNCS, , ,[ > diff --git a/include/libiberty.h b/include/libiberty.h > index 605ff56..0401dac 100644 > --- a/include/libiberty.h > +++ b/include/libiberty.h > @@ -670,6 +670,10 @@ extern int vsnprintf (char *, size_t, const char *, > va_list) ATTRIBUTE_PRINTF(3, > extern size_t strnlen (const char *, size_t); > #endif > oops pasto on strndup signature; meant char * of course > +#if defined (HAVE_DECL_STRNDUP) && !HAVE_DECL_STRNDUP > +extern size_t strndup (const char *, size_t); > +#endif > + > #if defined(HAVE_DECL_STRVERSCMP) && !HAVE_DECL_STRVERSCMP > /* Compare version strings. */ > extern int strverscmp (const char *, const char *);
Created attachment 40210 [details] test for strndup and publish it from libiberty if not available from the host. bootstrap (all langs, checking=yes,rtl,tree) completed at 243033 with this patch. I guess the question is why wasn't the function exported from libiberty before?
Or just use xstrndup like we do in gcc/?
Yeah, I'm susprised strndup isn't poisoned in system.h, strdup is. selftest.c shouldn't be using strndup, just xstrndup.
Thanks. I'm working on a patch to remove the use of strndup. Sorry for the breakage.
Author: dmalcolm Date: Fri Dec 2 22:39:43 2016 New Revision: 243207 URL: https://gcc.gnu.org/viewcvs?rev=243207&root=gcc&view=rev Log: selftest.c: remove calls to strndup (PR bootstrap/78616) gcc/ChangeLog: PR bootstrap/78616 * selftest.c (selftest::assert_strndup_eq): Rename to... (selftest::assert_xstrndup_eq): ...this, and remove call to strndup. (selftest::test_strndup): Rename to... (selftest::test_xstrndup): ...this, updating for above renaming. (selftest::test_libiberty): Update for renaming. Modified: trunk/gcc/ChangeLog trunk/gcc/selftest.c
Build breakage should have been fixed as of r243207 (sorry again). Should we poision strndup in system.h?
(In reply to David Malcolm from comment #10) > Build breakage should have been fixed as of r243207 (sorry again). > > Should we poision strndup in system.h? I think so, I meant to ask that last time this happened in bug 67363 but never got around to it.
Regression fixed (regression marker removed). All that's left is to poison strndup in system.h
(In reply to Jeffrey A. Law from comment #12) > Regression fixed (regression marker removed). All that's left is to poison > strndup in system.h Candidate patch: https://gcc.gnu.org/ml/gcc-patches/2017-01/msg00998.html
Author: dmalcolm Date: Mon Jan 16 15:03:41 2017 New Revision: 244494 URL: https://gcc.gnu.org/viewcvs?rev=244494&root=gcc&view=rev Log: system.h: Poison strndup (PR bootstrap/78616) gcc/ChangeLog: PR bootstrap/78616 * system.h: Poison strndup. Modified: trunk/gcc/ChangeLog trunk/gcc/system.h
(In reply to Jeffrey A. Law from comment #12) > Regression fixed (regression marker removed). All that's left is to poison > strndup in system.h Poisoned in r244494; marking this PR as resolved.