Require -fPIC instead of just -fPIE for -reduce-relocations

GCC 5 combined with a recent binutils have a new optimization that
allows them to generate copy relocations even in -fPIE code. Clang has
the same functionality when compiling an executable with -flto. We need
to let the compilers know that they cannot use copy relocations, so they
need to use really position-independent code.

Position independent code throughout is not really required. We just
need the compilers to use position-independent access to symbols coming
from the Qt libraries, but there's currently no other way of doing that.

Task-number: QTBUG-45755
Change-Id: I0d4913955e3745b69672ffff13db5df7377398c5
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
Thiago Macieira 2015-05-05 08:43:42 -07:00 committed by Simon Hausmann
parent ace86dca15
commit 36d6eb721e
6 changed files with 9 additions and 9 deletions

View File

@ -42,7 +42,7 @@ QMAKE_CFLAGS_RELEASE += $$QMAKE_CFLAGS_OPTIMIZE
QMAKE_CFLAGS_DEBUG += -g QMAKE_CFLAGS_DEBUG += -g
QMAKE_CFLAGS_SHLIB += -fPIC QMAKE_CFLAGS_SHLIB += -fPIC
QMAKE_CFLAGS_STATIC_LIB += -fPIC QMAKE_CFLAGS_STATIC_LIB += -fPIC
QMAKE_CFLAGS_APP += -fPIE QMAKE_CFLAGS_APP += -fPIC
QMAKE_CFLAGS_ISYSTEM = -isystem QMAKE_CFLAGS_ISYSTEM = -isystem
QMAKE_CFLAGS_YACC += -Wno-unused -Wno-parentheses QMAKE_CFLAGS_YACC += -Wno-unused -Wno-parentheses
QMAKE_CFLAGS_HIDESYMS += -fvisibility=hidden QMAKE_CFLAGS_HIDESYMS += -fvisibility=hidden

View File

@ -23,7 +23,7 @@ QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += $$QMAKE_CFLAGS_OPTIMIZE -g
QMAKE_CFLAGS_DEBUG += -g QMAKE_CFLAGS_DEBUG += -g
QMAKE_CFLAGS_SHLIB += -fPIC -shared QMAKE_CFLAGS_SHLIB += -fPIC -shared
QMAKE_CFLAGS_STATIC_LIB += -fPIC QMAKE_CFLAGS_STATIC_LIB += -fPIC
QMAKE_CFLAGS_APP += -fPIE QMAKE_CFLAGS_APP += -fPIC
QMAKE_CFLAGS_YACC += -Wno-unused -Wno-parentheses QMAKE_CFLAGS_YACC += -Wno-unused -Wno-parentheses
QMAKE_CFLAGS_HIDESYMS += -fvisibility=hidden QMAKE_CFLAGS_HIDESYMS += -fvisibility=hidden
QMAKE_CFLAGS_SSE2 += -msse2 QMAKE_CFLAGS_SSE2 += -msse2

View File

@ -12,7 +12,7 @@ QMAKE_LEXFLAGS =
QMAKE_YACC = yacc QMAKE_YACC = yacc
QMAKE_YACCFLAGS = -d QMAKE_YACCFLAGS = -d
QMAKE_CFLAGS = QMAKE_CFLAGS =
QMAKE_CFLAGS_APP = -fPIE QMAKE_CFLAGS_APP = -fPIC
QMAKE_CFLAGS_DEPS = -M QMAKE_CFLAGS_DEPS = -M
QMAKE_CFLAGS_WARN_ON = -w1 -Wall -Wcheck -wd1572,873,2259,2261 QMAKE_CFLAGS_WARN_ON = -w1 -Wall -Wcheck -wd1572,873,2259,2261
QMAKE_CFLAGS_WARN_OFF = -w QMAKE_CFLAGS_WARN_OFF = -w

View File

