From e7f5533a5a656cfd144d85a1b766522e432e33b3 Mon Sep 17 00:00:00 2001 From: Yaowen Mei Date: Thu, 24 Oct 2024 03:41:33 +0000 Subject: [PATCH] Patch LLVM/Clang to support memtag-stack Previously, we pypassed the clang flag `-fsanitize=memtag-stack` so that `m libc` was able to build with these two CLs (aosp/3261733, aosp/3264014). But just found out today that this is not enough: 1. `m libbase` was still falling back due to clang flag like this: `-fsanitize=integer,integer,memtag-stack` 2. There are also some other targets depending on this flag (see example: https://paste.googleplex.com/4516018109284352) This CL patched this github CL (http://shortn/_QQURhHpCQy) into reclient's input processor, so that re-client officially supports this memtag-stack clang flag. Test: abtd run: 1) caiman_fullmte_userdebug 8 fallbacks (http://shortn/_yy6YSVV0Cf), 2) kiyomi_fullmte-userdebug 8 fallbacks (http://shortn/_5UJCZ6PSjS) Bug: b/371029823 Change-Id: I71651b00c27c0595a73ec1eb182277c55eaf929b GitOrigin-RevId: 4f4b37ac14617145401b77709dda9738ab10aaf1 --- .../action/cppcompile/preprocessor.go | 3 --- .../action/cppcompile/preprocessor_test.go | 1 - module_extensions/llvm.bzl | 4 +++- .../llvm-delay-sanitizer-args-parsing.patch | 24 +++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 third_party/patches/llvm/llvm-delay-sanitizer-args-parsing.patch diff --git a/internal/pkg/inputprocessor/action/cppcompile/preprocessor.go b/internal/pkg/inputprocessor/action/cppcompile/preprocessor.go index 2df77991..81fcf62e 100644 --- a/internal/pkg/inputprocessor/action/cppcompile/preprocessor.go +++ b/internal/pkg/inputprocessor/action/cppcompile/preprocessor.go @@ -258,9 +258,6 @@ func (p *Preprocessor) BuildCommandLine(outputFlag string, outputFlagJoined bool args := []string{executablePath} for _, flag := range p.Flags.Flags { key, value := flag.Key, flag.Value - if key == "-fsanitize=" && value == "memtag-stack" { - continue - } if key == clangCompilerArgFlag { if _, present := toRemoveXclangFlags[value]; present { continue diff --git a/internal/pkg/inputprocessor/action/cppcompile/preprocessor_test.go b/internal/pkg/inputprocessor/action/cppcompile/preprocessor_test.go index 2819dac6..63a06b13 100644 --- a/internal/pkg/inputprocessor/action/cppcompile/preprocessor_test.go +++ b/internal/pkg/inputprocessor/action/cppcompile/preprocessor_test.go @@ -343,7 +343,6 @@ func TestComputeSpec_SysrootAndProfileSampleUseArgsConvertedToAbsolutePath(t *te {Key: "-isysroot", Value: "../c/d", Joined: true}, {Key: "--sysroot=", Value: fmt.Sprintf("%s/e/f", pwd), Joined: true}, {Key: "-fprofile-sample-use=", Value: "../c/d/abc.prof", Joined: true}, - {Key: "-fsanitize=", Value: "memtag-stack", Joined: true}, {Key: "-fsanitize-blacklist=", Value: fmt.Sprintf("%s/e/f/ignores.txt", pwd), Joined: true}, {Key: "-fsanitize-ignorelist=", Value: fmt.Sprintf("%s/e/f/ignores2.txt", pwd), Joined: true}, {Key: "-fprofile-list=", Value: fmt.Sprintf("%s/e/f/fun.list", pwd), Joined: true}, diff --git a/module_extensions/llvm.bzl b/module_extensions/llvm.bzl index 7cf38685..d32ea38e 100644 --- a/module_extensions/llvm.bzl +++ b/module_extensions/llvm.bzl @@ -1,4 +1,5 @@ """Apply llvm_configure to produce a llvm-project repo.""" + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # Refer to go/rbe/dev/x/playbook/upgrading_clang_scan_deps @@ -34,6 +35,7 @@ def _llvm_extension_impl(ctx): # @llvm//utils/bazel:configure.bzl, @llvm-raw is not pre-defined. "//third_party/patches/llvm:llvm-bzl-config.patch", "//third_party/patches/llvm:llvm-project-overlay-exectools.patch", + "//third_party/patches/llvm:llvm-delay-sanitizer-args-parsing.patch", ], sha256 = LLVM_SHA256, strip_prefix = "llvm-project-%s" % LLVM_COMMIT, @@ -46,4 +48,4 @@ def _llvm_extension_impl(ctx): llvm_extension = module_extension( implementation = _llvm_extension_impl, -) \ No newline at end of file +) diff --git a/third_party/patches/llvm/llvm-delay-sanitizer-args-parsing.patch b/third_party/patches/llvm/llvm-delay-sanitizer-args-parsing.patch new file mode 100644 index 00000000..be4aece1 --- /dev/null +++ b/third_party/patches/llvm/llvm-delay-sanitizer-args-parsing.patch @@ -0,0 +1,24 @@ +diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp +index ca992528ac2e..96695ef5b562 100644 +--- a/clang/lib/Driver/ToolChains/Clang.cpp ++++ b/clang/lib/Driver/ToolChains/Clang.cpp +@@ -6351,8 +6351,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, + options::OPT_no_offload_new_driver, false)) + CmdArgs.push_back("--offload-new-driver"); + +- SanitizeArgs.addArgs(TC, Args, CmdArgs, InputType); +- + const XRayArgs &XRay = TC.getXRayArgs(); + XRay.addArgs(TC, Args, CmdArgs, InputType); + +@@ -7176,6 +7174,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, + } + } + ++ // This needs to run after -Xclang argument forwarding to pick up the target ++ // features enabled through -Xclang -target-feature flags. ++ SanitizeArgs.addArgs(TC, Args, CmdArgs, InputType); ++ + // With -save-temps, we want to save the unoptimized bitcode output from the + // CompileJobAction, use -disable-llvm-passes to get pristine IR generated + // by the frontend.