Bug 106779 - GCC 12.2 fails to compile in libiberty - uknown symbol PTR - requires later patch
Summary: GCC 12.2 fails to compile in libiberty - uknown symbol PTR - requires later p...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 12.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2022-08-30 16:30 UTC by Todd Richmond
Modified: 2022-08-31 07:48 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Todd Richmond 2022-08-30 16:30:41 UTC
I have been able to build every gcc release from 8 to 12.2 on both CentOS6 and CentOS 7 w/o problem including 12.1. However, 12.2 fails to compile libiberty/objdump.c due to "PTR" not being defined. I tried compiling with 10.2, 11.3 and 12.1 w/o success

However, a big change was recently checked into libiberty that eliminates the PTR macro, but 12.2 does not include it. I can confirm that this diff works correctly

https://github.com/gcc-mirror/gcc/commit/50b009c5daef92bc60fc26fcc4c495e117667387.patch
Comment 1 Todd Richmond 2022-08-30 16:33:13 UTC
filename is likely wrong - I did this 2 days ago and lost the log output. 100% consistent on 2 different build systems/OS though
Comment 2 Jakub Jelinek 2022-08-30 17:12:04 UTC
Without seeing a build log on what exactly fails there is nothing we can do about it, applying the [PATCH] libiberty: stop using PTR macro change is not the right fix if anything needs to be fixed at all.
Note, there were no changes whatsoever in include/ or libiberty/ directories except for a 12.2.0 release added ChangeLog entry, so I somehow can't believe 12.1 worked fine and 12.2 doesn't if nothing else changed.
Comment 3 Todd Richmond 2022-08-30 17:59:00 UTC
We have been using the same build setup for the last 20 years and this is the 1st gcc failure :) We build EVERYTHING in a self contained fashion and don't rely on any OS libraries except libc.so.
I don't know what file normally defines PTR, but someone else must have run into this for the patch to have been checked in
Below log is from a CentOS 7 compile using gcc 12.1

/tools/arch/Linux_3.10.0-x86_64/gcc-12.1.0-bootstrap/bin/gcc -c -DHAVE_CONFIG_H -fPIC -pipe -DNDEBUG -Wno-error=unused-value -Wno-unused-variable  -I/tools/arch/Linux_3.10.0-x86_64/gcc-12.1.0-bootstrap//include    -I. -I/var/tmp/gcc-12.2.0-bootstrap/gcc-12.2.0/libiberty/../include  -W -Wall -Wwrite-strings -Wc++-compat -Wstrict-prototypes -Wshadow=local -pedantic  -D_GNU_SOURCE -fcf-protection /var/tmp/gcc-12.2.0-bootstrap/gcc-12.2.0/libiberty/objalloc.c -o objalloc.o

/var/tmp/gcc-12.2.0-bootstrap/gcc-12.2.0/libiberty/objalloc.c: In function ‘objalloc_create’:
/var/tmp/gcc-12.2.0-bootstrap/gcc-12.2.0/libiberty/objalloc.c:95:18: error: ‘PT’ undeclared (first use in this function)
   95 |   ret->chunks = (PTR) malloc (CHUNK_SIZE);
      |                  ^~~
/var/tmp/gcc-12.2.0-bootstrap/gcc-12.2.0/libiberty/objalloc.c:95:18: note: each undeclared identifier is reported only once for each function it appears in
/var/tmp/gcc-12.2.0-bootstrap/gcc-12.2.0/libiberty/objalloc.c:95:22: error: expected ‘;’ before ‘malloc’
   95 |   ret->chunks = (PTR) malloc (CHUNK_SIZE);
      |                      ^~~~~~~
      |                      ;
/var/tmp/gcc-12.2.0-bootstrap/gcc-12.2.0/libiberty/objalloc.c: At top level:
/var/tmp/gcc-12.2.0-bootstrap/gcc-12.2.0/libiberty/objalloc.c:114:1: error: unknown type name ‘PTR’
  114 | PTR
      | ^~~
/var/tmp/gcc-12.2.0-bootstrap/gcc-12.2.0/libiberty/objalloc.c:115:1: error: conflicting types for ‘_objalloc_alloc’; have ‘int(struct objalloc *, long unsigned int)’
  115 | _objalloc_alloc (struct objalloc *o, unsigned long original_len)
      | ^~~~~~~~~~~~~~~
