[Bug c++/92717] New: precompiled headers non-deterministic

2019-11-28 Thread gnu.org at mrks dot info
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92717

Bug ID: 92717
   Summary: precompiled headers non-deterministic
   Product: gcc
   Version: 9.2.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gnu.org at mrks dot info
  Target Milestone: ---

I found that introducing precompiled headers to my project causes ccache
lookups to fail. I tracked it down to the gcc output not being deterministic:

# /usr/bin/c++ -x c++-header -include test.hxx -o test.hxx.gch -c test.hxx.cxx
&& md5sum test.hxx.gch
3a0efb998351939f4ed8efcfce1c0015  test.hxx.gch
# /usr/bin/c++ -x c++-header -include test.hxx -o test.hxx.gch -c test.hxx.cxx
&& md5sum test.hxx.gch
d295cbe3613100e6d989e62e3aafad6c  test.hxx.gch

Both test.hxx and test.hxx.cxx are empty. The used gcc version is
9.2.1-9ubuntu2.

With clang (clang++ -cc1 test.hxx -emit-pch -o test.hxx.pch), the hashes match.

When compiling with save-temps, the ii and s files match.

As builds of regular C(++) files are deterministic (as expected), I suspect
that this might be a bug.

[Bug c++/92717] precompiled headers non-deterministic

2019-11-28 Thread gnu.org at mrks dot info
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92717

--- Comment #2 from Markus Dreseler  ---
> Try using __DATE__ macro and you will see it is not :).

Can't confirm:

# /usr/bin/c++ -D__DATE__=0 -D__TIMESTAMP__=0 -D__TIME__=0 -x c++-header
-include test.hxx -o test.hxx.gch -c test.hxx.cxx && md5sum test.hxx.gch

produces some new warnings, but again different file hashes.

Here are some other options that I have tested but that have no effect:
* SOURCE_DATE_EPOCH=0
* -fno-pie
* -nodefaultlibs -nostartfiles -nostdlib

[Bug c++/92717] precompiled headers non-deterministic

2019-11-28 Thread gnu.org at mrks dot info
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92717

--- Comment #4 from Markus Dreseler  ---
> By any chance, is your cc1plus built as PIE?  PCH doesn't work in that case.

I don't think so:

# file `find /usr -name cc1plus`
/usr/lib/gcc/x86_64-linux-gnu/9/cc1plus: ELF 64-bit LSB executable, x86-64,
version 1 (GNU/Linux), dynamically linked, interpreter
/lib64/ld-linux-x86-64.so.2,
BuildID[sha1]=ab2940b3dc6bbacbb2b3f15e7cdcdd416e74b3b8, for GNU/Linux 3.2.0,
stripped

This would say "LSB pie executable" otherwise, correct?

gcc 9.2.1 comes from the Ubuntu 19.10 repos.

[Bug c++/92717] precompiled headers non-deterministic

2019-11-28 Thread gnu.org at mrks dot info
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92717

--- Comment #5 from Markus Dreseler  ---
I took Andrew's __DATE__ suggestion as a reason to look at how much the files
actually differ. `cmp -l v1 v2 | wc -l` gives me 692634 differing bytes. This
sounds like the difference is bigger than just some macro values.

P.S.: Same issue on Mac with g++-8 (Homebrew GCC 8.2.0).

[Bug c++/92717] precompiled headers non-deterministic

2019-11-29 Thread gnu.org at mrks dot info
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92717

--- Comment #8 from Markus Dreseler  ---
Interesting. Is this implementation documented somewhere?

I can confirm that disabling ASLR results in reproducible gchs:

# setarch $(uname -m) -R /usr/bin/c++ -x c++-header -include test.hxx -o
test.hxx.gch -c test.hxx.cxx && md5sum test.hxx.gch
54486c6ffc08db87d4b58792dcb46091  test.hxx.gch
# setarch $(uname -m) -R /usr/bin/c++ -x c++-header -include test.hxx -o
test.hxx.gch -c test.hxx.cxx && md5sum test.hxx.gch
54486c6ffc08db87d4b58792dcb46091  test.hxx.gch

For CI builds of trusted files, this might be an option, but generally setting
the ADDR_NO_RANDOMIZE personality for gcc when gchs are build does not sound
like a good approach.