From owner-dev-commits-src-all@freebsd.org Fri Mar 12 17:36:24 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id E866157F040; Fri, 12 Mar 2021 17:36:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DxtK34xjRz4ZWY; Fri, 12 Mar 2021 17:36:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 97B351BD0B; Fri, 12 Mar 2021 17:36:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 12CHaNd6052633; Fri, 12 Mar 2021 17:36:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 12CHaNXr052632; Fri, 12 Mar 2021 17:36:23 GMT (envelope-from git) Date: Fri, 12 Mar 2021 17:36:23 GMT Message-Id: <202103121736.12CHaNXr052632@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alex Richardson Subject: git: fe525d3f9166 - main - Allow using sanitizers for ssp tests with out-of-tree compiler MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: arichardson X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fe525d3f916602ddac3286641dab8f5e274daa44 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Mar 2021 17:36:24 -0000 The branch main has been updated by arichardson: URL: https://cgit.FreeBSD.org/src/commit/?id=fe525d3f916602ddac3286641dab8f5e274daa44 commit fe525d3f916602ddac3286641dab8f5e274daa44 Author: Alex Richardson AuthorDate: 2021-03-12 17:15:00 +0000 Commit: Alex Richardson CommitDate: 2021-03-12 17:15:33 +0000 Allow using sanitizers for ssp tests with out-of-tree compiler With an out-of-tree Clang, we can use the -resource-dir flag when linking to point it at the runtime libraries from the current SYSROOT. This moves the path to the clang-internal library directory to a separate .mk file that can be used by Makefiles that want to find the sanitizer libraries. I intend to re-use this .mk file for my upcoming changes that allow building the entire base system with ASAN/UBSAN/MSAN. Reviewed By: dim Differential Revision: https://reviews.freebsd.org/D28852 --- lib/libc/tests/ssp/Makefile | 27 ++++++++++++--------------- lib/libclang_rt/Makefile.inc | 12 ++---------- lib/libclang_rt/compiler-rt-vars.mk | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/lib/libc/tests/ssp/Makefile b/lib/libc/tests/ssp/Makefile index 655130ab309d..452c57246e39 100644 --- a/lib/libc/tests/ssp/Makefile +++ b/lib/libc/tests/ssp/Makefile @@ -6,9 +6,10 @@ MK_WERROR= no WARNS?= 2 CFLAGS.h_raw+= -fstack-protector-all -Wstack-protector -.if ${COMPILER_TYPE} == "clang" && ${CC} == "cc" -# Only use -fsanitize=bounds when using the in-tree compiler. Otherwise -# we may link to a sanitizer library targeted at a newer kernel/libc. +.if ${COMPILER_TYPE} == "clang" +# Only use -fsanitize=bounds when using clang. Otherwise we are not able to +# override the sanitizer runtime libraries to be the ones installed on the +# target system. CFLAGS.h_raw+= -fsanitize=bounds .elif ${COMPILER_TYPE} == "gcc" CFLAGS.h_raw+= --param ssp-buffer-size=1 @@ -25,24 +26,20 @@ PROGS+= h_getcwd PROGS+= h_memcpy PROGS+= h_memmove PROGS+= h_memset -# This testcase doesn't run properly when not compiled with -fsantize=bounds -# with clang, which is currently contingent on a compiler_rt update -# # XXX: the h_raw/h_read testcases don't cause a SIGABRT with in-tree gcc right # now on amd64 when it trips the stack bounds specified in t_ssp.sh . This # probably needs to be fixed as it's currently hardcoded. -# -# sanitizer is not tested or supported for ARM right now. sbruno -.if ${COMPILER_TYPE} == "clang" && ${CC} == "cc" && !defined(_SKIP_BUILD) && \ +.if ${COMPILER_TYPE} == "clang" && !defined(_SKIP_BUILD) && \ (!defined(_RECURSING_PROGS) || ${PROG} == "h_raw") -.if !defined(_CLANG_RESOURCE_DIR) -_CLANG_RESOURCE_DIR!= ${CC:N${CCACHE_BIN}} -print-resource-dir -.export _CLANG_RESOURCE_DIR -.endif -_libclang_rt_arch= ${MACHINE_ARCH:S/amd64/x86_64/:C/hf$//:S/mipsn32/mips64/} -_libclang_rt_ubsan= ${_CLANG_RESOURCE_DIR}/lib/freebsd/libclang_rt.ubsan_standalone-${_libclang_rt_arch}.a +.include "${SRCTOP}/lib/libclang_rt/compiler-rt-vars.mk" +_libclang_rt_ubsan= ${SYSROOT}${SANITIZER_LIBDIR}/libclang_rt.ubsan_standalone-${CRTARCH}.a .if exists(${_libclang_rt_ubsan}) PROGS+= h_raw +LDADD.h_raw+= ${SANITIZER_LDFLAGS} +.else +.if make(all) +.info "Could not find runtime library ${_libclang_rt_ubsan}, skipping h_raw" +.endif .endif .endif PROGS+= h_read diff --git a/lib/libclang_rt/Makefile.inc b/lib/libclang_rt/Makefile.inc index 01bfd72b5a7e..946d3f4c77a7 100644 --- a/lib/libclang_rt/Makefile.inc +++ b/lib/libclang_rt/Makefile.inc @@ -2,20 +2,12 @@ .include -# armv[67] is a bit special since we allow a soft-floating version via -# CPUTYPE matching *soft*. This variant may not actually work though. -.if ${MACHINE_ARCH:Marmv[67]*} != "" && \ - (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} == "") -CRTARCH?= armhf -.else -CRTARCH?= ${MACHINE_ARCH:C/amd64/x86_64/} -.endif CRTSRC= ${SRCTOP}/contrib/llvm-project/compiler-rt +.include "compiler-rt-vars.mk" .PATH: ${CRTSRC}/lib -CLANGDIR= /usr/lib/clang/11.0.1 -LIBDIR= ${CLANGDIR}/lib/freebsd +LIBDIR= ${SANITIZER_LIBDIR} SHLIBDIR= ${LIBDIR} NO_PIC= diff --git a/lib/libclang_rt/compiler-rt-vars.mk b/lib/libclang_rt/compiler-rt-vars.mk new file mode 100644 index 000000000000..17424785c372 --- /dev/null +++ b/lib/libclang_rt/compiler-rt-vars.mk @@ -0,0 +1,24 @@ +CLANG_SUBDIR=clang/11.0.1 +CLANGDIR= /usr/lib/${CLANG_SUBDIR} +SANITIZER_LIBDIR= ${CLANGDIR}/lib/freebsd + +# armv[67] is a bit special since we allow a soft-floating version via +# CPUTYPE matching *soft*. This variant may not actually work though. +.if ${MACHINE_ARCH:Marmv[67]*} != "" && \ + (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} == "") +CRTARCH?= armhf +.else +CRTARCH?= ${MACHINE_ARCH:S/amd64/x86_64/:C/hf$//:S/mipsn32/mips64/} +.endif + +.if ${COMPILER_TYPE} == "clang" +# The only way to set the path to the sanitizer libraries with clang is to +# override the resource directory. +# Note: lib/freebsd is automatically appended to the -resource-dir value. +SANITIZER_LDFLAGS= -resource-dir=${SYSROOT}${CLANGDIR} +# Also set RPATH to ensure that the dynamically linked runtime libs are found. +SANITIZER_LDFLAGS+= -Wl,--enable-new-dtags +SANITIZER_LDFLAGS+= -Wl,-rpath,${SANITIZER_LIBDIR} +.else +.error "Unknown link flags for -fsanitize=... COMPILER_TYPE=${COMPILER_TYPE}" +.endif