Comment 4 Todd Richmond 2022-08-30 18:00:45 UTC
one other comment. all the gcc prereqs are the latest available releases - every 3rd party package is built by us from the most up-to-date versions
Comment 5 Jakub Jelinek 2022-08-30 18:04:20 UTC
include/ansidecl.h has:
#if defined (__STDC__) || defined(__cplusplus) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32)
...
#define PTR             void *
...
#else   /* Not ANSI C.  */
#define PTR             char *
...
#endif
So, can you rerun the above command line with -E -dD instead of -c and
-o objalloc.i instead of -o objalloc.o ?
Comment 6 Jakub Jelinek 2022-08-30 18:10:21 UTC
Where does the:
-I/tools/arch/Linux_3.10.0-x86_64/gcc-12.1.0-bootstrap//include
come there?  If it e.g. contains glibc fixincluded ansidecl.h, then that could explain why it breaks.
But you don't want to use your build compiler's include directories in preference over the build tree ones.
Comment 7 Todd Richmond 2022-08-30 19:07:16 UTC
i was playing w/ cmdline and had deleted an extra arg. the 12.2 path is before the 12.1 path.  However, our build scripts include the correct gcc header dir to all configure lines to ensure we don't pull in the system gcc headers. This causes 12.2 to include the source include dir (var/tmp...) last instead of first

It is strange that this only fails for 12.2. I rebuilt 12.1 yesterday w/o issue so did something change in Makefile.in or a configure script that changed the include order?

I can confirm that removing the original gcc include paths from the compile works correctly

fail:

/tools/arch/Linux_3.10.0-x86_64/gcc-12.1.0-bootstrap/bin/gcc -c -DHAVE_CONFIG_H -fPIC -O3 -pipe -DNDEBUG -Wno-error=unused-value -Wno-unused-variable  -I/tools/arch/Linux_3.10.0-x86_64/gcc-12.2.0-bootstrap/include -I/tools/arch/Linux_3.10.0-x86_64/gcc-12.1.0-bootstrap//include    -I. -I/var/tmp/gcc-12.2.0-bootstrap/gcc-12.2.0/libiberty/../include  -W -Wall -Wwrite-strings -Wc++-compat -Wstrict-prototypes -Wshadow=local -pedantic  -D_GNU_SOURCE -fcf-protection /var/tmp/gcc-12.2.0-bootstrap/gcc-12.2.0/libiberty/objalloc.c -o objalloc.o

succeed:
/tools/arch/Linux_3.10.0-x86_64/gcc-12.1.0-bootstrap/bin/gcc -c -DHAVE_CONFIG_H -fPIC -O3 -pipe -ffunction-sections -fdata-sections -march=nehalem -mtune=broadwell -DNDEBUG -Wno-error=unused-value -Wno-unused-variable   -I. -I/var/tmp/gcc-12.2.0-bootstrap/gcc-12.2.0/libiberty/../include  -W -Wall -Wwrite-strings -Wc++-compat -Wstrict-prototypes -Wshadow=local -pedantic  -D_GNU_SOURCE -fcf-protection /var/tmp/gcc-12.2.0-bootstrap/gcc-12.2.0/libiberty/objalloc.c -o objalloc.o
Comment 8 Eric Gallager 2022-08-30 23:42:57 UTC
(In reply to Todd Richmond from comment #0)
> I have been able to build every gcc release from 8 to 12.2 on both CentOS6
> and CentOS 7 w/o problem including 12.1. However, 12.2 fails to compile
> libiberty/objdump.c due to "PTR" not being defined. I tried compiling with
> 10.2, 11.3 and 12.1 w/o success
> 
> However, a big change was recently checked into libiberty that eliminates
> the PTR macro, but 12.2 does not include it. I can confirm that this diff
> works correctly
> 
> https://github.com/gcc-mirror/gcc/commit/
> 50b009c5daef92bc60fc26fcc4c495e117667387.patch

cc-ing author of this patch
Comment 9 Jakub Jelinek 2022-08-31 07:48:24 UTC
So this is a clear bug in your build scripts then.
You just can't add -I options that to configure/make variables where it will override -I paths added during the build, the build compilers paths need to always come after the other paths (and that is what happens by default, compiler always searches its own paths unless -nostdinc or -nostdinc++).
Don't do it and it will build fine.