[Bug c++/111034] New: Precompiled headers still non-deterministic

2023-08-15 Thread skunk at iskunk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111034

Bug ID: 111034
   Summary: Precompiled headers still non-deterministic
   Product: gcc
   Version: 13.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: skunk at iskunk dot org
  Target Milestone: ---

This is a follow-on of bug #92717.

In that bug, it was noted that .gch files are basically GCC memory dumps, and
that because ASLR is typically enabled on modern Linux systems, this results in
non-deterministic output every time such a file is generated.

The solution given was to disable ASLR, e.g. by using "setarch -R". And I
confirmed that if I generate the same .gch file multiple times in a tight loop
with ASLR disabled, every file comes out identical.

That was only a test, however. My production fix was to disable ASLR for the
entire build process, with "setarch -R make bootstrap".

And that yielded much spottier results. After multiple attempts, maybe 10% of
the pairs of bootstraps that I ran came out with identical .gch files. And that
was running on the same container host---if I tried the build in the same
container architecture/environment but a different host, the files would end up
different as a matter of course.

I think, in the interests of reproducibility, the way .gch files are generated
needs to be reworked in a way that does not depend on the runtime environment.
The current approach may be fine for PCH purposes, but the security
implications of any opaque non-determinism will only get worse with time.

[Bug c++/111033] New: libcody build does not use AR_FLAGS

2023-08-15 Thread skunk at iskunk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111033

Bug ID: 111033
   Summary: libcody build does not use AR_FLAGS
   Product: gcc
   Version: 13.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: skunk at iskunk dot org
  Target Milestone: ---

I am working on getting a reproducible GCC build. This includes passing the "D"
option to ar(1) to avoid non-deterministic static library outputs.

In bootstrapping 13.2.0, I noticed that libcody.a was not being generated
consistently. The libcody makefile has the following:

AR := @AR@

...

$(AR) -cr $@ $^

For comparison, in the rest of the GCC tree, you typically see

AR = @AR@
AR_FLAGS = rc

...

$(AR) $(AR_FLAGS) libfoo.a ...

and AR_FLAGS is the natural place to add additional flags. An AR_FLAGS variable
should thus likewise be added to the libcody makefile.

(ARFLAGS is also used; I am not entirely sure which form is favored.)

Beyond addressing this small inconsistency, it would be good to see the GCC
build itself check whether ar(1) supports the "D" flag, and add it
automatically if so.

[Bug tree-optimization/106247] GCC12 warning in Eigen: array subscript is partly outside array bounds

2022-08-01 Thread skunk at iskunk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106247

Daniel Richard G.  changed:

   What|Removed |Added

 CC||skunk at iskunk dot org

--- Comment #4 from Daniel Richard G.  ---
I am seeing what may be the same issue in a different context.

This is occurring in a proprietary C source codebase newly being compiled with
12.1.0, and unfortunately the problem goes away if I attempt to cut it down to
a minimal test case. Nevertheless, the actual issue is quite simple, and IMO
clear-cut.

(some names edited to protect the guilty)

In file included from /usr/include/string.h:375,
 from foo.c:7:
In function 'function3',
inlined from 'function2' at foo.c:1206:5,
inlined from 'function1' at foo.c:2840:7:
foo.c:415:3: error: array subscript 'union [1]' is partly outside
array bounds of 'unsigned char[5]' [-Werror=array-bounds]
  415 |   memset(constraints,0,sizeof(char)*NB_CONSTRAINTS);
  |   ^~
foo.c: In function 'function1':
foo.c:380:17: note: at offset 4 into object 'constraints' of size 5
  380 |   unsigned char constraints[NB_CONSTRAINTS];
  | ^~~~
cc1: all warnings being treated as errors


Curiously enough, I only see this issue in an i686 build. I don't get it on
x86-64. (Dropping -march=i686 does not help.)

[Bug libstdc++/106501] New: libstdc++ is built without -fPIC despite --with-pic

2022-08-01 Thread skunk at iskunk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106501

Bug ID: 106501
   Summary: libstdc++ is built without -fPIC despite --with-pic
   Product: gcc
   Version: 12.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: skunk at iskunk dot org
  Target Milestone: ---
  Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
 Build: x86_64-pc-linux-gnu

