Bug 1806545 - Precompiled header don't work at all with gcc-8.3.1 (C++)
Summary: Precompiled header don't work at all with gcc-8.3.1 (C++)
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: gcc
Version: 8.3
Hardware: x86_64
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: 8.0
Assignee: Marek Polacek
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-02-24 13:55 UTC by Christian Hägele
Modified: 2021-09-17 14:35 UTC (History)
8 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-03-13 15:55:53 UTC
Type: Bug
Target Upstream Version:


Attachments (Terms of Use)

Description Christian Hägele 2020-02-24 13:55:08 UTC
Description of problem:
Precompiled-Headers don't work with the system-compiler. Same code compiles on all other platforms I tried. Even with the same Compiler-Version.

Version-Release number of selected component (if applicable):
gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4)

How reproducible:
Any C++-Program which tries to use precompiled-headers and uses -Winvalid-pch.
I added a minimal example to reproduce.

Steps to Reproduce:
1. echo "#include <iostream>" > test.txt
2. echo "#include "stdafx.h"

int main() {
std::cout << "Hello World" << std::endl;
return 0; }
" > test.txt
3. mkdir stdafx.h.gch
4. /usr/bin/c++ -Wall -Wextra -Werror -x c++-header -o stdafx.h.gch/.c++ stdafx.h
5. /usr/bin/c++ -Wall -Wextra -Werror -Winvalid-pch -o main.o -c main.cpp

Actual results:
main.cpp:1:20: error: stdafx.h.gch/.c++: had text segment at different address [-Werror]
 #include "stdafx.h"
                    ^

Expected results:
Compile succeeds without Warnings and Error and is using Precompiled-Headers

Additional info:
I tested the same code also with DevToolset-8 (GCC-8.3.1)on RHEL7 and also with GCC-8.2.1 on openSUSE Leap 15.1 and it works without problems.

Comment 1 Christian Hägele 2020-02-24 14:03:52 UTC
I did a stupid copy&paste mistake on the steps to reproduce. Sorry for that.
Here are the correct steps:

1. echo "#include <iostream>" > stdafx.h
2. echo "#include "stdafx.h"

int main() {
std::cout << "Hello World" << std::endl;
return 0; }
" > main.cpp
3. mkdir stdafx.h.gch
4. /usr/bin/c++ -Wall -Wextra -Werror -x c++-header -o stdafx.h.gch/.c++ stdafx.h
5. /usr/bin/c++ -Wall -Wextra -Werror -Winvalid-pch -o main.o -c main.cpp

Comment 2 Marek Polacek 2020-02-24 14:58:25 UTC
Looks very much like a duplicate of Bug 1721553.

Comment 3 Mario Trangoni 2020-02-24 16:20:33 UTC
JFTR, the same code compiles on GCC-9 from GCC Toolset.

$ sudo dnf install gcc-toolset-9-gcc-c++
$ scl enable gcc-toolset-9 bash
$ c++ -Wall -Wextra -Werror -x c++-header -o stdafx.h.gch/.c++ stdafx.h
$ c++ -Wall -Wextra -Werror -Winvalid-pch -o main.o -c main.cpp
$ c++ --version
c++ (GCC) 9.1.1 20190605 (Red Hat 9.1.1-2)
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Comment 4 Marek Polacek 2020-02-24 16:24:54 UTC
Yes, that would make sense because I think we don't turn on hardening the compiler and its binaries in DTS 9.

Comment 5 Christian Hägele 2020-03-03 13:22:09 UTC
Is there any update on this issue? Did I do something wrong or is the current behavior expected?

Comment 6 Jeff Law 2020-03-13 15:55:53 UTC
This is expected behavior.  GCC's PCH mechanism is fundamentally incompatible with the security hardening requirements for RHEL (PIE in particular).  We are currently evaluating the best way to present a more friendly diagnostic for this issue.


Note You need to log in before you can comment on or make changes to this bug.