summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <[email protected]>2017-02-24 13:11:03 +0100
committerUlf Hermann <[email protected]>2017-04-28 09:21:43 +0000
commit76acde30382254f7ca51af67ea91433719080edd (patch)
tree71564ca688cff175381ecd3e51b1c8e2507db998
parentffb6a77fc4f0533126a3ff49ec5c03ef8e674520 (diff)
Check for -z,defs, -z,relro, -fPIC, -fPIE before using them
On windows those aren't needed because the link results are no ELF files and all code is position independent anyway. gcc then complains about them, which is in turn caught by -Werror. Change-Id: Ie3d600b7c430698fc3d867a986a4d48f7ad1bbec Reviewed-by: Christian Kandeler <[email protected]>
-rw-r--r--ChangeLog5
-rw-r--r--backends/ChangeLog4
-rw-r--r--backends/Makefile.am4
-rw-r--r--config/ChangeLog4
-rw-r--r--config/eu.am4
-rw-r--r--configure.ac56
-rw-r--r--lib/ChangeLog4
-rw-r--r--lib/Makefile.am2
-rw-r--r--libasm/ChangeLog4
-rw-r--r--libasm/Makefile.am2
-rw-r--r--libcpu/ChangeLog4
-rw-r--r--libcpu/Makefile.am2
-rw-r--r--libdw/ChangeLog4
-rw-r--r--libdw/Makefile.am4
-rw-r--r--libebl/ChangeLog4
-rw-r--r--libebl/Makefile.am2
-rw-r--r--libelf/ChangeLog4
-rw-r--r--libelf/Makefile.am6
-rw-r--r--libgnu/Makefile.am2
-rw-r--r--tests/ChangeLog4
-rw-r--r--tests/Makefile.am4
21 files changed, 111 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 6fe525c6..36c3cc74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2017-04-27 Ulf Hermann <[email protected]>
+ * configure.ac: Check if -fPIC, -fPIE, -Wl,-z,defs,
+ and -Wl,-z,relro are supported by the compiler.
+
+2017-04-27 Ulf Hermann <[email protected]>
+
* configure.ac: Drop checks for memrchr, rawmemchr, mempcpy, argp.
2017-04-21 Ulf Hermann <[email protected]>
diff --git a/backends/ChangeLog b/backends/ChangeLog
index 594aa98b..baeb7b92 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,7 @@
+2017-04-27 Ulf Hermann <[email protected]>
+
+ * Makefile.am: Use dso_LDFLAGS.
+
2017-04-21 Ulf Hermann <[email protected]>
* Makefile.am: Link backends against libgnu.a if requested.
diff --git a/backends/Makefile.am b/backends/Makefile.am
index 5dcb3e10..3e1992eb 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -138,10 +138,10 @@ libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw) $(libgnu)
@rm -f $(@:.so=.map)
$(AM_V_at)echo 'ELFUTILS_$(PACKAGE_VERSION) { global: $*_init; local: *; };' \
> $(@:.so=.map)
- $(AM_V_CCLD)$(LINK) -shared -o $(@:.map=.so) \
+ $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $(@:.map=.so) \
-Wl,--whole-archive $< $(cpu_$*) -Wl,--no-whole-archive \
-Wl,--version-script,$(@:.so=.map) \
- -Wl,-z,defs -Wl,--as-needed $(libelf) $(libdw) $(libgnu)
+ -Wl,--as-needed $(libelf) $(libdw) $(libgnu)
@$(textrel_check)
libebl_i386.so: $(cpu_i386)
diff --git a/config/ChangeLog b/config/ChangeLog
index 756bab61..59569e3e 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,7 @@
+2017-04-27 Ulf Hermann <[email protected]>
+
+ * eu.am: Use fpic_CFLAGS.
+
2017-04-21 Ulf Hermann <[email protected]>
* eu.am: Add $(top_srcdir)libgnu and $(top_builddir)/libgnu to -I if requested.
diff --git a/config/eu.am b/config/eu.am
index 11c2fece..bc8c7678 100644
--- a/config/eu.am
+++ b/config/eu.am
@@ -89,14 +89,14 @@ endif
%.os: %.c %.o
if AMDEP
- $(AM_V_CC)if $(COMPILE.os) -c -o $@ -fPIC $(DEFS.os) -MT $@ -MD -MP \
+ $(AM_V_CC)if $(COMPILE.os) -c -o $@ $(fpic_CFLAGS) $(DEFS.os) -MT $@ -MD -MP \
-MF "$(DEPDIR)/$*.Tpo" `test -f '$<' || echo '$(srcdir)/'`$<; \
then cat "$(DEPDIR)/$*.Tpo" >> "$(DEPDIR)/$*.Po"; \
rm -f "$(DEPDIR)/$*.Tpo"; \
else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
fi
else
- $(AM_V_CC)$(COMPILE.os) -c -o $@ -fPIC $(DEFS.os) $<
+ $(AM_V_CC)$(COMPILE.os) -c -o $@ $(fpic_CFLAGS) $(DEFS.os) $<
endif
CLEANFILES = *.gcno *.gcda
diff --git a/configure.ac b/configure.ac
index a48b13ea..107762fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -136,13 +136,65 @@ CFLAGS="$old_CFLAGS"])
AS_IF([test "x$ac_cv_c99" != xyes],
AC_MSG_ERROR([gcc with GNU99 support required]))
+AC_CACHE_CHECK([whether gcc supports -fPIC], ac_cv_fpic, [dnl
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -fPIC -Werror"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE()], ac_cv_fpic=yes, ac_cv_fpic=no)
+CFLAGS="$save_CFLAGS"
+])
+if test "$ac_cv_fpic" = "yes"; then
+ fpic_CFLAGS="-fPIC"
+else
+ fpic_CFLAGS=""
+fi
+AC_SUBST([fpic_CFLAGS])
+
+AC_CACHE_CHECK([whether gcc supports -fPIE], ac_cv_fpie, [dnl
+save_CFLAGS="$CFLAGS"
+CFLAGS="$save_CFLAGS -fPIE -Werror"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE()], ac_cv_fpie=yes, ac_cv_fpie=no)
+CFLAGS="$save_CFLAGS"
+])
+if test "$ac_cv_fpie" = "yes"; then
+ fpie_CFLAGS="-fPIE"
+else
+ fpie_CFLAGS=""
+fi
+AC_SUBST([fpie_CFLAGS])
+
+dso_LDFLAGS="-shared"
+
+ZDEFS_LDFLAGS="-Wl,-z,defs"
+AC_CACHE_CHECK([whether gcc supports $ZDEFS_LDFLAGS], ac_cv_zdefs, [dnl
+save_LDFLAGS="$LDFLAGS"
+LDFLAGS="$ZDEFS_LDFLAGS $save_LDFLAGS"
+AC_LINK_IFELSE([AC_LANG_PROGRAM()], ac_cv_zdefs=yes, ac_cv_zdefs=no)
+LDFLAGS="$save_LDFLAGS"
+])
+if test "$ac_cv_zdefs" = "yes"; then
+ dso_LDFLAGS="$dso_LDFLAGS $ZDEFS_LDFLAGS"
+fi
+
+ZRELRO_LDFLAGS="-Wl,-z,relro"
+AC_CACHE_CHECK([whether gcc supports $ZRELRO_LDFLAGS], ac_cv_zrelro, [dnl
+save_LDFLAGS="$LDFLAGS"
+LDFLAGS="$ZRELRO_LDFLAGS $save_LDFLAGS"
+AC_LINK_IFELSE([AC_LANG_PROGRAM()], ac_cv_zrelro=yes, ac_cv_zrelro=no)
+LDFLAGS="$save_LDFLAGS"
+])
+if test "$ac_cv_zrelro" = "yes"; then
+ dso_LDFLAGS="$dso_LDFLAGS $ZRELRO_LDFLAGS"
+fi
+
+AC_SUBST([dso_LDFLAGS])
+
AC_CACHE_CHECK([for __thread support], ac_cv_tls, [dnl
# Use the same flags that we use for our DSOs, so the test is representative.
# Some old compiler/linker/libc combinations fail some ways and not others.
save_CFLAGS="$CFLAGS"
save_LDFLAGS="$LDFLAGS"
-CFLAGS="-fPIC $CFLAGS"
-LDFLAGS="-shared -Wl,-z,defs,-z,relro $LDFLAGS"
+CFLAGS="$fpic_CFLAGS $CFLAGS"
+LDFLAGS="$dso_LDFLAGS $LDFLAGS"
AC_LINK_IFELSE([dnl
AC_LANG_PROGRAM([[#include <stdlib.h>
#undef __thread
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 82c009e4..605b9b9d 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,5 +1,9 @@
2017-04-27 Ulf Hermann <[email protected]>
+ * Makefile.am: Use fpic_CFLAGS.
+
+2017-04-27 Ulf Hermann <[email protected]>
+
* system.h: Drop mempcpy replacement.
* xstrndup.c: Don't include system.h.
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 7a65eb91..17d16d07 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -28,7 +28,7 @@
## not, see <http://www.gnu.org/licenses/>.
##
include $(top_srcdir)/config/eu.am
-AM_CFLAGS += -fPIC
+AM_CFLAGS += $(fpic_CFLAGS)
AM_CPPFLAGS += -I$(srcdir)/../libelf
noinst_LIBRARIES = libeu.a
diff --git a/libasm/ChangeLog b/libasm/ChangeLog
index 80aa7de9..971492a8 100644
--- a/libasm/ChangeLog
+++ b/libasm/ChangeLog
@@ -1,5 +1,9 @@
2017-02-27 Ulf Hermann <[email protected]>
+ * Makefile.am: Use dso_LDFLAGS.
+
+2017-02-27 Ulf Hermann <[email protected]>
+
* disasm_str.c: Don't include system.h
2017-02-21 Ulf Hermann <[email protected]>
diff --git a/libasm/Makefile.am b/libasm/Makefile.am
index 8713070c..a5fc9fc1 100644
--- a/libasm/Makefile.am
+++ b/libasm/Makefile.am
@@ -65,7 +65,7 @@ endif
libasm_so_SOURCES =
libasm.so$(EXEEXT): libasm_pic.a libasm.map
- $(AM_V_CCLD)$(LINK) -shared -o $@ -Wl,--whole-archive,$<,--no-whole-archive \
+ $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ -Wl,--whole-archive,$<,--no-whole-archive \
-Wl,--version-script,$(srcdir)/libasm.map,--no-undefined \
-Wl,--soname,$@.$(VERSION) \
../libebl/libebl.a ../libelf/libelf.so ../libdw/libdw.so \
diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog
index 9235b1b1..ef5da58f 100644
--- a/libcpu/ChangeLog
+++ b/libcpu/ChangeLog
@@ -1,3 +1,7 @@
+2017-02-27 Ulf Hermann <[email protected]>
+
+ * Makefile.am: Use fpic_CFLAGS.
+
2017-02-21 Ulf Hermann <[email protected]>
* Makefile.am: Link gendis agaist libgnu.a if requested.
diff --git a/libcpu/Makefile.am b/libcpu/Makefile.am
index 30a67997..9ca0f434 100644
--- a/libcpu/Makefile.am
+++ b/libcpu/Makefile.am
@@ -30,7 +30,7 @@
include $(top_srcdir)/config/eu.am
AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libebl \
-I$(srcdir)/../libdw -I$(srcdir)/../libasm
-AM_CFLAGS += -fPIC -fdollars-in-identifiers
+AM_CFLAGS += $(fpic_CFLAGS) -fdollars-in-identifiers
LEXCOMPILE = $(LEX) $(LFLAGS) $(AM_LFLAGS) -P$(<F:lex.l=)
LEX_OUTPUT_ROOT = lex.$(<F:lex.l=)
AM_YFLAGS = -p$(<F:parse.y=)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 6e11181e..d15c861b 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,9 @@
2017-02-27 Ulf Hermann <[email protected]>
+ * Makefile.am: Use fpic_CFLAGS and dso_LDFLAGS.
+
+2017-02-27 Ulf Hermann <[email protected]>
+
* Makefile.am: Remove argp_LDADD.
2017-02-21 Ulf Hermann <[email protected]>
diff --git a/libdw/Makefile.am b/libdw/Makefile.am
index 88430627..7b69f6a6 100644
--- a/libdw/Makefile.am
+++ b/libdw/Makefile.am
@@ -29,7 +29,7 @@
##
include $(top_srcdir)/config/eu.am
if BUILD_STATIC
-AM_CFLAGS += -fPIC
+AM_CFLAGS += $(fpic_CFLAGS)
endif
AM_CPPFLAGS += -I$(srcdir)/../libelf
VERSION = 1
@@ -114,7 +114,7 @@ libdw.so$(EXEEXT): $(srcdir)/libdw.map libdw_pic.a ../libdwelf/libdwelf_pic.a \
../libelf/libelf.so
# The rpath is necessary for libebl because its $ORIGIN use will
# not fly in a setuid executable that links in libdw.
- $(AM_V_CCLD)$(LINK) -shared -o $@ -Wl,--soname,$@.$(VERSION),-z,defs \
+ $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ -Wl,--soname,$@.$(VERSION) \
-Wl,--enable-new-dtags,-rpath,$(pkglibdir) \
-Wl,--version-script,$<,--no-undefined \
-Wl,--whole-archive $(filter-out $<,$^) -Wl,--no-whole-archive\
diff --git a/libebl/ChangeLog b/libebl/ChangeLog
index 0605083e..56b0421b 100644
--- a/libebl/ChangeLog
+++ b/libebl/ChangeLog
@@ -1,5 +1,9 @@
2017-04-27 Ulf Hermann <[email protected]>
+ * Makefile.am: Use fpic_CFLAGS.
+
+2017-04-27 Ulf Hermann <[email protected]>
+
* eblmachineflagname.c: Don't include system.h.
* eblopenbackend.c: Likewise.
diff --git a/libebl/Makefile.am b/libebl/Makefile.am
index 6f945eb8..60d0e734 100644
--- a/libebl/Makefile.am
+++ b/libebl/Makefile.am
@@ -28,7 +28,7 @@
## not, see <http://www.gnu.org/licenses/>.
##
include $(top_srcdir)/config/eu.am
-AM_CFLAGS += -fPIC
+AM_CFLAGS += $(fpic_CFLAGS)
AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libdw -I$(srcdir)/../libasm
VERSION = 1
LIBEBL_SUBDIR = @LIBEBL_SUBDIR@
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 9165634a..1c6cce29 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,5 +1,9 @@
2017-04-27 Ulf Hermann <[email protected]>
+ * Makefile.am: Use fpic_CFLAGS and dso_LDFLAGS.
+
+2017-04-27 Ulf Hermann <[email protected]>
+
* elf_getarsym.c: Don't replace rawmemchr.
* elf_strptr.c: Don't replace memrchr.
diff --git a/libelf/Makefile.am b/libelf/Makefile.am
index d141c641..78d68532 100644
--- a/libelf/Makefile.am
+++ b/libelf/Makefile.am
@@ -29,7 +29,7 @@
##
include $(top_srcdir)/config/eu.am
if BUILD_STATIC
-AM_CFLAGS += -fPIC
+AM_CFLAGS += $(fpic_CFLAGS)
endif
GCC_INCLUDE = -I$(shell $(CC) -print-file-name=include)
VERSION = 1
@@ -105,9 +105,9 @@ endif
libelf_so_SOURCES =
libelf.so$(EXEEXT): libelf_pic.a libelf.map
- $(AM_V_CCLD)$(LINK) -shared -o $@ -Wl,--whole-archive,$<,--no-whole-archive \
+ $(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ -Wl,--whole-archive,$<,--no-whole-archive \
-Wl,--version-script,$(srcdir)/libelf.map,--no-undefined \
- -Wl,--soname,$@.$(VERSION),-z,defs,-z,relro $(libelf_so_LDLIBS)
+ -Wl,--soname,$@.$(VERSION) $(libelf_so_LDLIBS)
@$(textrel_check)
$(AM_V_at)ln -fs $@ $@.$(VERSION)
diff --git a/libgnu/Makefile.am b/libgnu/Makefile.am
index c4a90e80..0d31e693 100644
--- a/libgnu/Makefile.am
+++ b/libgnu/Makefile.am
@@ -30,7 +30,7 @@
# for eu-config.h
AM_CPPFLAGS = -I$(top_srcdir)/lib
-AM_CFLAGS = -fPIC
+AM_CFLAGS = $(fpic_CFLAGS)
noinst_LIBRARIES =
MOSTLYCLEANFILES =
MOSTLYCLEANDIRS =
diff --git a/tests/ChangeLog b/tests/ChangeLog
index d2a14c2d..9d203419 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,9 @@
2017-04-27 Ulf Hermann <[email protected]>
+ * Makefile.am: Use fpie_CFLAGS and fpic_CFLAGS.
+
+2017-04-27 Ulf Hermann <[email protected]>
+
* Makefile.am: Drop argp_LDADD.
* elfstrmerge.c: Don't include system.h.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 69d1fcd3..7258069e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -468,7 +468,7 @@ dwfl_report_elf_align_LDADD = $(libdw) $(libgnu)
varlocs_LDADD = $(libdw) $(libelf) $(libgnu)
backtrace_LDADD = $(libdw) $(libelf) $(libgnu)
# backtrace-child-biarch also uses those *_CFLAGS and *_LDLAGS variables:
-backtrace_child_CFLAGS = -fPIE
+backtrace_child_CFLAGS = $(fpie_CFLAGS)
backtrace_child_LDFLAGS = -pie -pthread
backtrace_child_biarch_SOURCES = backtrace-child.c
backtrace_data_LDADD = $(libdw) $(libelf) $(libgnu)
@@ -479,7 +479,7 @@ debugaltlink_LDADD = $(libdw) $(libelf) $(libgnu)
buildid_LDADD = $(libdw) $(libelf) $(libgnu)
deleted_LDADD = ./deleted-lib.so $(libgnu)
deleted_lib_so_LDFLAGS = -shared -rdynamic
-deleted_lib_so_CFLAGS = -fPIC -fasynchronous-unwind-tables
+deleted_lib_so_CFLAGS = $(fpic_CFLAGS) -fasynchronous-unwind-tables
deleted_lib_so_LDADD = $(libgnu)
aggregate_size_LDADD = $(libdw) $(libelf) $(libgnu)
peel_type_LDADD = $(libdw) $(libelf) $(libgnu)