@ -71,7 +71,7 @@ set(_qt5_corelib_extra_includes)
# macro to add it. # macro to add it.
set(Qt5_POSITION_INDEPENDENT_CODE True) set(Qt5_POSITION_INDEPENDENT_CODE True)
set_property(TARGET Qt5::Core PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE \"ON\") set_property(TARGET Qt5::Core PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE \"ON\")
set(Qt5Core_EXECUTABLE_COMPILE_FLAGS \"-fPIE\") set(Qt5Core_EXECUTABLE_COMPILE_FLAGS \"-fPIC\")
!!IF !isEmpty(QT_NAMESPACE) !!IF !isEmpty(QT_NAMESPACE)
list(APPEND Qt5Core_DEFINITIONS -DQT_NAMESPACE=$$QT_NAMESPACE) list(APPEND Qt5Core_DEFINITIONS -DQT_NAMESPACE=$$QT_NAMESPACE)

View File

@ -1047,9 +1047,9 @@ Q_CORE_EXPORT int qrand();
# define QT_NO_SHAREDMEMORY # define QT_NO_SHAREDMEMORY
#endif #endif
#if !defined(QT_BOOTSTRAPPED) && defined(QT_REDUCE_RELOCATIONS) && defined(__ELF__) && !defined(__PIC__) && !defined(__PIE__) #if !defined(QT_BOOTSTRAPPED) && defined(QT_REDUCE_RELOCATIONS) && defined(__ELF__) && !defined(__PIC__)
# error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\ # error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
"Compile your code with -fPIC or -fPIE." "Compile your code with -fPIC."
#endif #endif
namespace QtPrivate { namespace QtPrivate {

View File

@ -662,7 +662,7 @@ void tst_Moc::oldStyleCasts()
QStringList args; QStringList args;
args << "-c" << "-x" << "c++" << "-Wold-style-cast" << "-I" << "." args << "-c" << "-x" << "c++" << "-Wold-style-cast" << "-I" << "."
<< "-I" << qtIncludePath << "-o" << "/dev/null" << "-fPIE" << "-"; << "-I" << qtIncludePath << "-o" << "/dev/null" << "-fPIC" << "-";
proc.start("gcc", args); proc.start("gcc", args);
QVERIFY(proc.waitForStarted()); QVERIFY(proc.waitForStarted());
proc.write(mocOut); proc.write(mocOut);
@ -732,7 +732,7 @@ void tst_Moc::inputFileNameWithDotsButNoExtension()
QStringList args; QStringList args;
args << "-c" << "-x" << "c++" << "-I" << ".." args << "-c" << "-x" << "c++" << "-I" << ".."
<< "-I" << qtIncludePath << "-o" << "/dev/null" << "-fPIE" << "-"; << "-I" << qtIncludePath << "-o" << "/dev/null" << "-fPIC" << "-";
proc.start("gcc", args); proc.start("gcc", args);
QVERIFY(proc.waitForStarted()); QVERIFY(proc.waitForStarted());
proc.write(mocOut); proc.write(mocOut);
@ -1011,7 +1011,7 @@ void tst_Moc::ignoreOptionClashes()
// If -pthread wasn't ignored, it was parsed as a prefix of "thread/", which breaks compilation. // If -pthread wasn't ignored, it was parsed as a prefix of "thread/", which breaks compilation.
QStringList gccArgs; QStringList gccArgs;
gccArgs << "-c" << "-x" << "c++" << "-I" << ".." gccArgs << "-c" << "-x" << "c++" << "-I" << ".."
<< "-I" << qtIncludePath << "-I" << includeDir << "-o" << "/dev/null" << "-fPIE" << "-"; << "-I" << qtIncludePath << "-I" << includeDir << "-o" << "/dev/null" << "-fPIC" << "-";
proc.start("gcc", gccArgs); proc.start("gcc", gccArgs);
QVERIFY(proc.waitForStarted()); QVERIFY(proc.waitForStarted());
proc.write(mocOut); proc.write(mocOut);