[AArch64] Bugfix when using execute-only and memtag sanitizer together by Il-Capitano · Pull Request #133084 · llvm/llvm-project (original) (raw)

@llvm/pr-subscribers-backend-aarch64

@llvm/pr-subscribers-mc

Author: Csanád Hajdú (Il-Capitano)

Changes

Support for execute-only code generation (#125687) introduced a bug in the case where the memtag sanitizer is used in a module containing a mix of execute-only and non-execute-only functions.

The bug is caused by using return instead of break to short-circuit a loop, which meant that the rest of the function dealing with memtag sanitizer logic wasn't run.


Full diff: https://github.com/llvm/llvm-project/pull/133084.diff

2 Files Affected:

diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp index 98bd102d8f4c1..b12a12436db81 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp @@ -511,11 +511,17 @@ void AArch64TargetELFStreamer::finish() { })) { auto *Text = static_cast<MCSectionELF *>(Ctx.getObjectFileInfo()->getTextSection());

diff --git a/llvm/test/MC/AArch64/execute-only-memtag.ll b/llvm/test/MC/AArch64/execute-only-memtag.ll new file mode 100644 index 0000000000000..02daf3179101f --- /dev/null +++ b/llvm/test/MC/AArch64/execute-only-memtag.ll @@ -0,0 +1,18 @@ +; RUN: llc %s -mtriple=aarch64-linux-android31 -filetype=obj -o %t.o +; RUN: llvm-readelf -r %t.o | FileCheck %s + +; CHECK: Relocation section '.rela.memtag.globals.static' at offset {{.}} contains 1 entries: +; CHECK-NEXT: Type {{.}} Symbol's Name +; CHECK-NEXT: R_AARCH64_NONE {{.*}} global + +@global = global i32 1, sanitize_memtag + +define void @foo() {