200 lines
6.9 KiB
Diff
200 lines
6.9 KiB
Diff
From 63855e3e2414afbe232e5ea2e4bdfb03b786344a Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= <besser82@fedoraproject.org>
|
|
Date: Sat, 13 Jan 2018 13:19:47 +0100
|
|
Subject: [PATCH] autotools: Let libtool handle PIC/PIE flags
|
|
|
|
Signed-off-by: Stephan Mueller <smueller@chronox.de>
|
|
---
|
|
Makefile.am | 34 +++++++++++++++++++++++++---------
|
|
configure.ac | 5 +++--
|
|
m4/ax_check_pie.m4 | 19 +++++++++++++++++++
|
|
3 files changed, 47 insertions(+), 11 deletions(-)
|
|
create mode 100644 m4/ax_check_pie.m4
|
|
|
|
diff --git a/Makefile.am b/Makefile.am
|
|
index cc4d123..66464e1 100644
|
|
--- a/Makefile.am
|
|
+++ b/Makefile.am
|
|
@@ -5,8 +5,15 @@ lib_LTLIBRARIES = libkcapi.la
|
|
COMMON_CPPFLAGS = -Wextra -Wall -pedantic -fwrapv --param ssp-buffer-size=4 -O2 -Werror -std=gnu99
|
|
COMMON_LDFLAGS = -Wl,-z,relro,-z,now
|
|
|
|
+libtool: $(LIBTOOL_DEPS)
|
|
+ $(SHELL) ./config.status libtool
|
|
+
|
|
noinst_PROGRAMS = lib/doc/bin/docproc
|
|
|
|
+EXTRA_lib_doc_bin_docproc_DEPENDENCIES = libtool
|
|
+
|
|
+EXTRA_libkcapi_la_DEPENDENCIES = libtool
|
|
+
|
|
libkcapi_la_SOURCES = lib/cryptouser.h \
|
|
lib/internal.h \
|
|
lib/kcapi.h \
|
|
@@ -29,6 +36,7 @@ if DISABLE_LIB_MD
|
|
libkcapi_la_SOURCES +=
|
|
else
|
|
libkcapi_la_SOURCES += lib/kcapi-md.c
|
|
+
|
|
if DISABLE_LIB_KDF
|
|
libkcapi_la_SOURCES +=
|
|
else
|
|
@@ -60,7 +68,7 @@ else
|
|
libkcapi_la_SOURCES +=
|
|
endif
|
|
|
|
-libkcapi_la_CPPFLAGS = $(COMMON_CPPFLAGS) -fPIC -fvisibility=hidden
|
|
+libkcapi_la_CPPFLAGS = $(COMMON_CPPFLAGS) -fvisibility=hidden
|
|
libkcapi_la_LDFLAGS = $(COMMON_LDFLAGS) -Wl,--version-script,$(top_srcdir)/lib/version.lds -version-number `echo $(VERSION) | sed 's/\./:/g'`
|
|
|
|
SCAN_FILES = $(libkcapi_la_SOURCES)
|
|
@@ -72,28 +80,31 @@ bin_PROGRAMS =
|
|
if ENABLE_KCAPI_TEST
|
|
bin_PROGRAMS += bin/kcapi
|
|
|
|
-bin_kcapi_CPPFLAGS = $(COMMON_CPPFLAGS) -Wno-overlength-strings -pie -fPIE -g -Ilib/
|
|
+bin_kcapi_CPPFLAGS = $(COMMON_CPPFLAGS) -Wno-overlength-strings -g -Ilib/
|
|
bin_kcapi_LDFLAGS = $(COMMON_LDFLAGS)
|
|
bin_kcapi_LDADD = libkcapi.la
|
|
bin_kcapi_SOURCES = test/kcapi-main.c
|
|
+EXTRA_bin_kcapi_DEPENDENCIES = libtool
|
|
|
|
SCAN_FILES += $(bin_kcapi_SOURCES)
|
|
|
|
bin_PROGRAMS += bin/kcapi-enc-test-large
|
|
|
|
-bin_kcapi_enc_test_large_CPPFLAGS = $(COMMON_CPPFLAGS) -Wno-overlength-strings -pie -fPIE -g -Ilib/
|
|
+bin_kcapi_enc_test_large_CPPFLAGS = $(COMMON_CPPFLAGS) -Wno-overlength-strings -g -Ilib/
|
|
bin_kcapi_enc_test_large_LDFLAGS = $(COMMON_LDFLAGS)
|
|
bin_kcapi_enc_test_large_LDADD = libkcapi.la
|
|
bin_kcapi_enc_test_large_SOURCES = test/kcapi-enc-test-large.c
|
|
+EXTRA_bin_kcapi_enc_test_large_DEPENDENCIES = libtool
|
|
|
|
SCAN_FILES += $(bin_kcapi_enc_test_large_SOURCES)
|
|
|
|
bin_PROGRAMS += bin/kcapi-convenience
|
|
|
|
-bin_kcapi_convenience_CPPFLAGS = $(COMMON_CPPFLAGS) -Wno-overlength-strings -pie -fPIE -g -Ilib/
|
|
+bin_kcapi_convenience_CPPFLAGS = $(COMMON_CPPFLAGS) -Wno-overlength-strings -g -Ilib/
|
|
bin_kcapi_convenience_LDFLAGS = $(COMMON_LDFLAGS)
|
|
bin_kcapi_convenience_LDADD = libkcapi.la
|
|
bin_kcapi_convenience_SOURCES = test/kcapi-convenience.c
|
|
+EXTRA_bin_kcapi_convenience_DEPENDENCIES = libtool
|
|
|
|
SCAN_FILES += $(bin_kcapi_convenience_SOURCES)
|
|
endif
|
|
@@ -101,7 +112,7 @@ endif
|
|
if ENABLE_KCAPI_SPEED
|
|
bin_PROGRAMS += bin/kcapi-speed
|
|
|
|
-bin_kcapi_speed_CPPFLAGS = $(COMMON_CPPFLAGS) -pie -fPIE -Wno-variadic-macros -Ilib/
|
|
+bin_kcapi_speed_CPPFLAGS = $(COMMON_CPPFLAGS) -Wno-variadic-macros -Ilib/
|
|
bin_kcapi_speed_LDFLAGS = $(COMMON_LDFLAGS)
|
|
bin_kcapi_speed_LDADD = libkcapi.la
|
|
bin_kcapi_speed_SOURCES = speed-test/cryptoperf.h \
|
|
@@ -111,6 +122,7 @@ bin_kcapi_speed_SOURCES = speed-test/cryptoperf.h \
|
|
speed-test/cryptoperf-main.c \
|
|
speed-test/cryptoperf-rng.c \
|
|
speed-test/cryptoperf-skcipher.c
|
|
+EXTRA_bin_kcapi_speed_DEPENDENCIES = libtool
|
|
|
|
SCAN_FILES += $(bin_kcapi_speed_SOURCES)
|
|
endif
|
|
@@ -118,10 +130,11 @@ endif
|
|
if ENABLE_KCAPI_HASHER
|
|
bin_PROGRAMS += bin/kcapi-hasher
|
|
|
|
-bin_kcapi_hasher_CPPFLAGS = $(COMMON_CPPFLAGS) -fPIC -Ilib/
|
|
+bin_kcapi_hasher_CPPFLAGS = $(COMMON_CPPFLAGS) -Ilib/
|
|
bin_kcapi_hasher_LDFLAGS = $(COMMON_LDFLAGS) -ldl
|
|
bin_kcapi_hasher_LDADD = libkcapi.la
|
|
bin_kcapi_hasher_SOURCES = apps/kcapi-hasher.c apps/app-internal.c
|
|
+EXTRA_bin_kcapi_hasher_DEPENDENCIES = libtool
|
|
|
|
SCAN_FILES += $(bin_kcapi_hasher_SOURCES)
|
|
|
|
@@ -138,10 +151,11 @@ endif
|
|
if ENABLE_KCAPI_RNGAPP
|
|
bin_PROGRAMS += bin/kcapi-rng
|
|
|
|
-bin_kcapi_rng_CPPFLAGS = $(COMMON_CPPFLAGS) -pie -fPIE -Ilib/
|
|
+bin_kcapi_rng_CPPFLAGS = $(COMMON_CPPFLAGS) -Ilib/
|
|
bin_kcapi_rng_LDFLAGS = $(COMMON_LDFLAGS)
|
|
bin_kcapi_rng_LDADD = libkcapi.la
|
|
bin_kcapi_rng_SOURCES = apps/kcapi-rng.c apps/app-internal.c
|
|
+EXTRA_bin_kcapi_rng_DEPENDENCIES = libtool
|
|
|
|
SCAN_FILES += $(bin_kcapi_rng_SOURCES)
|
|
man_MANS += apps/kcapi-rng.1
|
|
@@ -150,10 +164,11 @@ endif
|
|
if ENABLE_KCAPI_ENCAPP
|
|
bin_PROGRAMS += bin/kcapi-enc
|
|
|
|
-bin_kcapi_enc_CPPFLAGS = $(COMMON_CPPFLAGS) -pie -fPIE -Ilib/
|
|
+bin_kcapi_enc_CPPFLAGS = $(COMMON_CPPFLAGS) -Ilib/
|
|
bin_kcapi_enc_LDFLAGS = $(COMMON_LDFLAGS)
|
|
bin_kcapi_enc_LDADD = libkcapi.la
|
|
bin_kcapi_enc_SOURCES = apps/kcapi-enc.c apps/app-internal.c
|
|
+EXTRA_bin_kcapi_enc_DEPENDENCIES = libtool
|
|
|
|
SCAN_FILES += $(bin_kcapi_enc_SOURCES)
|
|
man_MANS += apps/kcapi-enc.1
|
|
@@ -162,10 +177,11 @@ endif
|
|
if ENABLE_KCAPI_DGSTAPP
|
|
bin_PROGRAMS += bin/kcapi-dgst
|
|
|
|
-bin_kcapi_dgst_CPPFLAGS = $(COMMON_CPPFLAGS) -pie -fPIE -Ilib/
|
|
+bin_kcapi_dgst_CPPFLAGS = $(COMMON_CPPFLAGS) -Ilib/
|
|
bin_kcapi_dgst_LDFLAGS = $(COMMON_LDFLAGS)
|
|
bin_kcapi_dgst_LDADD = libkcapi.la
|
|
bin_kcapi_dgst_SOURCES = apps/kcapi-dgst.c apps/app-internal.c
|
|
+EXTRA_bin_kcapi_dgst_DEPENDENCIES = libtool
|
|
|
|
SCAN_FILES += $(bin_kcapi_dgst_SOURCES)
|
|
man_MANS += apps/kcapi-dgst.1
|
|
diff --git a/configure.ac b/configure.ac
|
|
index 245d059..f3a2c97 100644
|
|
--- a/configure.ac
|
|
+++ b/configure.ac
|
|
@@ -19,12 +19,13 @@ AC_DEFINE([KCAPI_MAJVERSION], [__KCAPI_MAJVERSION])
|
|
AC_DEFINE([KCAPI_MINVERSION], [__KCAPI_MINVERSION])
|
|
AC_DEFINE([KCAPI_PATCHLEVEL], [__KCAPI_PATCHLEVEL])
|
|
AM_INIT_AUTOMAKE([foreign])
|
|
-LT_INIT
|
|
+LT_INIT([pic-only])
|
|
+AC_SUBST([LIBTOOL_DEPS])
|
|
AC_PROG_CC
|
|
AC_CONFIG_FILES([Makefile])
|
|
-AM_PROG_LIBTOOL
|
|
AC_CONFIG_MACRO_DIR([m4])
|
|
AX_PROG_CC_FOR_BUILD
|
|
+AX_CHECK_PIE
|
|
|
|
AC_CHECK_PROG([CLANG], [clang], [yes])
|
|
AC_CHECK_PROG([CPPCHECK], [cppcheck], [yes])
|
|
diff --git a/m4/ax_check_pie.m4 b/m4/ax_check_pie.m4
|
|
new file mode 100644
|
|
index 0000000..a149af8
|
|
--- /dev/null
|
|
+++ b/m4/ax_check_pie.m4
|
|
@@ -0,0 +1,19 @@
|
|
+AC_DEFUN([AX_CHECK_PIE], [
|
|
+ AC_ARG_ENABLE([pie], AS_HELP_STRING([--disable-pie], [Disable Position-Independent Executable]), [], [enable_pie=yes])
|
|
+ AS_IF([test "x$enable_pie" = "xyes"], [
|
|
+ AC_MSG_CHECKING([if $CC supports PIE])
|
|
+ BAKLDFLAGS="$LDFLAGS"
|
|
+ BAKCFLAGS="$CFLAGS"
|
|
+ LDFLAGS="$LDFLAGS -pie"
|
|
+ CFLAGS="$CFLAGS -fpie -fPIE -DPIE"
|
|
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [
|
|
+ if $CC $CFLAGS $LDFLAGS -o conftest conftest.c 2>&1 | grep "warning: no debug symbols in executable" >/dev/null; then
|
|
+ LDFLAGS="$BAKLDFLAGS"
|
|
+ AC_MSG_RESULT(no)
|
|
+ else
|
|
+ AC_MSG_RESULT(yes)
|
|
+ fi
|
|
+ rm -f conftest conftest.c conftest.o
|
|
+ ], [LDFLAGS="$BAKLDFLAGS" ; CFLAGS="$BAKCFLAGS" ; AC_MSG_RESULT(no)])
|
|
+ ])
|
|
+])
|