[llvm] 0b69cc8 - [AArch64] Improve sanitize_memtag test

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 10 13:25:14 PDT 2023


Author: Fangrui Song
Date: 2023-07-10T13:25:09-07:00
New Revision: 0b69cc8bcba79366aeee1531c61b1e8255a2d6c4

URL: https://github.com/llvm/llvm-project/commit/0b69cc8bcba79366aeee1531c61b1e8255a2d6c4
DIFF: https://github.com/llvm/llvm-project/commit/0b69cc8bcba79366aeee1531c61b1e8255a2d6c4.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/test/MC/AArch64/global-tagging.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 79a4e168e7e795..5381dfdd184cc9 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -730,8 +730,8 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
 
     if (T.getArch() != Triple::aarch64 || !T.isAndroid())
       OutContext.reportError(SMLoc(),
-                             "Tagged symbols (-fsanitize=memtag-globals) are "
-                             "only supported on aarch64 + Android.");
+                             "tagged symbols (-fsanitize=memtag-globals) are "
+                             "only supported on AArch64 Android");
     OutStreamer->emitSymbolAttribute(EmittedSym, MAI->getMemtagAttr());
   }
 

diff  --git a/llvm/test/MC/AArch64/global-tagging.ll b/llvm/test/MC/AArch64/global-tagging.ll
index 871c6fd0c39ef4..0c730ecd00c43e 100644
--- a/llvm/test/MC/AArch64/global-tagging.ll
+++ b/llvm/test/MC/AArch64/global-tagging.ll
@@ -1,6 +1,8 @@
 ;; Tagged symbols are only available on aarch64-linux-android.
-; RUN: not llc %s -mtriple=aarch64-linux-unknown
-; RUN: not llc %s -mtriple=x86_64-linux-unknown
+; RUN: not llc %s -mtriple=aarch64-unknown-linux 2>&1 | FileCheck %s --check-prefix=ERR
+; RUN: not llc %s -mtriple=x86_64-unknown-linux 2>&1 | FileCheck %s --check-prefix=ERR
+
+; ERR: error: tagged symbols (-fsanitize=memtag-globals) are only supported on AArch64 Android
 
 ; RUN: llc %s -mtriple=aarch64-linux-android31 -o %t.S
 ; RUN: FileCheck %s --input-file=%t.S --check-prefix=CHECK-ASM
@@ -12,6 +14,13 @@
 ; RUN: yaml2obj %t.yaml -o %t.o
 ; RUN: llvm-readelf -r %t.o | FileCheck %s --check-prefix=CHECK-RELOCS
 
+;; Check we don't create relocations referencing a section symbol for sanitize_memtag globals.
+; CHECK-RELOCS:      Relocation section '.rela.text' {{.*}} contains 4 entries:
+; CHECK-RELOCS:      R_AARCH64_ADR_GOT_PAGE     {{.*}} internal_four + 0
+; CHECK-RELOCS-NEXT: R_AARCH64_ADR_GOT_PAGE     {{.*}} four + 0
+; CHECK-RELOCS-NEXT: R_AARCH64_LD64_GOT_LO12_NC {{.*}} internal_four + 0
+; CHECK-RELOCS-NEXT: R_AARCH64_LD64_GOT_LO12_NC {{.*}} four + 0
+
 ; CHECK-RELOCS:     Relocation section '.rela.memtag.globals.static' {{.*}} contains 4 entries
 ; CHECK-RELOCS:     R_AARCH64_NONE {{.*}} internal_four
 ; CHECK-RELOCS:     R_AARCH64_NONE {{.*}} four
@@ -40,7 +49,15 @@
 ; CHECK-ASM-NOT: .memtag specialcaselisted
 
 @internal_four = internal global i32 1, sanitize_memtag
- at four = global i32 1, sanitize_memtag
+ at four = dso_local global i32 1, sanitize_memtag
 @sixteen = global [16 x i8] zeroinitializer, sanitize_memtag
 @huge = global [16777232 x i8] zeroinitializer, sanitize_memtag
 @specialcaselisted = global i16 2
+
+define i32 @use() {
+entry:
+  %a = load i32, ptr @internal_four
+  %b = load i32, ptr @four
+  %sum = add i32 %a, %b
+  ret i32 %sum
+}


        


More information about the llvm-commits mailing list