From patchwork Fri Dec 3 05:37:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeny Vereshchagin X-Patchwork-Id: 48485 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B8B03858423 for ; Fri, 3 Dec 2021 22:58:39 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from forward106p.mail.yandex.net (forward106p.mail.yandex.net [77.88.28.109]) by sourceware.org (Postfix) with ESMTPS id DCF273858D28 for ; Fri, 3 Dec 2021 22:58:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DCF273858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=ya.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ya.ru Received: from forward103q.mail.yandex.net (forward103q.mail.yandex.net [IPv6:2a02:6b8:c0e:50:0:640:b21c:d009]) by forward106p.mail.yandex.net (Yandex) with ESMTP id C15672FC08E1 for ; Sat, 4 Dec 2021 01:58:26 +0300 (MSK) Received: from vla5-8f5c42dab783.qloud-c.yandex.net (vla5-8f5c42dab783.qloud-c.yandex.net [IPv6:2a02:6b8:c18:3512:0:640:8f5c:42da]) by forward103q.mail.yandex.net (Yandex) with ESMTP id BD15356A0002 for ; Sat, 4 Dec 2021 01:58:26 +0300 (MSK) Received: from vla1-1bc5b51c612f.qloud-c.yandex.net (vla1-1bc5b51c612f.qloud-c.yandex.net [2a02:6b8:c0d:89c:0:640:1bc5:b51c]) by vla5-8f5c42dab783.qloud-c.yandex.net (mxback/Yandex) with ESMTP id SXuiDoGeoz-wQeS9YYj; Sat, 04 Dec 2021 01:58:26 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ya.ru; s=mail; t=1638572306; bh=VSvNsd/mWAmiCpLlTHjiF8KzPkehxAT0ceszFqTYsZ8=; h=Date:Subject:To:From:Message-Id:Cc; b=mwqTMxPHJ/PLipUZoDPfIQpm1mqfwBZaIx+XJyL7x9Iaysz8mr4+i7dqi39vmzx2J 8S4f8tDQ1UYtxq0QZSZQhtYfCbULlAvflknbh6mUSn/Uk/bbNgUd0l8maMr6W2hxKe QrV27GH6qDfyzpv1/dr3vFMASoikpCY+ysBtmFBw= Authentication-Results: vla5-8f5c42dab783.qloud-c.yandex.net; dkim=pass header.i=@ya.ru Received: by vla1-1bc5b51c612f.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id rpGG9N9BUi-wOQma91F; Sat, 04 Dec 2021 01:58:25 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-Yandex-Fwd: 2 From: Evgeny Vereshchagin To: elfutils-devel@sourceware.org Subject: [PATCH] build: allow turning off --no-undefined and -z,defs Date: Fri, 3 Dec 2021 05:37:05 +0000 Message-Id: <20211203053705.969283-1-evvers@ya.ru> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00, DATE_IN_PAST_12_24, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , Cc: Evgeny Vereshchagin Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" 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. 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 https://github.com/evverx/elfutils/pull/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 --- ChangeLog | 5 +++++ configure.ac | 31 ++++++++++++++++++++++--------- debuginfod/Makefile.am | 2 +- libasm/Makefile.am | 2 +- libdw/Makefile.am | 2 +- libelf/Makefile.am | 2 +- 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index d61b21c7..33d20be5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-12-03 Evgeny Vereshchagin + + * configure.ac [--disable-no-undefined]: Allow turning off + --no-undefined and -z,defs to build elfutils with clang sanitizers. + 2021-11-10 Mark Wielaard * configure.ac (AC_INIT): Set version to 0.186. diff --git a/configure.ac b/configure.ac index ff9581d2..14cd2e6f 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/debuginfod/Makefile.am b/debuginfod/Makefile.am index 3adb2755..58bf71d3 100644 --- a/debuginfod/Makefile.am +++ b/debuginfod/Makefile.am @@ -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) diff --git a/libasm/Makefile.am b/libasm/Makefile.am index c2b54811..683c9847 100644 --- a/libasm/Makefile.am +++ b/libasm/Makefile.am @@ -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) diff --git a/libdw/Makefile.am b/libdw/Makefile.am index 4fda33bd..534e5cc7 100644 --- a/libdw/Makefile.am +++ b/libdw/Makefile.am @@ -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) diff --git a/libelf/Makefile.am b/libelf/Makefile.am index 560ed45f..034b7a0d 100644 --- a/libelf/Makefile.am +++ b/libelf/Makefile.am @@ -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)