I bootstrapped GCC 12.1.0 with the following options:

--disable-shared
--disable-nls
--enable-version-specific-runtime-libs
--with-pic
--disable-multilib
--with-arch=opteron
--disable-libsanitizer
--disable-libcc1
--enable-languages=c,c++,lto

Notable is the combination of "--disable-shared --with-pic", with the intention
of having all the GCC support libraries be statically linkable when building
executables, shared libraries, etc.

Once the bootstrap was complete, I used the new GCC to build a current version
of GDB. That build failed with

  CXXLD  libinproctrace.so
/usr/bin/ld:
/opt/sfw/bin/../lib/gcc/x86_64-pc-linux-gnu/12.1.0/libstdc++.a(class_type_info.o):
relocation R_X86_64_32S against `_ZTVN10__cxxabiv117__class_type_infoE' can not
be used when making a shared object; recompile with -fPIC
/opt/sfw/bin/../lib/gcc/x86_64-pc-linux-gnu/12.1.0/libstdc++.a: could not read
symbols: Bad value
collect2: error: ld returned 1 exit status
gmake[2]: *** [Makefile:383: libinproctrace.so] Error 1
gmake[2]: Leaving directory '/tmp/gdb-12.1-build/gdbserver'
gmake[1]: *** [Makefile:11743: all-gdbserver] Error 2
gmake[1]: Leaving directory '/tmp/gdb-12.1-build'
gmake: *** [Makefile:1001: all] Error 2


I checked the build log for GCC. None of the compile lines for
class_type_info.o include the -fPIC option (i.e. "fgrep class_type_info.o
gcc12-build-log.txt | grep -c PIC" yields 0).

The --with-pic option should cause all libraries to be built with -fPIC, even
when they are built as static archives. It is possible that libstdc++ is not
the only library that was built incorrectly; it is only the one I noticed.

Related: bug #66955, bug #67128

[Bug bootstrap/106482] [12 Regression] bootstrap of 12.1.0 using 4.8.2 fails with C++ errors

2022-08-01 Thread skunk at iskunk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106482

--- Comment #2 from Daniel Richard G.  ---
It would be good to have a specific minimum version of GCC in the documented
prerequisites, as the current text ("an existing GCC binary (version 4.8 or
later)", albeit referring to non-bootstrap builds) misses edge cases like this.

[Bug bootstrap/106482] New: [12 Regression] bootstrap of 12.1.0 using 4.8.2 fails with C++ errors

2022-07-30 Thread skunk at iskunk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106482

Bug ID: 106482
   Summary: [12 Regression] bootstrap of 12.1.0 using 4.8.2 fails
with C++ errors
   Product: gcc
   Version: 12.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: bootstrap
  Assignee: unassigned at gcc dot gnu.org
  Reporter: skunk at iskunk dot org
  Target Milestone: ---
  Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
 Build: x86_64-pc-linux-gnu

I attempted to bootstrap 12.1.0 using GCC 4.8.2. The documented prerequisites
include an "ISO C++11 compiler," so this appears to be a supported arrangement.

GCC 12 was configured with --disable-shared --disable-nls
--enable-version-specific-runtime-libs --with-pic --disable-multilib
--with-arch=opteron --disable-libcc1 --enable-languages=c,c++,lto

The bootstrap failed as shown below. I was able to bootstrap 10.2.0 using the
original compiler, and then bootstrapped 12.1.0 with that intermediary.


tg-g++ -std=c++11  -fno-PIE -c   -g -DIN_GCC -fno-exceptions -fno-rtti
-fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings
-Wcast-qual -Wno-format -Wmissing-format-attribute -Woverloaded-virtual
-pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings
-fno-common  -DHAVE_CONFIG_H -I. -I. -I/home/src/gcc-12.1.0/gcc
-I/home/src/gcc-12.1.0/gcc/. -I/home/src/gcc-12.1.0/gcc/../include
-I/home/src/gcc-12.1.0/gcc/../libcpp/include
-I/home/src/gcc-12.1.0/gcc/../libcody -I/home/sfw/arch/linux64/include
-I/home/sfw/arch/linux64/include -I/home/sfw/arch/linux64/include 
-I/home/src/gcc-12.1.0/gcc/../libdecnumber
-I/home/src/gcc-12.1.0/gcc/../libdecnumber/bid -I../libdecnumber
-I/home/src/gcc-12.1.0/gcc/../libbacktrace   -o fwprop.o -MT fwprop.o -MMD -MP
-MF ./.deps/fwprop.TPo /home/src/gcc-12.1.0/gcc/fwprop.cc
In file included from /home/src/gcc-12.1.0/gcc/splay-tree-utils.h:491:0,
 from /home/src/gcc-12.1.0/gcc/rtl-ssa.h:45,
 from /home/src/gcc-12.1.0/gcc/fwprop.cc:29:
/home/src/gcc-12.1.0/gcc/splay-tree-utils.tcc:24:1: error: prototype for
'typename base_splay_tree::node_type
base_splay_tree::get_child(typename Accessors::node_type, unsigned
int)' does not match any in class 'base_splay_tree'
 base_splay_tree::get_child (node_type node, unsigned int index)
 ^
In file included from /home/src/gcc-12.1.0/gcc/rtl-ssa.h:45:0,
 from /home/src/gcc-12.1.0/gcc/fwprop.cc:29:
/home/src/gcc-12.1.0/gcc/splay-tree-utils.h:125:20: error: candidate is: static
typename Accessors::node_type base_splay_tree::get_child(typename
Accessors::node_type, unsigned int)
   static node_type get_child (node_type, unsigned int);
^
In file included from /home/src/gcc-12.1.0/gcc/splay-tree-utils.h:491:0,
 from /home/src/gcc-12.1.0/gcc/rtl-ssa.h:45,
 from /home/src/gcc-12.1.0/gcc/fwprop.cc:29:
/home/src/gcc-12.1.0/gcc/splay-tree-utils.tcc:49:1: error: prototype for
'typename base_splay_tree::node_type
base_splay_tree::promote_child(typename Accessors::node_type,
unsigned int)' does not match any in class 'base_splay_tree'
 base_splay_tree::promote_child (node_type node, unsigned int index)
 ^
In file included from /home/src/gcc-12.1.0/gcc/rtl-ssa.h:45:0,
 from /home/src/gcc-12.1.0/gcc/fwprop.cc:29:
/home/src/gcc-12.1.0/gcc/splay-tree-utils.h:128:15: error: candidates are:
static void base_splay_tree::promote_child(typename
Accessors::node_type, unsigned int, typename Accessors::node_type)
   static void promote_child (node_type, unsigned int, node_type);
   ^
/home/src/gcc-12.1.0/gcc/splay-tree-utils.h:127:20: error:
static typename Accessors::node_type
base_splay_tree::promote_child(typename Accessors::node_type,
unsigned int)
   static node_type promote_child (node_type, unsigned int);
^
In file included from /home/src/gcc-12.1.0/gcc/splay-tree-utils.h:491:0,
 from /home/src/gcc-12.1.0/gcc/rtl-ssa.h:45,
 from /home/src/gcc-12.1.0/gcc/fwprop.cc:29:
/home/src/gcc-12.1.0/gcc/splay-tree-utils.tcc:187:1: error: prototype for
'typename base_splay_tree::node_type
base_splay_tree::splay_limit(typename Accessors::node_type)' does
not match any in class 'base_splay_tree'
 base_splay_tree::splay_limit (node_type start)
 ^
In file included from /home/src/gcc-12.1.0/gcc/rtl-ssa.h:45:0,
 from /home/src/gcc-12.1.0/gcc/fwprop.cc:29:
/home/src/gcc-12.1.0/gcc/splay-tree-utils.h:131:20: error: candidate is:
template template static typename
Accessors::node_type base_splay_tree::splay_limit(typename
Accessors::node_type)
   static node_type splay_limit (node_type);
^
In file included from /home/src/gcc-12.1.0/gcc/splay-tree-utils.h:491:0,
 from /home/src/gcc-12.1.0/gcc/rtl-ssa.h:45,
 from /home/sr