Skip to content

Commit 5ff8c03

Browse files
authored
[AArch64] Bugfix when using execute-only and memtag sanitizer together (#133084)
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.
1 parent 6b647de commit 5ff8c03

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,17 @@ void AArch64TargetELFStreamer::finish() {
511511
})) {
512512
auto *Text =
513513
static_cast<MCSectionELF *>(Ctx.getObjectFileInfo()->getTextSection());
514-
for (auto &F : *Text)
515-
if (auto *DF = dyn_cast<MCDataFragment>(&F))
516-
if (!DF->getContents().empty())
517-
return;
518-
Text->setFlags(Text->getFlags() | ELF::SHF_AARCH64_PURECODE);
514+
bool Empty = true;
515+
for (auto &F : *Text) {
516+
if (auto *DF = dyn_cast<MCDataFragment>(&F)) {
517+
if (!DF->getContents().empty()) {
518+
Empty = false;
519+
break;
520+
}
521+
}
522+
}
523+
if (Empty)
524+
Text->setFlags(Text->getFlags() | ELF::SHF_AARCH64_PURECODE);
519525
}
520526

521527
MCSectionELF *MemtagSec = nullptr;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: llc %s -mtriple=aarch64-linux-android31 -filetype=obj -o %t.o
2+
; RUN: llvm-readelf -r %t.o | FileCheck %s
3+
4+
; CHECK: Relocation section '.rela.memtag.globals.static' at offset {{.*}} contains 1 entries:
5+
; CHECK-NEXT: Type {{.*}} Symbol's Name
6+
; CHECK-NEXT: R_AARCH64_NONE {{.*}} global
7+
8+
@global = global i32 1, sanitize_memtag
9+
10+
define void @foo() {
11+
ret void
12+
}
13+
14+
define void @bar() #0 {
15+
ret void
16+
}
17+
18+
attributes #0 = { "target-features"="+execute-only" }

0 commit comments

Comments
 (0)