From patchwork Fri Dec 16 10:27:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 33938 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp884645wrn; Fri, 16 Dec 2022 02:28:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf7iSZhbk3VUaSc5sOzAp/5qG95bifOhWlH0iapJ0yTzEKFpc6PyWiT7g9X9WGftMtSAPWqm X-Received: by 2002:a50:ff18:0:b0:46f:e856:87ac with SMTP id a24-20020a50ff18000000b0046fe85687acmr16014805edu.3.1671186519778; Fri, 16 Dec 2022 02:28:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671186519; cv=none; d=google.com; s=arc-20160816; b=RUager4fAR4j22YowCRMoJHeCyHbK9SO3jtHrCZy9EhlmJNwy0uWtD2nniWFbrx9ZI VOVEKTraEHkD0843dSX6yep1Ni0fzpP03Z3O1SLzhKrmG8gefVfWJAXO5oM+fGSlaSWr Vu4WUT/qf59FmApktd9ulhrBu0tV3AzA78BSrO1VBPBpsOLG5tQKwsjd/PgDplKBucbE Ege/6dyenE4E/2a91upESpw1aizW9fZi3aqb2LLGF81X0HAtne8Do6O8ncWsIAYGmkmM a71W+7vHAGLNaUiG/qduwuhJDfN19lRpsN1OXEf4wMFRt/21HpN2U78KFfVxNu9nIEbv dr2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=hsELqH85LwJ5N7lKRKjTf1SxRubXPJ6NZtBBI8KdeOU=; b=KNWY0doe7EjJsTwtQ1havhf9lQMBkq8rGEUcs2dKIzbbqSRy+FCTn6pal6FWV2eSMl RiaOeDVazUIdHdrsrD6eeHd6d0ihZr3lIoRSupYEQgsXMgxJpyvb8Idcl634VH2i/q2K Vn7nFEcuZOkK5iABw6YjotYOopQSVsXRyhMC20AU5qvpQYlKtjNP6hZn6P3AW4w2fb9C /QS2SKTaxopXOqhEHrh3H5PGqUTCD9Wi1v/w57uj2iuoAxPSiS1RMaocqLiVDLt5f4to y7I7g3NDUQWVWCZP2TBmIIjnZtctu+qHg6Fg4b8wUGvpRLYEr5q2mAqpDXPifgyPQogC mFSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vImx6xw4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c13-20020a50d64d000000b0046d57bba913si1959709edj.520.2022.12.16.02.28.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 02:28:39 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vImx6xw4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3FC2E382EF04 for ; Fri, 16 Dec 2022 10:28:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3FC2E382EF04 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671186518; bh=hsELqH85LwJ5N7lKRKjTf1SxRubXPJ6NZtBBI8KdeOU=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=vImx6xw4tfbBk4IF5CXtwaM4toQCgtBEk88Ikummzilyb/pd0EYtGR5olyvvEEqEW I9HAgs37zn9XR3GYzSJr5sD/Pdxtphkp4RWnUXeBbjExK9VxeNd2la9CP5f4FROR9m ElQlzTN/dswyQZF+LNNgUktr7POpyzYK5zLO7vVc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 5DB023881D14 for ; Fri, 16 Dec 2022 10:27:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5DB023881D14 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-610-c_YDXlpqNmWH_hsJzAVEoA-1; Fri, 16 Dec 2022 05:27:48 -0500 X-MC-Unique: c_YDXlpqNmWH_hsJzAVEoA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4091E181E3F0; Fri, 16 Dec 2022 10:27:48 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EC9F1400F5A; Fri, 16 Dec 2022 10:27:47 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2BGARil22833492 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 16 Dec 2022 11:27:44 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BGARgZJ2833491; Fri, 16 Dec 2022 11:27:42 +0100 Date: Fri, 16 Dec 2022 11:27:42 +0100 To: Richard Biener , Martin =?utf-8?b?TGnFoWth?= , hjl.tools@gmail.com, Richard Sandiford Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] hwasan: Add libhwasan_preinit.o Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752366076277297978?= X-GMAIL-MSGID: =?utf-8?q?1752366076277297978?= Hi! I've noticed an inconsistency with the other sanitizers. For -fsanitize={address,thread,leak} we link into binaries lib*san_preinit.o such that the -lasan, -ltsan or -llsan libraries are initialized as early as possible through .preinit_array. The hwasan library has the same thing, but we strangely compiled it into the library (where it apparently didn't do anything, .preinit_array doesn't seem to be created for shared libraries), rather than installing it like in the other 3 cases. The following patch handles it for hwasan similarly to asan, tsan and lsan. I don't have any hw with hwasan support, so I've just checked it builds and installs as expected and that gcc -fsanitize=hwaddress -o a a.c -mlam=u57 on trivial main results in .preinit_array section in the binary. Ok for trunk? 2022-12-16 Jakub Jelinek * config/gnu-user.h (LIBHWASAN_EARLY_SPEC): Add libhwasan_preinit.o to link spec if not -shared. * hwasan/Makefile.am (nodist_toolexeclib_HEADERS): Set to libhwasan_preinit.o. (hwasan_files): Remove hwasan_preinit.cpp. (libhwasan_preinit.o): Copy from hwasan_preinit.o. * hwasan/Makefile.in: Regenerated. Jakub --- gcc/config/gnu-user.h.jj 2022-01-11 23:11:21.753299105 +0100 +++ gcc/config/gnu-user.h 2022-12-16 10:41:16.289726621 +0100 @@ -138,7 +138,8 @@ see the files COPYING3 and COPYING.RUNTI LD_STATIC_OPTION " --whole-archive -lasan --no-whole-archive " \ LD_DYNAMIC_OPTION "}}%{!static-libasan:-lasan}" #undef LIBHWASAN_EARLY_SPEC -#define LIBHWASAN_EARLY_SPEC "%{static-libhwasan:%{!shared:" \ +#define LIBHWASAN_EARLY_SPEC "%{!shared:libhwasan_preinit%O%s} " \ + "%{static-libhwasan:%{!shared:" \ LD_STATIC_OPTION " --whole-archive -lhwasan --no-whole-archive " \ LD_DYNAMIC_OPTION "}}%{!static-libhwasan:-lhwasan}" #undef LIBTSAN_EARLY_SPEC --- libsanitizer/hwasan/Makefile.am.jj 2022-05-09 09:09:21.003463752 +0200 +++ libsanitizer/hwasan/Makefile.am 2022-12-16 10:32:25.999508099 +0100 @@ -12,6 +12,7 @@ AM_CCASFLAGS = $(EXTRA_ASFLAGS) ACLOCAL_AMFLAGS = -I $(top_srcdir) -I $(top_srcdir)/config toolexeclib_LTLIBRARIES = libhwasan.la +nodist_toolexeclib_HEADERS = libhwasan_preinit.o hwasan_files = \ hwasan_allocation_functions.cpp \ @@ -28,7 +29,6 @@ hwasan_files = \ hwasan_memintrinsics.cpp \ hwasan_new_delete.cpp \ hwasan_poisoning.cpp \ - hwasan_preinit.cpp \ hwasan_report.cpp \ hwasan_setjmp_aarch64.S \ hwasan_setjmp_x86_64.S \ @@ -49,6 +49,9 @@ libhwasan_la_LIBADD += $(LIBSTDCXX_RAW_C libhwasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libhwasan) +libhwasan_preinit.o: hwasan_preinit.o + cp $< $@ + # Work around what appears to be a GNU make bug handling MAKEFLAGS # values defined in terms of make variables, as is the case for CC and # friends when we are called from the top level Makefile. --- libsanitizer/hwasan/Makefile.in.jj 2022-05-09 09:09:21.003463752 +0200 +++ libsanitizer/hwasan/Makefile.in 2022-12-16 10:33:20.681705095 +0100 @@ -14,6 +14,7 @@ @SET_MAKE@ + VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ @@ -141,7 +142,8 @@ am__uninstall_files_from_dir = { \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && rm -f $$files; }; \ } -am__installdirs = "$(DESTDIR)$(toolexeclibdir)" +am__installdirs = "$(DESTDIR)$(toolexeclibdir)" \ + "$(DESTDIR)$(toolexeclibdir)" LTLIBRARIES = $(toolexeclib_LTLIBRARIES) am__DEPENDENCIES_1 = libhwasan_la_DEPENDENCIES = \ @@ -152,10 +154,9 @@ am__objects_1 = hwasan_allocation_functi hwasan_fuchsia.lo hwasan_globals.lo hwasan_interceptors.lo \ hwasan_interceptors_vfork.lo hwasan_linux.lo \ hwasan_memintrinsics.lo hwasan_new_delete.lo \ - hwasan_poisoning.lo hwasan_preinit.lo hwasan_report.lo \ - hwasan_setjmp_aarch64.lo hwasan_setjmp_x86_64.lo \ - hwasan_tag_mismatch_aarch64.lo hwasan_thread.lo \ - hwasan_thread_list.lo hwasan_type_test.lo + hwasan_poisoning.lo hwasan_report.lo hwasan_setjmp_aarch64.lo \ + hwasan_setjmp_x86_64.lo hwasan_tag_mismatch_aarch64.lo \ + hwasan_thread.lo hwasan_thread_list.lo hwasan_type_test.lo am_libhwasan_la_OBJECTS = $(am__objects_1) libhwasan_la_OBJECTS = $(am_libhwasan_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) @@ -233,6 +234,7 @@ am__can_run_installinfo = \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac +HEADERS = $(nodist_toolexeclib_HEADERS) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is @@ -415,6 +417,7 @@ AM_CXXFLAGS = -Wall -W -Wno-unused-param AM_CCASFLAGS = $(EXTRA_ASFLAGS) ACLOCAL_AMFLAGS = -I $(top_srcdir) -I $(top_srcdir)/config toolexeclib_LTLIBRARIES = libhwasan.la +nodist_toolexeclib_HEADERS = libhwasan_preinit.o hwasan_files = \ hwasan_allocation_functions.cpp \ hwasan_allocator.cpp \ @@ -430,7 +433,6 @@ hwasan_files = \ hwasan_memintrinsics.cpp \ hwasan_new_delete.cpp \ hwasan_poisoning.cpp \ - hwasan_preinit.cpp \ hwasan_report.cpp \ hwasan_setjmp_aarch64.S \ hwasan_setjmp_x86_64.S \ @@ -575,7 +577,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_memintrinsics.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_new_delete.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_poisoning.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_preinit.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_report.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_setjmp_aarch64.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwasan_setjmp_x86_64.Plo@am__quote@ @@ -631,6 +632,27 @@ mostlyclean-libtool: clean-libtool: -rm -rf .libs _libs +install-nodist_toolexeclibHEADERS: $(nodist_toolexeclib_HEADERS) + @$(NORMAL_INSTALL) + @list='$(nodist_toolexeclib_HEADERS)'; test -n "$(toolexeclibdir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(toolexeclibdir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(toolexeclibdir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(toolexeclibdir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(toolexeclibdir)" || exit $$?; \ + done + +uninstall-nodist_toolexeclibHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(nodist_toolexeclib_HEADERS)'; test -n "$(toolexeclibdir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + dir='$(DESTDIR)$(toolexeclibdir)'; $(am__uninstall_files_from_dir) ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique @@ -685,9 +707,9 @@ distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags check-am: all-am check: check-am -all-am: Makefile $(LTLIBRARIES) +all-am: Makefile $(LTLIBRARIES) $(HEADERS) installdirs: - for dir in "$(DESTDIR)$(toolexeclibdir)"; do \ + for dir in "$(DESTDIR)$(toolexeclibdir)" "$(DESTDIR)$(toolexeclibdir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am @@ -749,7 +771,8 @@ install-dvi: install-dvi-am install-dvi-am: -install-exec-am: install-toolexeclibLTLIBRARIES +install-exec-am: install-nodist_toolexeclibHEADERS \ + install-toolexeclibLTLIBRARIES install-html: install-html-am @@ -789,7 +812,8 @@ ps: ps-am ps-am: -uninstall-am: uninstall-toolexeclibLTLIBRARIES +uninstall-am: uninstall-nodist_toolexeclibHEADERS \ + uninstall-toolexeclibLTLIBRARIES .MAKE: install-am install-strip @@ -800,17 +824,21 @@ uninstall-am: uninstall-toolexeclibLTLIB info-am install install-am install-data install-data-am \ install-dvi install-dvi-am install-exec install-exec-am \ install-html install-html-am install-info install-info-am \ - install-man install-pdf install-pdf-am install-ps \ - install-ps-am install-strip install-toolexeclibLTLIBRARIES \ - installcheck installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - tags tags-am uninstall uninstall-am \ + install-man install-nodist_toolexeclibHEADERS install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + install-toolexeclibLTLIBRARIES installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am uninstall-nodist_toolexeclibHEADERS \ uninstall-toolexeclibLTLIBRARIES .PRECIOUS: Makefile +libhwasan_preinit.o: hwasan_preinit.o + cp $< $@ + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: