Skip to content

Commit d6fc10c

Browse files
theuniluke-jr
authored andcommitted
build: Use fPIC rather than fPIE for qt objects.
But only if qt was built with reduced relocations. Github-Pull: #6978 Rebased-From: 69d0513
1 parent f016923 commit d6fc10c

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

build-aux/m4/bitcoin_qt.m4

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,43 @@ AC_DEFUN([BITCOIN_QT_CONFIGURE],[
178178
fi
179179
fi
180180
181+
if test x$use_hardening != xno; then
182+
BITCOIN_QT_CHECK([
183+
AC_MSG_CHECKING(whether -fPIE can be used with this Qt config)
184+
TEMP_CPPFLAGS=$CPPFLAGS
185+
TEMP_CXXFLAGS=$CXXFLAGS
186+
CPPFLAGS="$QT_INCLUDES $CPPFLAGS"
187+
CXXFLAGS="$PIE_FLAGS $CXXFLAGS"
188+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <QtCore/qconfig.h>]],
189+
[[
190+
#if defined(QT_REDUCE_RELOCATIONS)
191+
choke;
192+
#endif
193+
]])],
194+
[ AC_MSG_RESULT(yes); QT_PIE_FLAGS=$PIE_FLAGS ],
195+
[ AC_MSG_RESULT(no); QT_PIE_FLAGS=$PIC_FLAGS]
196+
)
197+
CPPFLAGS=$TEMP_CPPFLAGS
198+
CXXFLAGS=$TEMP_CXXFLAGS
199+
])
200+
else
201+
BITCOIN_QT_CHECK([
202+
AC_MSG_CHECKING(whether -fPIC is needed with this Qt config)
203+
TEMP_CPPFLAGS=$CPPFLAGS
204+
CPPFLAGS="$QT_INCLUDES $CPPFLAGS"
205+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <QtCore/qconfig.h>]],
206+
[[
207+
#if defined(QT_REDUCE_RELOCATIONS)
208+
choke;
209+
#endif
210+
]])],
211+
[ AC_MSG_RESULT(no)],
212+
[ AC_MSG_RESULT(yes); QT_PIE_FLAGS=$PIC_FLAGS]
213+
)
214+
CPPFLAGS=$TEMP_CPPFLAGS
215+
])
216+
fi
217+
181218
BITCOIN_QT_PATH_PROGS([MOC], [moc-qt${bitcoin_qt_got_major_vers} moc${bitcoin_qt_got_major_vers} moc], $qt_bin_path)
182219
BITCOIN_QT_PATH_PROGS([UIC], [uic-qt${bitcoin_qt_got_major_vers} uic${bitcoin_qt_got_major_vers} uic], $qt_bin_path)
183220
BITCOIN_QT_PATH_PROGS([RCC], [rcc-qt${bitcoin_qt_got_major_vers} rcc${bitcoin_qt_got_major_vers} rcc], $qt_bin_path)
@@ -223,6 +260,7 @@ AC_DEFUN([BITCOIN_QT_CONFIGURE],[
223260
])
224261
AC_MSG_RESULT([$bitcoin_enable_qt (Qt${bitcoin_qt_got_major_vers})])
225262
263+
AC_SUBST(QT_PIE_FLAGS)
226264
AC_SUBST(QT_INCLUDES)
227265
AC_SUBST(QT_LIBS)
228266
AC_SUBST(QT_LDFLAGS)

src/Makefile.qt.include

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ BITCOIN_QT_INCLUDES = -I$(builddir)/qt -I$(srcdir)/qt -I$(srcdir)/qt/forms \
324324

325325
qt_libbitcoinqt_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \
326326
$(QT_INCLUDES) $(QT_DBUS_INCLUDES) $(PROTOBUF_CFLAGS) $(QR_CFLAGS)
327-
qt_libbitcoinqt_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
327+
qt_libbitcoinqt_a_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS)
328328

329329
qt_libbitcoinqt_a_SOURCES = $(BITCOIN_QT_CPP) $(BITCOIN_QT_H) $(QT_FORMS_UI) \
330330
$(QT_QRC) $(QT_QRC_LOCALE) $(QT_TS) $(PROTOBUF_PROTO) $(RES_ICONS) $(RES_IMAGES) $(RES_MOVIES)
@@ -348,7 +348,7 @@ $(QT_MOC_CPP): $(PROTOBUF_H)
348348
# bitcoin-qt binary #
349349
qt_bitcoin_qt_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \
350350
$(QT_INCLUDES) $(PROTOBUF_CFLAGS) $(QR_CFLAGS)
351-
qt_bitcoin_qt_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
351+
qt_bitcoin_qt_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS)
352352

353353
qt_bitcoin_qt_SOURCES = qt/bitcoin.cpp
354354
if TARGET_DARWIN

src/Makefile.qttest.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBIT
3434
$(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \
3535
$(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1)
3636
qt_test_test_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
37-
qt_test_test_bitcoin_qt_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
37+
qt_test_test_bitcoin_qt_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS)
3838

3939
CLEAN_BITCOIN_QT_TEST = $(TEST_QT_MOC_CPP) qt/test/*.gcda qt/test/*.gcno
4040

0 commit comments

Comments
 (0)