1*4882a593SmuzhiyunFrom 9abda1bb380bdbef1affaec381742ced394ca118 Mon Sep 17 00:00:00 2001 2*4882a593SmuzhiyunFrom: Lada Trimasova <ltrimas@synopsys.com> 3*4882a593SmuzhiyunDate: Mon, 18 Jan 2016 15:58:19 +0300 4*4882a593SmuzhiyunSubject: [PATCH] Check if the compiler understands pie and relro options 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun-pie and -fpie enable the building of position-independent 7*4882a593Smuzhiyunexecutables, and -Wl,-z,relro turns on read-only relocation support in gcc. 8*4882a593SmuzhiyunAdd checks to ensure that the compiler and linker understand these options. 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunSigned-off-by: Lada Trimasova <ltrimas@synopsys.com> 11*4882a593Smuzhiyun[Bernd: Rebased for version 0.3.14] 12*4882a593SmuzhiyunSigned-off-by: Bernd Kuhls <bernd.kuhls@t-online.de> 13*4882a593Smuzhiyun--- 14*4882a593Smuzhiyun configure.ac | 5 +++ 15*4882a593Smuzhiyun m4/ax_check_compile_flag.m4 | 72 ++++++++++++++++++++++++++++++++++++ 16*4882a593Smuzhiyun m4/ax_check_link_flag.m4 | 71 +++++++++++++++++++++++++++++++++++ 17*4882a593Smuzhiyun src/tcsd/Makefile.am | 4 +- 18*4882a593Smuzhiyun 4 files changed, 150 insertions(+), 2 deletions(-) 19*4882a593Smuzhiyun create mode 100644 m4/ax_check_compile_flag.m4 20*4882a593Smuzhiyun create mode 100644 m4/ax_check_link_flag.m4 21*4882a593Smuzhiyun 22*4882a593Smuzhiyundiff --git a/configure.in b/configure.in 23*4882a593Smuzhiyunindex add23dc..9603353 100644 24*4882a593Smuzhiyun--- a/configure.ac 25*4882a593Smuzhiyun+++ b/configure.ac 26*4882a593Smuzhiyun@@ -12,6 +12,7 @@ TSS_VER_MINOR=3 27*4882a593Smuzhiyun # compute $target 28*4882a593Smuzhiyun AC_CANONICAL_TARGET 29*4882a593Smuzhiyun AM_INIT_AUTOMAKE([foreign subdir-objects 1.6]) 30*4882a593Smuzhiyun+AC_CONFIG_MACRO_DIR([m4]) 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun # Debugging support 33*4882a593Smuzhiyun AC_ARG_ENABLE([debug], 34*4882a593Smuzhiyun@@ -383,6 +384,10 @@ elif test x"${prefix}" = x"NONE"; then 35*4882a593Smuzhiyun localstatedir="/usr/local/var" 36*4882a593Smuzhiyun fi 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun+AX_CHECK_COMPILE_FLAG([-fPIE -DPIE], [PIE_CFLAGS="-fPIE -DPIE"]) 39*4882a593Smuzhiyun+AX_CHECK_LINK_FLAG([-pie], [PIE_LDFLAGS="$PIE_LDFLAGS -pie"]) 40*4882a593Smuzhiyun+AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"]) 41*4882a593Smuzhiyun+ 42*4882a593Smuzhiyun AC_OUTPUT(dist/tcsd.conf \ 43*4882a593Smuzhiyun dist/fedora/trousers.spec \ 44*4882a593Smuzhiyun dist/trousers.spec \ 45*4882a593Smuzhiyundiff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4 46*4882a593Smuzhiyunnew file mode 100644 47*4882a593Smuzhiyunindex 0000000..c3a8d69 48*4882a593Smuzhiyun--- /dev/null 49*4882a593Smuzhiyun+++ b/m4/ax_check_compile_flag.m4 50*4882a593Smuzhiyun@@ -0,0 +1,72 @@ 51*4882a593Smuzhiyun+# =========================================================================== 52*4882a593Smuzhiyun+# http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html 53*4882a593Smuzhiyun+# =========================================================================== 54*4882a593Smuzhiyun+# 55*4882a593Smuzhiyun+# SYNOPSIS 56*4882a593Smuzhiyun+# 57*4882a593Smuzhiyun+# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS]) 58*4882a593Smuzhiyun+# 59*4882a593Smuzhiyun+# DESCRIPTION 60*4882a593Smuzhiyun+# 61*4882a593Smuzhiyun+# Check whether the given FLAG works with the current language's compiler 62*4882a593Smuzhiyun+# or gives an error. (Warnings, however, are ignored) 63*4882a593Smuzhiyun+# 64*4882a593Smuzhiyun+# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 65*4882a593Smuzhiyun+# success/failure. 66*4882a593Smuzhiyun+# 67*4882a593Smuzhiyun+# If EXTRA-FLAGS is defined, it is added to the current language's default 68*4882a593Smuzhiyun+# flags (e.g. CFLAGS) when the check is done. The check is thus made with 69*4882a593Smuzhiyun+# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to 70*4882a593Smuzhiyun+# force the compiler to issue an error when a bad flag is given. 71*4882a593Smuzhiyun+# 72*4882a593Smuzhiyun+# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 73*4882a593Smuzhiyun+# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. 74*4882a593Smuzhiyun+# 75*4882a593Smuzhiyun+# LICENSE 76*4882a593Smuzhiyun+# 77*4882a593Smuzhiyun+# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de> 78*4882a593Smuzhiyun+# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com> 79*4882a593Smuzhiyun+# 80*4882a593Smuzhiyun+# This program is free software: you can redistribute it and/or modify it 81*4882a593Smuzhiyun+# under the terms of the GNU General Public License as published by the 82*4882a593Smuzhiyun+# Free Software Foundation, either version 3 of the License, or (at your 83*4882a593Smuzhiyun+# option) any later version. 84*4882a593Smuzhiyun+# 85*4882a593Smuzhiyun+# This program is distributed in the hope that it will be useful, but 86*4882a593Smuzhiyun+# WITHOUT ANY WARRANTY; without even the implied warranty of 87*4882a593Smuzhiyun+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 88*4882a593Smuzhiyun+# Public License for more details. 89*4882a593Smuzhiyun+# 90*4882a593Smuzhiyun+# You should have received a copy of the GNU General Public License along 91*4882a593Smuzhiyun+# with this program. If not, see <http://www.gnu.org/licenses/>. 92*4882a593Smuzhiyun+# 93*4882a593Smuzhiyun+# As a special exception, the respective Autoconf Macro's copyright owner 94*4882a593Smuzhiyun+# gives unlimited permission to copy, distribute and modify the configure 95*4882a593Smuzhiyun+# scripts that are the output of Autoconf when processing the Macro. You 96*4882a593Smuzhiyun+# need not follow the terms of the GNU General Public License when using 97*4882a593Smuzhiyun+# or distributing such scripts, even though portions of the text of the 98*4882a593Smuzhiyun+# Macro appear in them. The GNU General Public License (GPL) does govern 99*4882a593Smuzhiyun+# all other use of the material that constitutes the Autoconf Macro. 100*4882a593Smuzhiyun+# 101*4882a593Smuzhiyun+# This special exception to the GPL applies to versions of the Autoconf 102*4882a593Smuzhiyun+# Macro released by the Autoconf Archive. When you make and distribute a 103*4882a593Smuzhiyun+# modified version of the Autoconf Macro, you may extend this special 104*4882a593Smuzhiyun+# exception to the GPL to apply to your modified version as well. 105*4882a593Smuzhiyun+ 106*4882a593Smuzhiyun+#serial 2 107*4882a593Smuzhiyun+ 108*4882a593Smuzhiyun+AC_DEFUN([AX_CHECK_COMPILE_FLAG], 109*4882a593Smuzhiyun+[AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX 110*4882a593Smuzhiyun+AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl 111*4882a593Smuzhiyun+AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ 112*4882a593Smuzhiyun+ ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS 113*4882a593Smuzhiyun+ _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" 114*4882a593Smuzhiyun+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], 115*4882a593Smuzhiyun+ [AS_VAR_SET(CACHEVAR,[yes])], 116*4882a593Smuzhiyun+ [AS_VAR_SET(CACHEVAR,[no])]) 117*4882a593Smuzhiyun+ _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) 118*4882a593Smuzhiyun+AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes], 119*4882a593Smuzhiyun+ [m4_default([$2], :)], 120*4882a593Smuzhiyun+ [m4_default([$3], :)]) 121*4882a593Smuzhiyun+AS_VAR_POPDEF([CACHEVAR])dnl 122*4882a593Smuzhiyun+])dnl AX_CHECK_COMPILE_FLAGS 123*4882a593Smuzhiyundiff --git a/m4/ax_check_link_flag.m4 b/m4/ax_check_link_flag.m4 124*4882a593Smuzhiyunnew file mode 100644 125*4882a593Smuzhiyunindex 0000000..e2d0d36 126*4882a593Smuzhiyun--- /dev/null 127*4882a593Smuzhiyun+++ b/m4/ax_check_link_flag.m4 128*4882a593Smuzhiyun@@ -0,0 +1,71 @@ 129*4882a593Smuzhiyun+# =========================================================================== 130*4882a593Smuzhiyun+# http://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html 131*4882a593Smuzhiyun+# =========================================================================== 132*4882a593Smuzhiyun+# 133*4882a593Smuzhiyun+# SYNOPSIS 134*4882a593Smuzhiyun+# 135*4882a593Smuzhiyun+# AX_CHECK_LINK_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS]) 136*4882a593Smuzhiyun+# 137*4882a593Smuzhiyun+# DESCRIPTION 138*4882a593Smuzhiyun+# 139*4882a593Smuzhiyun+# Check whether the given FLAG works with the linker or gives an error. 140*4882a593Smuzhiyun+# (Warnings, however, are ignored) 141*4882a593Smuzhiyun+# 142*4882a593Smuzhiyun+# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 143*4882a593Smuzhiyun+# success/failure. 144*4882a593Smuzhiyun+# 145*4882a593Smuzhiyun+# If EXTRA-FLAGS is defined, it is added to the linker's default flags 146*4882a593Smuzhiyun+# when the check is done. The check is thus made with the flags: "LDFLAGS 147*4882a593Smuzhiyun+# EXTRA-FLAGS FLAG". This can for example be used to force the linker to 148*4882a593Smuzhiyun+# issue an error when a bad flag is given. 149*4882a593Smuzhiyun+# 150*4882a593Smuzhiyun+# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 151*4882a593Smuzhiyun+# macro in sync with AX_CHECK_{PREPROC,COMPILE}_FLAG. 152*4882a593Smuzhiyun+# 153*4882a593Smuzhiyun+# LICENSE 154*4882a593Smuzhiyun+# 155*4882a593Smuzhiyun+# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de> 156*4882a593Smuzhiyun+# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com> 157*4882a593Smuzhiyun+# 158*4882a593Smuzhiyun+# This program is free software: you can redistribute it and/or modify it 159*4882a593Smuzhiyun+# under the terms of the GNU General Public License as published by the 160*4882a593Smuzhiyun+# Free Software Foundation, either version 3 of the License, or (at your 161*4882a593Smuzhiyun+# option) any later version. 162*4882a593Smuzhiyun+# 163*4882a593Smuzhiyun+# This program is distributed in the hope that it will be useful, but 164*4882a593Smuzhiyun+# WITHOUT ANY WARRANTY; without even the implied warranty of 165*4882a593Smuzhiyun+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 166*4882a593Smuzhiyun+# Public License for more details. 167*4882a593Smuzhiyun+# 168*4882a593Smuzhiyun+# You should have received a copy of the GNU General Public License along 169*4882a593Smuzhiyun+# with this program. If not, see <http://www.gnu.org/licenses/>. 170*4882a593Smuzhiyun+# 171*4882a593Smuzhiyun+# As a special exception, the respective Autoconf Macro's copyright owner 172*4882a593Smuzhiyun+# gives unlimited permission to copy, distribute and modify the configure 173*4882a593Smuzhiyun+# scripts that are the output of Autoconf when processing the Macro. You 174*4882a593Smuzhiyun+# need not follow the terms of the GNU General Public License when using 175*4882a593Smuzhiyun+# or distributing such scripts, even though portions of the text of the 176*4882a593Smuzhiyun+# Macro appear in them. The GNU General Public License (GPL) does govern 177*4882a593Smuzhiyun+# all other use of the material that constitutes the Autoconf Macro. 178*4882a593Smuzhiyun+# 179*4882a593Smuzhiyun+# This special exception to the GPL applies to versions of the Autoconf 180*4882a593Smuzhiyun+# Macro released by the Autoconf Archive. When you make and distribute a 181*4882a593Smuzhiyun+# modified version of the Autoconf Macro, you may extend this special 182*4882a593Smuzhiyun+# exception to the GPL to apply to your modified version as well. 183*4882a593Smuzhiyun+ 184*4882a593Smuzhiyun+#serial 2 185*4882a593Smuzhiyun+ 186*4882a593Smuzhiyun+AC_DEFUN([AX_CHECK_LINK_FLAG], 187*4882a593Smuzhiyun+[AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_ldflags_$4_$1])dnl 188*4882a593Smuzhiyun+AC_CACHE_CHECK([whether the linker accepts $1], CACHEVAR, [ 189*4882a593Smuzhiyun+ ax_check_save_flags=$LDFLAGS 190*4882a593Smuzhiyun+ LDFLAGS="$LDFLAGS $4 $1" 191*4882a593Smuzhiyun+ AC_LINK_IFELSE([AC_LANG_PROGRAM()], 192*4882a593Smuzhiyun+ [AS_VAR_SET(CACHEVAR,[yes])], 193*4882a593Smuzhiyun+ [AS_VAR_SET(CACHEVAR,[no])]) 194*4882a593Smuzhiyun+ LDFLAGS=$ax_check_save_flags]) 195*4882a593Smuzhiyun+AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes], 196*4882a593Smuzhiyun+ [m4_default([$2], :)], 197*4882a593Smuzhiyun+ [m4_default([$3], :)]) 198*4882a593Smuzhiyun+AS_VAR_POPDEF([CACHEVAR])dnl 199*4882a593Smuzhiyun+])dnl AX_CHECK_LINK_FLAGS 200*4882a593Smuzhiyundiff --git a/src/tcsd/Makefile.am b/src/tcsd/Makefile.am 201*4882a593Smuzhiyunindex 2210734..6640ab2 100644 202*4882a593Smuzhiyun--- a/src/tcsd/Makefile.am 203*4882a593Smuzhiyun+++ b/src/tcsd/Makefile.am 204*4882a593Smuzhiyun@@ -1,8 +1,8 @@ 205*4882a593Smuzhiyun sbin_PROGRAMS=tcsd 206*4882a593Smuzhiyun 207*4882a593Smuzhiyun-tcsd_CFLAGS=-DAPPID=\"TCSD\" -DVAR_PREFIX=\"@localstatedir@\" -DETC_PREFIX=\"@sysconfdir@\" -I${top_srcdir}/src/include -fPIE -DPIE 208*4882a593Smuzhiyun+tcsd_CFLAGS=-DAPPID=\"TCSD\" -DVAR_PREFIX=\"@localstatedir@\" -DETC_PREFIX=\"@sysconfdir@\" -I${top_srcdir}/src/include $(PIE_CFLAGS) 209*4882a593Smuzhiyun tcsd_LDADD=${top_builddir}/src/tcs/libtcs.a ${top_builddir}/src/tddl/libtddl.a -lpthread @CRYPTOLIB@ 210*4882a593Smuzhiyun-tcsd_LDFLAGS=@TCSD_LDFLAGS@ 211*4882a593Smuzhiyun+tcsd_LDFLAGS=$(PIE_LDFLAGS) $(RELRO_LDFLAGS) 212*4882a593Smuzhiyun tcsd_SOURCES=svrside.c tcsd_conf.c tcsd_threads.c platform.c 213*4882a593Smuzhiyun 214*4882a593Smuzhiyun if TSS_BUILD_PS 215