Skip to content

Commit 0b69cc8

Browse files
committed
[AArch64] Improve sanitize_memtag test
The ELFObjectWriter::shouldRelocateWithSymbol change in D128958 is untested. Add the testing. Also, change a diagnostic to follow the convention (no capitalization or trailing period). Test it.
1 parent d9e04b0 commit 0b69cc8

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,8 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
730730

731731
if (T.getArch() != Triple::aarch64 || !T.isAndroid())
732732
OutContext.reportError(SMLoc(),
733-
"Tagged symbols (-fsanitize=memtag-globals) are "
734-
"only supported on aarch64 + Android.");
733+
"tagged symbols (-fsanitize=memtag-globals) are "
734+
"only supported on AArch64 Android");
735735
OutStreamer->emitSymbolAttribute(EmittedSym, MAI->getMemtagAttr());
736736
}
737737

llvm/test/MC/AArch64/global-tagging.ll

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
;; Tagged symbols are only available on aarch64-linux-android.
2-
; RUN: not llc %s -mtriple=aarch64-linux-unknown
3-
; RUN: not llc %s -mtriple=x86_64-linux-unknown
2+
; RUN: not llc %s -mtriple=aarch64-unknown-linux 2>&1 | FileCheck %s --check-prefix=ERR
3+
; RUN: not llc %s -mtriple=x86_64-unknown-linux 2>&1 | FileCheck %s --check-prefix=ERR
4+
5+
; ERR: error: tagged symbols (-fsanitize=memtag-globals) are only supported on AArch64 Android
46

57
; RUN: llc %s -mtriple=aarch64-linux-android31 -o %t.S
68
; RUN: FileCheck %s --input-file=%t.S --check-prefix=CHECK-ASM
@@ -12,6 +14,13 @@
1214
; RUN: yaml2obj %t.yaml -o %t.o
1315
; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
1416

17+
;; Check we don't create relocations referencing a section symbol for sanitize_memtag globals.
18+
; CHECK-RELOCS: Relocation section '.rela.text' {{.*}} contains 4 entries:
19+
; CHECK-RELOCS: R_AARCH64_ADR_GOT_PAGE {{.*}} internal_four + 0
20+
; CHECK-RELOCS-NEXT: R_AARCH64_ADR_GOT_PAGE {{.*}} four + 0
21+
; CHECK-RELOCS-NEXT: R_AARCH64_LD64_GOT_LO12_NC {{.*}} internal_four + 0
22+
; CHECK-RELOCS-NEXT: R_AARCH64_LD64_GOT_LO12_NC {{.*}} four + 0
23+
1524
; CHECK-RELOCS: Relocation section '.rela.memtag.globals.static' {{.*}} contains 4 entries
1625
; CHECK-RELOCS: R_AARCH64_NONE {{.*}} internal_four
1726
; CHECK-RELOCS: R_AARCH64_NONE {{.*}} four
@@ -40,7 +49,15 @@
4049
; CHECK-ASM-NOT: .memtag specialcaselisted
4150

4251
@internal_four = internal global i32 1, sanitize_memtag
43-
@four = global i32 1, sanitize_memtag
52+
@four = dso_local global i32 1, sanitize_memtag
4453
@sixteen = global [16 x i8] zeroinitializer, sanitize_memtag
4554
@huge = global [16777232 x i8] zeroinitializer, sanitize_memtag
4655
@specialcaselisted = global i16 2
56+
57+
define i32 @use() {
58+
entry:
59+
%a = load i32, ptr @internal_four
60+
%b = load i32, ptr @four
61+
%sum = add i32 %a, %b
62+
ret i32 %sum
63+
}

0 commit comments

Comments
 (0)