Skip to content

Commit

Permalink
build: allow turning off --no-undefined and -z,defs
Browse files Browse the repository at this point in the history
ASan, UBSan and MSan provided by clang aren't compatible with --no-undefined and -z,defs:
https://clang.llvm.org/docs/AddressSanitizer.html#usage
google/sanitizers#380
so to build elfutils with clang with the sanitizers it should be possible
to turn them off.

Without this patch something like

sed -i 's/^\(ZDEFS_LDFLAGS=\).*/\1/' configure.ac
find -name Makefile.am | xargs sed -i 's/,--no-undefined//'

should be used to make elfutils compile.

The patch was tested in #24 by
compiling elfutils with both gcc and clang with and without ASan/UBsan
and running `make check && make distcheck`. --no-undefined and -z,defs
are still passed by default as expected.

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
  • Loading branch information
evverx committed Dec 5, 2021
1 parent b18601e commit 42c5b4b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2021-12-03 Evgeny Vereshchagin <evvers@ya.ru>

* configure.ac [--disable-no-undefined]: Allow turning off
--no-undefined and -z,defs to build elfutils with clang sanitizers.

2021-11-10 Mark Wielaard <mark@klomp.org>

* configure.ac (AC_INIT): Set version to 0.186.
Expand Down
31 changes: 22 additions & 9 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,29 @@ 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"
# ASan, UBSan and MSan provided by clang aren't compatible with --no-undefined and -z,defs:
# https://clang.llvm.org/docs/AddressSanitizer.html#usage
# https://github.com/google/sanitizers/issues/380
# so to build elfutils with clang with the sanitizers it should be possible
# to turn them off.
AC_ARG_ENABLE([no-undefined],
AS_HELP_STRING([--disable-no-undefined],[disable --no-undefined and -z,defs]),
[use_no_undefined=$enableval], [use_no_undefined=yes])
if test "$use_no_undefined" = yes; then
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

NO_UNDEFINED=",--no-undefined"
fi
AC_SUBST([NO_UNDEFINED])

# We really want build-ids. Warn and force generating them if gcc was
# configure without --enable-linker-build-id
Expand Down
2 changes: 1 addition & 1 deletion debuginfod/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ endif
$(LIBDEBUGINFOD_SONAME): $(srcdir)/libdebuginfod.map $(libdebuginfod_so_LIBS)
$(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ \
-Wl,--soname,$(LIBDEBUGINFOD_SONAME) \
-Wl,--version-script,$<,--no-undefined \
-Wl,--version-script,$<$(NO_UNDEFINED) \
-Wl,--whole-archive $(libdebuginfod_so_LIBS) -Wl,--no-whole-archive \
$(libdebuginfod_so_LDLIBS)
@$(textrel_check)
Expand Down
2 changes: 1 addition & 1 deletion libasm/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ libasm_so_LIBS = libasm_pic.a
libasm.so: $(srcdir)/libasm.map $(libasm_so_LIBS) $(libasm_so_DEPS)
$(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ \
-Wl,--soname,$@.$(VERSION) \
-Wl,--version-script,$<,--no-undefined \
-Wl,--version-script,$<$(NO_UNDEFINED) \
-Wl,--whole-archive $(libasm_so_LIBS) -Wl,--no-whole-archive \
$(libasm_so_LDLIBS)
@$(textrel_check)
Expand Down
2 changes: 1 addition & 1 deletion libdw/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ libdw_so_LDLIBS = $(libdw_so_DEPS) -ldl -lz $(argp_LDADD) $(fts_LIBS) $(obstack_
libdw.so: $(srcdir)/libdw.map $(libdw_so_LIBS) $(libdw_so_DEPS)
$(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ \
-Wl,--soname,$@.$(VERSION),--enable-new-dtags \
-Wl,--version-script,$<,--no-undefined \
-Wl,--version-script,$<$(NO_UNDEFINED) \
-Wl,--whole-archive $(libdw_so_LIBS) -Wl,--no-whole-archive \
$(libdw_so_LDLIBS)
@$(textrel_check)
Expand Down
2 changes: 1 addition & 1 deletion libelf/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ libelf_so_LIBS = libelf_pic.a
libelf.so: $(srcdir)/libelf.map $(libelf_so_LIBS) $(libelf_so_DEPS)
$(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ \
-Wl,--soname,$@.$(VERSION) \
-Wl,--version-script,$<,--no-undefined \
-Wl,--version-script,$<$(NO_UNDEFINED) \
-Wl,--whole-archive $(libelf_so_LIBS) -Wl,--no-whole-archive \
$(libelf_so_LDLIBS)
@$(textrel_check)
Expand Down

0 comments on commit 42c5b4b

Please sign in to comment.