[JITLink][ELF][AArch64] Add support for ELF R_AARCH64_ABS32 relocation.
authorLang Hames <lhames@gmail.com>
Mon, 20 Mar 2023 20:50:27 +0000 (20:50 +0000)
committerLang Hames <lhames@gmail.com>
Mon, 20 Mar 2023 21:00:20 +0000 (21:00 +0000)
This relocation is commonly used in debug sections. Failure to handle it caused
the test failure in https://lab.llvm.org/buildbot/#/builders/197/builds/4272,
which forced the reversion, in f721fcb6ed0, of 57aeb305460 ("[JITLink][ELF]
Don't skip debug info sections by default"). This fix should allow us to
re-land 57aeb305460.

llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp
llvm/test/ExecutionEngine/JITLink/AArch64/ELF_R_AARCH64_ABS32.yaml [new file with mode: 0644]

index 3eb7e1b..ab47f86 100644 (file)
@@ -58,6 +58,7 @@ private:
     ELFMovwAbsG1,
     ELFMovwAbsG2,
     ELFMovwAbsG3,
+    ELFAbs32,
     ELFAbs64,
     ELFPrel32,
     ELFPrel64,
@@ -98,6 +99,8 @@ private:
       return ELFMovwAbsG2;
     case ELF::R_AARCH64_MOVW_UABS_G3:
       return ELFMovwAbsG3;
+    case ELF::R_AARCH64_ABS32:
+      return ELFAbs32;
     case ELF::R_AARCH64_ABS64:
       return ELFAbs64;
     case ELF::R_AARCH64_PREL32:
@@ -284,6 +287,10 @@ private:
       Kind = aarch64::MoveWide16;
       break;
     }
+    case ELFAbs32: {
+      Kind = aarch64::Pointer32;
+      break;
+    }
     case ELFAbs64: {
       Kind = aarch64::Pointer64;
       break;
@@ -357,6 +364,8 @@ private:
       return "ELFMovwAbsG2";
     case ELFMovwAbsG3:
       return "ELFMovwAbsG3";
+    case ELFAbs32:
+      return "ELFAbs32";
     case ELFAbs64:
       return "ELFAbs64";
     case ELFPrel32:
diff --git a/llvm/test/ExecutionEngine/JITLink/AArch64/ELF_R_AARCH64_ABS32.yaml b/llvm/test/ExecutionEngine/JITLink/AArch64/ELF_R_AARCH64_ABS32.yaml
new file mode 100644 (file)
index 0000000..ca992ad
--- /dev/null
@@ -0,0 +1,90 @@
+# Check success and failure cases of R_AARCH64_32 handling.
+# This file contains a single R_AARCH64_ABS32 relocation. We expect the
+# relocation to apply successfully when we assign x an address in the low
+# 32-bits of the address space, and fail if we assign x an address outside that
+# range.
+
+# RUN: yaml2obj -o %t.o %s
+# RUN: llvm-jitlink -abs x=0x12345678 -noexec -check=%s %t.o
+# RUN: not llvm-jitlink -abs x=0x123456789 -noexec %t.o 2>&1 | \
+# RUN:   FileCheck -check-prefix=CHECK-ERROR %s
+
+# jitlink-check: *{8}xptr = x
+
+# CHECK-ERROR: relocation target "x" {{.*}} is out of range of Pointer32 fixup
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_AARCH64
+  SectionHeaderStringTable: .strtab
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x4
+    Content:         E0031F2AC0035FD6
+  - Name:            .data
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_WRITE, SHF_ALLOC ]
+    AddressAlign:    0x8
+    Content:         '0000000000000000'
+  - Name:            .comment
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_MERGE, SHF_STRINGS ]
+    AddressAlign:    0x1
+    EntSize:         0x1
+    Content:         00636C616E672076657273696F6E2031372E302E30202868747470733A2F2F6769746875622E636F6D2F6C6C766D2F6C6C766D2D70726F6A6563742E67697420333130616161633834363336656336633933383739633138643933653332663537623264383938362900
+  - Name:            .note.GNU-stack
+    Type:            SHT_PROGBITS
+    AddressAlign:    0x1
+  - Name:            .rela.data
+    Type:            SHT_RELA
+    Flags:           [ SHF_INFO_LINK ]
+    Link:            .symtab
+    AddressAlign:    0x8
+    Info:            .data
+    Relocations:
+      - Symbol:          x
+        Type:            R_AARCH64_ABS32
+  - Name:            .llvm_addrsig
+    Type:            SHT_LLVM_ADDRSIG
+    Flags:           [ SHF_EXCLUDE ]
+    Link:            .symtab
+    AddressAlign:    0x1
+    Symbols:         [ x ]
+  - Type:            SectionHeaderTable
+    Sections:
+      - Name:            .strtab
+      - Name:            .text
+      - Name:            .data
+      - Name:            .rela.data
+      - Name:            .comment
+      - Name:            .note.GNU-stack
+      - Name:            .llvm_addrsig
+      - Name:            .symtab
+Symbols:
+  - Name:            hw.c
+    Type:            STT_FILE
+    Index:           SHN_ABS
+  - Name:            '$x.0'
+    Section:         .text
+  - Name:            '$d.1'
+    Section:         .data
+  - Name:            '$d.2'
+    Section:         .comment
+  - Name:            main
+    Type:            STT_FUNC
+    Section:         .text
+    Binding:         STB_GLOBAL
+    Size:            0x8
+  - Name:            xptr
+    Type:            STT_OBJECT
+    Section:         .data
+    Binding:         STB_GLOBAL
+    Size:            0x8
+  - Name:            x
+    Binding:         STB_GLOBAL
+...