* [PATCH/libiberty] fix build of gdb/binutils with clang. @ 2015-04-28 22:30 Yunlian Jiang 2015-05-01 22:45 ` Ian Lance Taylor 0 siblings, 1 reply; 15+ messages in thread From: Yunlian Jiang @ 2015-04-28 22:30 UTC (permalink / raw) To: gcc-patches I believe this is the same problem as https://gcc.gnu.org/ml/gcc-patches/2008-07/msg00292.html The asprinf declaration is messed up when using clang to build gdb. diff --git a/include/libiberty.h b/include/libiberty.h index b33dd65..a294903 100644 --- a/include/libiberty.h +++ b/include/libiberty.h @@ -625,8 +625,10 @@ extern int pwait (int, int *, int); /* Like sprintf but provides a pointer to malloc'd storage, which must be freed by the caller. */ +#ifndef asprintf extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; #endif +#endif /* Like asprintf but allocates memory without fail. This works like xmalloc. */ ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-04-28 22:30 [PATCH/libiberty] fix build of gdb/binutils with clang Yunlian Jiang @ 2015-05-01 22:45 ` Ian Lance Taylor 2015-05-01 23:45 ` Yunlian Jiang 0 siblings, 1 reply; 15+ messages in thread From: Ian Lance Taylor @ 2015-05-01 22:45 UTC (permalink / raw) To: Yunlian Jiang; +Cc: gcc-patches On Tue, Apr 28, 2015 at 2:59 PM, Yunlian Jiang <yunlian@google.com> wrote: > I believe this is the same problem as > https://gcc.gnu.org/ml/gcc-patches/2008-07/msg00292.html > > The asprinf declaration is messed up when using clang to build gdb. > > diff --git a/include/libiberty.h b/include/libiberty.h > index b33dd65..a294903 100644 > --- a/include/libiberty.h > +++ b/include/libiberty.h > @@ -625,8 +625,10 @@ extern int pwait (int, int *, int); > /* Like sprintf but provides a pointer to malloc'd storage, which must > be freed by the caller. */ > > +#ifndef asprintf > extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; > #endif > +#endif > > /* Like asprintf but allocates memory without fail. This works like > xmalloc. */ Why is HAVE_DECL_ASPRINTF not defined? Ian ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-05-01 22:45 ` Ian Lance Taylor @ 2015-05-01 23:45 ` Yunlian Jiang 2015-05-02 18:58 ` Ian Lance Taylor 0 siblings, 1 reply; 15+ messages in thread From: Yunlian Jiang @ 2015-05-01 23:45 UTC (permalink / raw) To: Ian Lance Taylor; +Cc: gcc-patches The test case does not have #define _GNU_SOURCE, so it says error: ‘asprintf’ undeclared (first use in this function) On Fri, May 1, 2015 at 3:45 PM, Ian Lance Taylor <iant@google.com> wrote: > On Tue, Apr 28, 2015 at 2:59 PM, Yunlian Jiang <yunlian@google.com> wrote: >> I believe this is the same problem as >> https://gcc.gnu.org/ml/gcc-patches/2008-07/msg00292.html >> >> The asprinf declaration is messed up when using clang to build gdb. >> >> diff --git a/include/libiberty.h b/include/libiberty.h >> index b33dd65..a294903 100644 >> --- a/include/libiberty.h >> +++ b/include/libiberty.h >> @@ -625,8 +625,10 @@ extern int pwait (int, int *, int); >> /* Like sprintf but provides a pointer to malloc'd storage, which must >> be freed by the caller. */ >> >> +#ifndef asprintf >> extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; >> #endif >> +#endif >> >> /* Like asprintf but allocates memory without fail. This works like >> xmalloc. */ > > Why is HAVE_DECL_ASPRINTF not defined? > > Ian ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-05-01 23:45 ` Yunlian Jiang @ 2015-05-02 18:58 ` Ian Lance Taylor 2015-05-04 22:49 ` Yunlian Jiang 0 siblings, 1 reply; 15+ messages in thread From: Ian Lance Taylor @ 2015-05-02 18:58 UTC (permalink / raw) To: Yunlian Jiang; +Cc: gcc-patches On Fri, May 1, 2015 at 4:45 PM, Yunlian Jiang <yunlian@google.com> wrote: > The test case does not have #define _GNU_SOURCE, so it says > error: ‘asprintf’ undeclared (first use in this function) OK, then my next question is: why does the test case (I assume you mean the test case for whether to set HAVE_DECL_ASPRINTF) not have #define _GNU_SOURCE? What is the background here? Ian > On Fri, May 1, 2015 at 3:45 PM, Ian Lance Taylor <iant@google.com> wrote: >> On Tue, Apr 28, 2015 at 2:59 PM, Yunlian Jiang <yunlian@google.com> wrote: >>> I believe this is the same problem as >>> https://gcc.gnu.org/ml/gcc-patches/2008-07/msg00292.html >>> >>> The asprinf declaration is messed up when using clang to build gdb. >>> >>> diff --git a/include/libiberty.h b/include/libiberty.h >>> index b33dd65..a294903 100644 >>> --- a/include/libiberty.h >>> +++ b/include/libiberty.h >>> @@ -625,8 +625,10 @@ extern int pwait (int, int *, int); >>> /* Like sprintf but provides a pointer to malloc'd storage, which must >>> be freed by the caller. */ >>> >>> +#ifndef asprintf >>> extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; >>> #endif >>> +#endif >>> >>> /* Like asprintf but allocates memory without fail. This works like >>> xmalloc. */ >> >> Why is HAVE_DECL_ASPRINTF not defined? >> >> Ian ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-05-02 18:58 ` Ian Lance Taylor @ 2015-05-04 22:49 ` Yunlian Jiang 2015-05-05 0:30 ` Ian Lance Taylor 0 siblings, 1 reply; 15+ messages in thread From: Yunlian Jiang @ 2015-05-04 22:49 UTC (permalink / raw) To: Ian Lance Taylor; +Cc: gcc-patches There was a similar disscussion here https://gcc.gnu.org/ml/gcc/2005-11/msg01190.html The problem is in the configure stage, the __GNU_SOURCE is not defined, and it could not find the declaration of asprintf. so it make a declaration of asprintf in libiberty.h. And for the file floatformat.c, the __GNU_SOURCE is defined, so it could find another asprintf in /usr/include/bits/stdio2.h, it also includes libiberty.h. So these two asprintf conflicts when __USE_FORTIFY_LEVEL is set. On Sat, May 2, 2015 at 11:58 AM, Ian Lance Taylor <iant@google.com> wrote: > On Fri, May 1, 2015 at 4:45 PM, Yunlian Jiang <yunlian@google.com> wrote: >> The test case does not have #define _GNU_SOURCE, so it says >> error: ‘asprintf’ undeclared (first use in this function) > > OK, then my next question is: why does the test case (I assume you > mean the test case for whether to set HAVE_DECL_ASPRINTF) not have > #define _GNU_SOURCE? > > What is the background here? > > Ian > >> On Fri, May 1, 2015 at 3:45 PM, Ian Lance Taylor <iant@google.com> wrote: >>> On Tue, Apr 28, 2015 at 2:59 PM, Yunlian Jiang <yunlian@google.com> wrote: >>>> I believe this is the same problem as >>>> https://gcc.gnu.org/ml/gcc-patches/2008-07/msg00292.html >>>> >>>> The asprinf declaration is messed up when using clang to build gdb. >>>> >>>> diff --git a/include/libiberty.h b/include/libiberty.h >>>> index b33dd65..a294903 100644 >>>> --- a/include/libiberty.h >>>> +++ b/include/libiberty.h >>>> @@ -625,8 +625,10 @@ extern int pwait (int, int *, int); >>>> /* Like sprintf but provides a pointer to malloc'd storage, which must >>>> be freed by the caller. */ >>>> >>>> +#ifndef asprintf >>>> extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; >>>> #endif >>>> +#endif >>>> >>>> /* Like asprintf but allocates memory without fail. This works like >>>> xmalloc. */ >>> >>> Why is HAVE_DECL_ASPRINTF not defined? >>> >>> Ian ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-05-04 22:49 ` Yunlian Jiang @ 2015-05-05 0:30 ` Ian Lance Taylor 2015-05-18 23:52 ` Yunlian Jiang 0 siblings, 1 reply; 15+ messages in thread From: Ian Lance Taylor @ 2015-05-05 0:30 UTC (permalink / raw) To: Yunlian Jiang; +Cc: gcc-patches On Mon, May 4, 2015 at 3:49 PM, Yunlian Jiang <yunlian@google.com> wrote: > There was a similar disscussion here > https://gcc.gnu.org/ml/gcc/2005-11/msg01190.html That was a discussion about libiberty. Your subject says you have trouble building gdb. Can you describe the exact problem that you are having? What precisely are you doing? What precisely happens? > The problem is in the configure stage, the __GNU_SOURCE is not > defined, and it could not find > the declaration of asprintf. so it make a declaration of asprintf in > libiberty.h. And for the file floatformat.c, > the __GNU_SOURCE is defined, so it could find another asprintf in > /usr/include/bits/stdio2.h, it also includes > libiberty.h. So these two asprintf conflicts when __USE_FORTIFY_LEVEL is set. I think the basic guideline should be that HAVE_DECL_ASPRINTF should be correct. If libiberty compiled with _GNU_SOURCE defined, then it should test HAVE_DECL_ASPRINTF with _GNU_SOURCE defined. If not, then not. So perhaps the problem is that libiberty is compiling some files with _GNU_SOURCE defined and some not. Ian ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-05-05 0:30 ` Ian Lance Taylor @ 2015-05-18 23:52 ` Yunlian Jiang 2015-05-19 0:15 ` Ian Lance Taylor 0 siblings, 1 reply; 15+ messages in thread From: Yunlian Jiang @ 2015-05-18 23:52 UTC (permalink / raw) To: Ian Lance Taylor; +Cc: gcc-patches Yes, the problem is libiberty is compiling some files with _GNU_SOURCE defined and some not. So the configure file does not include "#define _GNU_SOURCE". I have reduced the failing compiling as below. #define _GNU_SOURCE //// (1) #define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m))) #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m) #define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3) #include <stdio.h> //#define _GNU_SOURCE // (2) extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; it fails with command line /usr/bin/clang -fPIE -D_FORTIFY_SOURCE=2 -O2 -c f.c -o f.o If the _GNU_SOURCE is placed at (1), then the asprintf in the test case is a macro and it is expanded to extern int __asprintf_chk (char **, 2 - 1, const char *, ...) __attribute__ ((__format__ (__printf__, 2, 3))) __attribute__ ((__nonnull__ (2))); in the pre-processed file and causes compilation error. If the _GNU_SOURCE is placed at (2) or after stdio.h, then asprintf in the test case is still a function in the pre-processed file and it compiles. extern int asprintf (char **, const char *, ...) __attribute__ ((__format__ (__printf__, 2, 3))) __attribute__ ((__nonnull__ (2))); I then looked at the /usr/include/bits/stdio2.h, it has # ifdef __USE_GNU ... # ifdef __va_arg_pack __fortify_function int __NTH (asprintf (char **__restrict __ptr, const char *__restrict __fmt, ...)) { return __asprintf_chk (__ptr, __USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ()); } __fortify_function int __NTH (__asprintf (char **__restrict __ptr, const char *__restrict __fmt, ...)) { return __asprintf_chk (__ptr, __USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ()); } __fortify_function int __NTH (obstack_printf (struct obstack *__restrict __obstack, const char *__restrict __fmt, ...)) { return __obstack_printf_chk (__obstack, __USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ()); } # elif !defined __cplusplus # define asprintf(ptr, ...) \ __asprintf_chk (ptr, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) # define __asprintf(ptr, ...) \ __asprintf_chk (ptr, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) # define obstack_printf(obstack, ...) \ __obstack_printf_chk (obstack, __USE_FORTIFY_LEVEL - 1, __VA_ARGS__) # endif # endif It requires gcc to be at least 4.3 to have __va_arg_pack defined. Clang only has gcc 4.2. So clang chooses the asprintf macro and causes the problem. On Mon, May 4, 2015 at 5:30 PM, Ian Lance Taylor <iant@google.com> wrote: > On Mon, May 4, 2015 at 3:49 PM, Yunlian Jiang <yunlian@google.com> wrote: >> There was a similar disscussion here >> https://gcc.gnu.org/ml/gcc/2005-11/msg01190.html > > That was a discussion about libiberty. Your subject says you have > trouble building gdb. > > Can you describe the exact problem that you are having? What > precisely are you doing? What precisely happens? > > >> The problem is in the configure stage, the __GNU_SOURCE is not >> defined, and it could not find >> the declaration of asprintf. so it make a declaration of asprintf in >> libiberty.h. And for the file floatformat.c, >> the __GNU_SOURCE is defined, so it could find another asprintf in >> /usr/include/bits/stdio2.h, it also includes >> libiberty.h. So these two asprintf conflicts when __USE_FORTIFY_LEVEL is set. > > I think the basic guideline should be that HAVE_DECL_ASPRINTF should > be correct. If libiberty compiled with _GNU_SOURCE defined, then it > should test HAVE_DECL_ASPRINTF with _GNU_SOURCE defined. If not, then > not. So perhaps the problem is that libiberty is compiling some files > with _GNU_SOURCE defined and some not. > > Ian ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-05-18 23:52 ` Yunlian Jiang @ 2015-05-19 0:15 ` Ian Lance Taylor 2015-05-19 18:15 ` Yunlian Jiang 0 siblings, 1 reply; 15+ messages in thread From: Ian Lance Taylor @ 2015-05-19 0:15 UTC (permalink / raw) To: Yunlian Jiang; +Cc: gcc-patches On Mon, May 18, 2015 at 4:26 PM, Yunlian Jiang <yunlian@google.com> wrote: > > Yes, the problem is libiberty is compiling some files > with _GNU_SOURCE defined and some not. So the configure > file does not include "#define _GNU_SOURCE". As far as I can see it should be fine to define _GNU_SOURCE when compiling all libiberty files. Ian ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-05-19 0:15 ` Ian Lance Taylor @ 2015-05-19 18:15 ` Yunlian Jiang 2015-05-19 18:16 ` DJ Delorie 2015-05-19 18:16 ` Ian Lance Taylor 0 siblings, 2 replies; 15+ messages in thread From: Yunlian Jiang @ 2015-05-19 18:15 UTC (permalink / raw) To: Ian Lance Taylor; +Cc: gcc-patches I could do that and it make the compilation of libiberty passes. However, I have some other problem when using clang to build gdb because of libiberty. Some c file from other component may include 'libiberty.h' which contains the following #if !HAVE_DECL_ASPRINTF /* Like sprintf but provides a pointer to malloc'd storage, which must be freed by the caller. */ extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; #endif The HAVE_DECL_ASPRINTF is defined in config.h under libiberty directory. If the other c file only includes libiberty.h and does not include the libiberty/config.h and at the same time, _GNU_SOURCE is defind, the same error happens. On Mon, May 18, 2015 at 4:52 PM, Ian Lance Taylor <iant@google.com> wrote: > On Mon, May 18, 2015 at 4:26 PM, Yunlian Jiang <yunlian@google.com> wrote: >> >> Yes, the problem is libiberty is compiling some files >> with _GNU_SOURCE defined and some not. So the configure >> file does not include "#define _GNU_SOURCE". > > As far as I can see it should be fine to define _GNU_SOURCE when > compiling all libiberty files. > > Ian ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-05-19 18:15 ` Yunlian Jiang @ 2015-05-19 18:16 ` DJ Delorie 2015-05-19 18:16 ` Ian Lance Taylor 1 sibling, 0 replies; 15+ messages in thread From: DJ Delorie @ 2015-05-19 18:16 UTC (permalink / raw) To: Yunlian Jiang; +Cc: iant, gcc-patches > If the other c file only includes libiberty.h and does not include the > libiberty/config.h and In general, such "other c files" should have their own config.h that does the same test and has its own HAVE_DECL_ASPRINTF. That way, the config.h matches the compiler options being used, and not the compiler options libiberty's build used. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-05-19 18:15 ` Yunlian Jiang 2015-05-19 18:16 ` DJ Delorie @ 2015-05-19 18:16 ` Ian Lance Taylor 2015-05-20 18:28 ` Yunlian Jiang 1 sibling, 1 reply; 15+ messages in thread From: Ian Lance Taylor @ 2015-05-19 18:16 UTC (permalink / raw) To: Yunlian Jiang; +Cc: gcc-patches On Tue, May 19, 2015 at 11:08 AM, Yunlian Jiang <yunlian@google.com> wrote: > > I could do that and it make the compilation of libiberty passes. > However, I have some other problem when using clang to build gdb > because of libiberty. > > Some c file from other component may include 'libiberty.h' which contains > the following > > #if !HAVE_DECL_ASPRINTF > /* Like sprintf but provides a pointer to malloc'd storage, which must > be freed by the caller. */ > > extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; > #endif > > The HAVE_DECL_ASPRINTF is defined in config.h under libiberty directory. > If the other c file only includes libiberty.h and does not include the > libiberty/config.h and > at the same time, _GNU_SOURCE is defind, the same error happens. Probably if HAVE_DECL_ASPRINTF is not defined at all, we should not declare asprintf in libiberty.h. Ian ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-05-19 18:16 ` Ian Lance Taylor @ 2015-05-20 18:28 ` Yunlian Jiang 2015-05-20 20:15 ` Ian Lance Taylor 0 siblings, 1 reply; 15+ messages in thread From: Yunlian Jiang @ 2015-05-20 18:28 UTC (permalink / raw) To: Ian Lance Taylor; +Cc: gcc-patches I have the following change to make libiberty compile with _GNU_SOURCE defined and remove the declaration of asprintf in libiberty.h if HAVE_DECL_ASPRINTF is not defined. diff --git a/include/libiberty.h b/include/libiberty.h index b33dd65..8e096a0 100644 --- a/include/libiberty.h +++ b/include/libiberty.h @@ -621,7 +621,7 @@ extern int pexecute (const char *, char * const *, const char *, extern int pwait (int, int *, int); -#if !HAVE_DECL_ASPRINTF +#if defined(HAVE_DECL_ASPRINTF) && !HAVE_DECL_ASPRINTF /* Like sprintf but provides a pointer to malloc'd storage, which must be freed by the caller. */ diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in index f06cc69..624420d 100644 --- a/libiberty/Makefile.in +++ b/libiberty/Makefile.in @@ -113,7 +113,8 @@ installcheck: installcheck-subdir INCDIR=$(srcdir)/$(MULTISRCTOP)../include -COMPILE.c = $(CC) -c @DEFS@ $(CFLAGS) $(CPPFLAGS) -I. -I$(INCDIR) $(HDEFINES) @ac_libiberty_warn_cflags@ +COMPILE.c = $(CC) -c @DEFS@ $(CFLAGS) $(CPPFLAGS) -I. -I$(INCDIR) \ + $(HDEFINES) @ac_libiberty_warn_cflags@ -D_GNU_SOURCE # Just to make sure we don't use a built-in rule with VPATH .c.$(objext): diff --git a/libiberty/configure b/libiberty/configure index b06cab2..c6758b0 100755 --- a/libiberty/configure +++ b/libiberty/configure @@ -5130,6 +5130,9 @@ $as_echo "#define NEED_DECLARATION_ERRNO 1" >>confdefs.h fi +$as_echo "#define _GNU_SOURCE 1" >>confdefs.h + + # Determine sizes of some types. # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects diff --git a/libiberty/configure.ac b/libiberty/configure.ac index 922aa86..9f2d661 100644 --- a/libiberty/configure.ac +++ b/libiberty/configure.ac @@ -272,6 +272,8 @@ AC_HEADER_TIME libiberty_AC_DECLARE_ERRNO +AC_DEFINE(_GNU_SOURCE) + # Determine sizes of some types. AC_CHECK_SIZEOF([int]) AC_CHECK_SIZEOF([long]) diff --git a/libiberty/floatformat.c b/libiberty/floatformat.c index 789fa05..4e73a2d 100644 --- a/libiberty/floatformat.c +++ b/libiberty/floatformat.c @@ -19,7 +19,9 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ /* This is needed to pick up the NAN macro on some systems. */ +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #ifdef HAVE_CONFIG_H #include "config.h" On Tue, May 19, 2015 at 11:15 AM, Ian Lance Taylor <iant@google.com> wrote: > On Tue, May 19, 2015 at 11:08 AM, Yunlian Jiang <yunlian@google.com> wrote: >> >> I could do that and it make the compilation of libiberty passes. >> However, I have some other problem when using clang to build gdb >> because of libiberty. >> >> Some c file from other component may include 'libiberty.h' which contains >> the following >> >> #if !HAVE_DECL_ASPRINTF >> /* Like sprintf but provides a pointer to malloc'd storage, which must >> be freed by the caller. */ >> >> extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; >> #endif >> >> The HAVE_DECL_ASPRINTF is defined in config.h under libiberty directory. >> If the other c file only includes libiberty.h and does not include the >> libiberty/config.h and >> at the same time, _GNU_SOURCE is defind, the same error happens. > > Probably if HAVE_DECL_ASPRINTF is not defined at all, we should not > declare asprintf in libiberty.h. > > Ian ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-05-20 18:28 ` Yunlian Jiang @ 2015-05-20 20:15 ` Ian Lance Taylor 2015-05-20 23:27 ` Yunlian Jiang 0 siblings, 1 reply; 15+ messages in thread From: Ian Lance Taylor @ 2015-05-20 20:15 UTC (permalink / raw) To: Yunlian Jiang; +Cc: gcc-patches This is OK if GCC bootstraps. Thanks. Ian On Wed, May 20, 2015 at 11:25 AM, Yunlian Jiang <yunlian@google.com> wrote: > I have the following change to make libiberty compile with _GNU_SOURCE defined > and remove the declaration of asprintf in libiberty.h if > HAVE_DECL_ASPRINTF is not > defined. > > diff --git a/include/libiberty.h b/include/libiberty.h > index b33dd65..8e096a0 100644 > --- a/include/libiberty.h > +++ b/include/libiberty.h > @@ -621,7 +621,7 @@ extern int pexecute (const char *, char * const *, > const char *, > > extern int pwait (int, int *, int); > > -#if !HAVE_DECL_ASPRINTF > +#if defined(HAVE_DECL_ASPRINTF) && !HAVE_DECL_ASPRINTF > /* Like sprintf but provides a pointer to malloc'd storage, which must > be freed by the caller. */ > > diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in > index f06cc69..624420d 100644 > --- a/libiberty/Makefile.in > +++ b/libiberty/Makefile.in > @@ -113,7 +113,8 @@ installcheck: installcheck-subdir > > INCDIR=$(srcdir)/$(MULTISRCTOP)../include > > -COMPILE.c = $(CC) -c @DEFS@ $(CFLAGS) $(CPPFLAGS) -I. -I$(INCDIR) > $(HDEFINES) @ac_libiberty_warn_cflags@ > +COMPILE.c = $(CC) -c @DEFS@ $(CFLAGS) $(CPPFLAGS) -I. -I$(INCDIR) \ > + $(HDEFINES) @ac_libiberty_warn_cflags@ -D_GNU_SOURCE > > # Just to make sure we don't use a built-in rule with VPATH > .c.$(objext): > diff --git a/libiberty/configure b/libiberty/configure > index b06cab2..c6758b0 100755 > --- a/libiberty/configure > +++ b/libiberty/configure > @@ -5130,6 +5130,9 @@ $as_echo "#define NEED_DECLARATION_ERRNO 1" >>confdefs.h > fi > > > +$as_echo "#define _GNU_SOURCE 1" >>confdefs.h > + > + > # Determine sizes of some types. > # The cast to long int works around a bug in the HP C Compiler > # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects > diff --git a/libiberty/configure.ac b/libiberty/configure.ac > index 922aa86..9f2d661 100644 > --- a/libiberty/configure.ac > +++ b/libiberty/configure.ac > @@ -272,6 +272,8 @@ AC_HEADER_TIME > > libiberty_AC_DECLARE_ERRNO > > +AC_DEFINE(_GNU_SOURCE) > + > # Determine sizes of some types. > AC_CHECK_SIZEOF([int]) > AC_CHECK_SIZEOF([long]) > diff --git a/libiberty/floatformat.c b/libiberty/floatformat.c > index 789fa05..4e73a2d 100644 > --- a/libiberty/floatformat.c > +++ b/libiberty/floatformat.c > @@ -19,7 +19,9 @@ along with this program; if not, write to the Free Software > Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA > 02110-1301, USA. */ > > /* This is needed to pick up the NAN macro on some systems. */ > +#ifndef _GNU_SOURCE > #define _GNU_SOURCE > +#endif > > #ifdef HAVE_CONFIG_H > #include "config.h" > > On Tue, May 19, 2015 at 11:15 AM, Ian Lance Taylor <iant@google.com> wrote: >> On Tue, May 19, 2015 at 11:08 AM, Yunlian Jiang <yunlian@google.com> wrote: >>> >>> I could do that and it make the compilation of libiberty passes. >>> However, I have some other problem when using clang to build gdb >>> because of libiberty. >>> >>> Some c file from other component may include 'libiberty.h' which contains >>> the following >>> >>> #if !HAVE_DECL_ASPRINTF >>> /* Like sprintf but provides a pointer to malloc'd storage, which must >>> be freed by the caller. */ >>> >>> extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; >>> #endif >>> >>> The HAVE_DECL_ASPRINTF is defined in config.h under libiberty directory. >>> If the other c file only includes libiberty.h and does not include the >>> libiberty/config.h and >>> at the same time, _GNU_SOURCE is defind, the same error happens. >> >> Probably if HAVE_DECL_ASPRINTF is not defined at all, we should not >> declare asprintf in libiberty.h. >> >> Ian ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-05-20 20:15 ` Ian Lance Taylor @ 2015-05-20 23:27 ` Yunlian Jiang 2015-05-22 21:25 ` Ian Lance Taylor 0 siblings, 1 reply; 15+ messages in thread From: Yunlian Jiang @ 2015-05-20 23:27 UTC (permalink / raw) To: Ian Lance Taylor; +Cc: gcc-patches GCC bootstraps with this patch. On Wed, May 20, 2015 at 12:54 PM, Ian Lance Taylor <iant@google.com> wrote: > This is OK if GCC bootstraps. > > Thanks. > > Ian > > On Wed, May 20, 2015 at 11:25 AM, Yunlian Jiang <yunlian@google.com> wrote: >> I have the following change to make libiberty compile with _GNU_SOURCE defined >> and remove the declaration of asprintf in libiberty.h if >> HAVE_DECL_ASPRINTF is not >> defined. >> >> diff --git a/include/libiberty.h b/include/libiberty.h >> index b33dd65..8e096a0 100644 >> --- a/include/libiberty.h >> +++ b/include/libiberty.h >> @@ -621,7 +621,7 @@ extern int pexecute (const char *, char * const *, >> const char *, >> >> extern int pwait (int, int *, int); >> >> -#if !HAVE_DECL_ASPRINTF >> +#if defined(HAVE_DECL_ASPRINTF) && !HAVE_DECL_ASPRINTF >> /* Like sprintf but provides a pointer to malloc'd storage, which must >> be freed by the caller. */ >> >> diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in >> index f06cc69..624420d 100644 >> --- a/libiberty/Makefile.in >> +++ b/libiberty/Makefile.in >> @@ -113,7 +113,8 @@ installcheck: installcheck-subdir >> >> INCDIR=$(srcdir)/$(MULTISRCTOP)../include >> >> -COMPILE.c = $(CC) -c @DEFS@ $(CFLAGS) $(CPPFLAGS) -I. -I$(INCDIR) >> $(HDEFINES) @ac_libiberty_warn_cflags@ >> +COMPILE.c = $(CC) -c @DEFS@ $(CFLAGS) $(CPPFLAGS) -I. -I$(INCDIR) \ >> + $(HDEFINES) @ac_libiberty_warn_cflags@ -D_GNU_SOURCE >> >> # Just to make sure we don't use a built-in rule with VPATH >> .c.$(objext): >> diff --git a/libiberty/configure b/libiberty/configure >> index b06cab2..c6758b0 100755 >> --- a/libiberty/configure >> +++ b/libiberty/configure >> @@ -5130,6 +5130,9 @@ $as_echo "#define NEED_DECLARATION_ERRNO 1" >>confdefs.h >> fi >> >> >> +$as_echo "#define _GNU_SOURCE 1" >>confdefs.h >> + >> + >> # Determine sizes of some types. >> # The cast to long int works around a bug in the HP C Compiler >> # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects >> diff --git a/libiberty/configure.ac b/libiberty/configure.ac >> index 922aa86..9f2d661 100644 >> --- a/libiberty/configure.ac >> +++ b/libiberty/configure.ac >> @@ -272,6 +272,8 @@ AC_HEADER_TIME >> >> libiberty_AC_DECLARE_ERRNO >> >> +AC_DEFINE(_GNU_SOURCE) >> + >> # Determine sizes of some types. >> AC_CHECK_SIZEOF([int]) >> AC_CHECK_SIZEOF([long]) >> diff --git a/libiberty/floatformat.c b/libiberty/floatformat.c >> index 789fa05..4e73a2d 100644 >> --- a/libiberty/floatformat.c >> +++ b/libiberty/floatformat.c >> @@ -19,7 +19,9 @@ along with this program; if not, write to the Free Software >> Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA >> 02110-1301, USA. */ >> >> /* This is needed to pick up the NAN macro on some systems. */ >> +#ifndef _GNU_SOURCE >> #define _GNU_SOURCE >> +#endif >> >> #ifdef HAVE_CONFIG_H >> #include "config.h" >> >> On Tue, May 19, 2015 at 11:15 AM, Ian Lance Taylor <iant@google.com> wrote: >>> On Tue, May 19, 2015 at 11:08 AM, Yunlian Jiang <yunlian@google.com> wrote: >>>> >>>> I could do that and it make the compilation of libiberty passes. >>>> However, I have some other problem when using clang to build gdb >>>> because of libiberty. >>>> >>>> Some c file from other component may include 'libiberty.h' which contains >>>> the following >>>> >>>> #if !HAVE_DECL_ASPRINTF >>>> /* Like sprintf but provides a pointer to malloc'd storage, which must >>>> be freed by the caller. */ >>>> >>>> extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; >>>> #endif >>>> >>>> The HAVE_DECL_ASPRINTF is defined in config.h under libiberty directory. >>>> If the other c file only includes libiberty.h and does not include the >>>> libiberty/config.h and >>>> at the same time, _GNU_SOURCE is defind, the same error happens. >>> >>> Probably if HAVE_DECL_ASPRINTF is not defined at all, we should not >>> declare asprintf in libiberty.h. >>> >>> Ian ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH/libiberty] fix build of gdb/binutils with clang. 2015-05-20 23:27 ` Yunlian Jiang @ 2015-05-22 21:25 ` Ian Lance Taylor 0 siblings, 0 replies; 15+ messages in thread From: Ian Lance Taylor @ 2015-05-22 21:25 UTC (permalink / raw) To: Yunlian Jiang; +Cc: gcc-patches [-- Attachment #1: Type: text/plain, Size: 518 bytes --] On Wed, May 20, 2015 at 3:58 PM, Yunlian Jiang <yunlian@google.com> wrote: > GCC bootstraps with this patch. Committed as follows. Ian include/: 2015-05-22 Yunlian Jiang <yunlian@google.com> * libiberty.h (asprintf): Don't declare if HAVE_DECL_ASPRINTF is not defined. libiberty/: 2015-05-22 Yunlian Jiang <yunlian@google.com> * configure.ac: Add AC_GNU_SOURCE. * Makefile.in (COMPILE.c): Add -D_GNU_SOURCE. * configure, config.in: Rebuild. * floatformat.c (_GNU_SOURCE): Don't define if already defined. [-- Attachment #2: foo.txt --] [-- Type: text/plain, Size: 1898 bytes --] Index: include/libiberty.h =================================================================== --- include/libiberty.h (revision 223578) +++ include/libiberty.h (working copy) @@ -621,7 +621,7 @@ extern int pexecute (const char *, char extern int pwait (int, int *, int); -#if !HAVE_DECL_ASPRINTF +#if defined(HAVE_DECL_ASPRINTF) && !HAVE_DECL_ASPRINTF /* Like sprintf but provides a pointer to malloc'd storage, which must be freed by the caller. */ Index: libiberty/Makefile.in =================================================================== --- libiberty/Makefile.in (revision 223578) +++ libiberty/Makefile.in (working copy) @@ -113,7 +113,8 @@ installcheck: installcheck-subdir INCDIR=$(srcdir)/$(MULTISRCTOP)../include -COMPILE.c = $(CC) -c @DEFS@ $(CFLAGS) $(CPPFLAGS) -I. -I$(INCDIR) $(HDEFINES) @ac_libiberty_warn_cflags@ +COMPILE.c = $(CC) -c @DEFS@ $(CFLAGS) $(CPPFLAGS) -I. -I$(INCDIR) \ + $(HDEFINES) @ac_libiberty_warn_cflags@ -D_GNU_SOURCE # Just to make sure we don't use a built-in rule with VPATH .c.$(objext): Index: libiberty/configure.ac =================================================================== --- libiberty/configure.ac (revision 223578) +++ libiberty/configure.ac (working copy) @@ -155,6 +155,7 @@ AC_MSG_NOTICE([target_header_dir = $targ GCC_NO_EXECUTABLES AC_PROG_CC +AC_GNU_SOURCE AC_SYS_LARGEFILE AC_PROG_CPP_WERROR Index: libiberty/floatformat.c =================================================================== --- libiberty/floatformat.c (revision 223578) +++ libiberty/floatformat.c (working copy) @@ -19,7 +19,9 @@ along with this program; if not, write t Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ /* This is needed to pick up the NAN macro on some systems. */ +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #ifdef HAVE_CONFIG_H #include "config.h" ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2015-05-22 20:55 UTC | newest] Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-04-28 22:30 [PATCH/libiberty] fix build of gdb/binutils with clang Yunlian Jiang 2015-05-01 22:45 ` Ian Lance Taylor 2015-05-01 23:45 ` Yunlian Jiang 2015-05-02 18:58 ` Ian Lance Taylor 2015-05-04 22:49 ` Yunlian Jiang 2015-05-05 0:30 ` Ian Lance Taylor 2015-05-18 23:52 ` Yunlian Jiang 2015-05-19 0:15 ` Ian Lance Taylor 2015-05-19 18:15 ` Yunlian Jiang 2015-05-19 18:16 ` DJ Delorie 2015-05-19 18:16 ` Ian Lance Taylor 2015-05-20 18:28 ` Yunlian Jiang 2015-05-20 20:15 ` Ian Lance Taylor 2015-05-20 23:27 ` Yunlian Jiang 2015-05-22 21:25 ` Ian Lance Taylor
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).