Skip to content

Commit

Permalink
Patch LLVM/Clang to support memtag-stack
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ywmei-brt1 authored and copybara-github committed Oct 24, 2024
1 parent 609ddf9 commit e7f5533
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
3 changes: 0 additions & 3 deletions internal/pkg/inputprocessor/action/cppcompile/preprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 3 additions & 1 deletion module_extensions/llvm.bzl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -46,4 +48,4 @@ def _llvm_extension_impl(ctx):

llvm_extension = module_extension(
implementation = _llvm_extension_impl,
)
)
24 changes: 24 additions & 0 deletions third_party/patches/llvm/llvm-delay-sanitizer-args-parsing.patch
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit e7f5533

Please sign in to comment.