Closed jimis closed 1 month ago
Interesting. We already included langauge
in the hash calculation:
Isn't language
the input language? Both input files are C++ code. The different is in the output format.
According to my experiments, it's the parameter -x c++-header
that makes GCC generate GCH file.
GCC's logic that determines the output format is a bit complicated, and depends on the extension of the main input file and on the -x
option. According to GCC docs:
-x language
Specify explicitly the language for the following input files (rather than letting the compiler choose a default based on the file name suffix). This option applies to all following input files until the next -x option.
After experimenting, here is GCC's behaviour, without sccache involved:
gcc -o blah -c cmake_pch.hxx.cxx
generates object codegcc -o blah -c cmake_pch.hxx.hxx
generates precompiled header filegcc -x c++-header -o blah -c whatever_filename_and_extension_you_like
generates precompiled header file~I guess Sccache doesn't take -x
into consideration?~
EDIT: scratch that, apparently it does:
https://github.com/mozilla/sccache/blob/7074753bfc100ee3e22dc730cf71f3750fc42c1d/src/compiler/gcc.rs#L609-L620
Another thing to note is that all the .cpp
files that get mis-compiled are empty i.e. contain only comments (class documentation). And the cmake_pch.hxx.cxx file is also empty, contains only a single comment line.
So here my current theory:
-E
) first, with output to stdout
-E
parameter, outputs the same preprocessed source regardless of the -x
argument it has on the command line[2023-08-01T16:20:57Z TRACE sccache::compiler::gcc] compile
[2023-08-01T16:20:57Z DEBUG sccache::compiler::compiler] [cmake_pch.hxx.gch]: Compiling locally
-x
argument. But sccache stores them under the same hash key.
Simplest way to reproduce the issue:
$ touch empty.c
$ gcc -c -o out1 empty.c
$ gcc -x c-header -c -o out2 empty.c
$ file out1 out2
out1: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
out2: GCC precompiled header (version 014) for C
The two files are different. But if we feed these compilations to sccache, they lead to the same result:
$ sccache gcc -c -o out3 empty.c
$ sccache gcc -x c-header -c -o out4 empty.c
$ file out3 out4
out3: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
out4: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
I'm editing the description to avoid misleading people through heaps of debugging info.
Simplest way to reproduce the issue (EDIT as of 2024-10-04)
The two files are different. But if we feed these compilations to sccache, they lead to the same result:
Old Summary
The problem manifests as this error message during linking:
The reason is that
archdetect.cpp.o
and a few other files, have been mis-compiled to contain precompiled headers instead of object code:Digging into the problem
Command lines generated by ninja on the client
cmake_pch.hxx.gch
[420/2442] sccache /usr/bin/g++ -DBACKTRACE_HEADER=\"execinfo.h\" -DCore_EXPORTS -DELF_INTERPRETER=\"/lib64/ld-linux-x86-64.so.2\" -DPCRE2_CODE_UNIT_WIDTH=16 -DQT_ASCII_CAST_WARNINGS -DQT_BUILDING_QT -DQT_BUILD_CORE_LIB -DQT_DEPRECATED_WARNINGS -DQT_DISABLE_DEPRECATED_UP_TO=0x050000 -DQT_EXPLICIT_QFILE_CONSTRUCTION_FROM_PATH -DQT_LEAN_HEADERS=1 -DQT_MOC_COMPAT -DQT_NO_AS_CONST -DQT_NO_CAST_TO_ASCII -DQT_NO_CONTEXTLESS_CONNECT -DQT_NO_DEBUG -DQT_NO_FOREACH -DQT_NO_JAVA_STYLE_ITERATORS -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_NO_QEXCHANGE -DQT_NO_USING_NAMESPACE -DQT_TYPESAFE_FLAGS -DQT_USE_QSTRINGBUILDER -DQT_WARN_DEPRECATED_UP_TO=0x070000 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I/home/qt/work/qt/qtbase_build/src/corelib/Core_autogen/include -I/home/qt/work/qt/qtbase_build/include -I/home/qt/work/qt/qtbase_build/include/QtCore -I/home/qt/work/qt/qtbase/src/corelib -I/home/qt/work/qt/qtbase_build/src/corelib -I/home/qt/work/qt/qtbase_build/src/corelib/global -I/home/qt/work/qt/qtbase_build/src/corelib/kernel -I/home/qt/work/qt/qtbase/src/corelib/../3rdparty/tinycbor/src -I/home/qt/work/qt/qtbase_build/include/QtCore/6.7.0 -I/home/qt/work/qt/qtbase_build/include/QtCore/6.7.0/QtCore -I/home/qt/work/qt/qtbase/src/corelib/../3rdparty/double-conversion/double-conversion -I/home/qt/work/qt/qtbase/src/corelib/../3rdparty/double-conversion -I/home/qt/work/qt/qtbase/src/corelib/../3rdparty/forkfd -I/home/qt/work/qt/qtbase_build/src/corelib/.rcc -I/home/qt/work/qt/qtbase/mkspecs/linux-g++ -I/home/qt/work/qt/qtbase/src/3rdparty/pcre2/src -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -g -DNDEBUG -O3 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -Wsuggest-override -fcf-protection=full -std=c++17 -Winvalid-pch -x c++-header -include /home/qt/work/qt/qtbase_build/src/corelib/CMakeFiles/Core.dir/cmake_pch.hxx -MD -MT src/corelib/CMakeFiles/Core.dir/cmake_pch.hxx.gch -MF src/corelib/CMakeFiles/Core.dir/cmake_pch.hxx.gch.d -o src/corelib/CMakeFiles/Core.dir/cmake_pch.hxx.gch -c /home/qt/work/qt/qtbase_build/src/corelib/CMakeFiles/Core.dir/cmake_pch.hxx.cxx
qpointer.cpp.o
[496/2442] sccache /usr/bin/g++ -DBACKTRACE_HEADER=\"execinfo.h\" -DCore_EXPORTS -DELF_INTERPRETER=\"/lib64/ld-linux-x86-64.so.2\" -DPCRE2_CODE_UNIT_WIDTH=16 -DQT_ASCII_CAST_WARNINGS -DQT_BUILDING_QT -DQT_BUILD_CORE_LIB -DQT_DEPRECATED_WARNINGS -DQT_DISABLE_DEPRECATED_UP_TO=0x050000 -DQT_EXPLICIT_QFILE_CONSTRUCTION_FROM_PATH -DQT_LEAN_HEADERS=1 -DQT_MOC_COMPAT -DQT_NO_AS_CONST -DQT_NO_CAST_TO_ASCII -DQT_NO_CONTEXTLESS_CONNECT -DQT_NO_DEBUG -DQT_NO_FOREACH -DQT_NO_JAVA_STYLE_ITERATORS -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_NO_QEXCHANGE -DQT_NO_USING_NAMESPACE -DQT_TYPESAFE_FLAGS -DQT_USE_QSTRINGBUILDER -DQT_WARN_DEPRECATED_UP_TO=0x070000 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I/home/qt/work/qt/qtbase_build/src/corelib/Core_autogen/include -I/home/qt/work/qt/qtbase_build/include -I/home/qt/work/qt/qtbase_build/include/QtCore -I/home/qt/work/qt/qtbase/src/corelib -I/home/qt/work/qt/qtbase_build/src/corelib -I/home/qt/work/qt/qtbase_build/src/corelib/global -I/home/qt/work/qt/qtbase_build/src/corelib/kernel -I/home/qt/work/qt/qtbase/src/corelib/../3rdparty/tinycbor/src -I/home/qt/work/qt/qtbase_build/include/QtCore/6.7.0 -I/home/qt/work/qt/qtbase_build/include/QtCore/6.7.0/QtCore -I/home/qt/work/qt/qtbase/src/corelib/../3rdparty/double-conversion/double-conversion -I/home/qt/work/qt/qtbase/src/corelib/../3rdparty/double-conversion -I/home/qt/work/qt/qtbase/src/corelib/../3rdparty/forkfd -I/home/qt/work/qt/qtbase_build/src/corelib/.rcc -I/home/qt/work/qt/qtbase/mkspecs/linux-g++ -I/home/qt/work/qt/qtbase/src/3rdparty/pcre2/src -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -g -DNDEBUG -O3 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -Wsuggest-override -fcf-protection=full -std=c++17 -Winvalid-pch -include /home/qt/work/qt/qtbase_build/src/corelib/CMakeFiles/Core.dir/cmake_pch.hxx -MD -MT src/corelib/CMakeFiles/Core.dir/kernel/qpointer.cpp.o -MF src/corelib/CMakeFiles/Core.dir/kernel/qpointer.cpp.o.d -o src/corelib/CMakeFiles/Core.dir/kernel/qpointer.cpp.o -c /home/qt/work/qt/qtbase/src/corelib/kernel/qpointer.cpp
Trace logs on the (local) server
cmake_pch.hxx.gch
qpointer.cpp.o
NOTE: The hash key for both is
586fe72d0dc68bf36a7995cb57fa05356f76548d750f215589f97c25dc733883
!!!My understanding is that both commands compile the same pre-processed source code, but the output format differs.