[JITLink][ELF][x86-64] Implement ELF::R_X86_64_NONE.
authorLang Hames <lhames@gmail.com>
Sun, 16 Apr 2023 03:13:38 +0000 (03:13 +0000)
committerLang Hames <lhames@gmail.com>
Sun, 16 Apr 2023 03:19:11 +0000 (03:19 +0000)
R_X86_64_NONE is a no-op, so we just need to return from addSingleRelocation
early.

llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_NONE.yaml [new file with mode: 0644]

index 7ac088f..cab181f 100644 (file)
@@ -129,6 +129,12 @@ private:
                             Block &BlockToFix) {
     using Base = ELFLinkGraphBuilder<ELFT>;
 
+    auto ELFReloc = Rel.getType(false);
+
+    // R_X86_64_NONE is a no-op.
+    if (LLVM_UNLIKELY(ELFReloc == ELF::R_X86_64_NONE))
+      return Error::success();
+
     uint32_t SymbolIndex = Rel.getSymbol(false);
     auto ObjSymbol = Base::Obj.getRelocationSymbol(Rel, Base::SymTabSec);
     if (!ObjSymbol)
@@ -147,7 +153,6 @@ private:
     int64_t Addend = Rel.r_addend;
     Edge::Kind Kind = Edge::Invalid;
 
-    auto ELFReloc = Rel.getType(false);
     switch (ELFReloc) {
     case ELF::R_X86_64_PC32:
       Kind = x86_64::Delta32;
diff --git a/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_NONE.yaml b/llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_NONE.yaml
new file mode 100644 (file)
index 0000000..bbf68ef
--- /dev/null
@@ -0,0 +1,59 @@
+# RUN: yaml2obj -o %t.o %s
+# RUN: llvm-jitlink -noexec -check=%s %t.o
+#
+# Check that R_X86_64_NONE relocations are handled without modifying the fixup
+# location.
+
+# jitlink-check: *{8}P = 42
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+  SectionHeaderStringTable: .strtab
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x4
+  - Name:            .text.main
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x10
+    Content:         31C0C3
+  - Name:            .data
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_WRITE, SHF_ALLOC ]
+    AddressAlign:    0x8
+    Content:         '2A00000000000000'
+  - Name:            .rela.data
+    Type:            SHT_RELA
+    Flags:           [ SHF_INFO_LINK ]
+    Link:            .symtab
+    AddressAlign:    0x8
+    Info:            .data
+    Relocations:
+      - Symbol:          P
+        Type:            R_X86_64_NONE
+  - Type:            SectionHeaderTable
+    Sections:
+      - Name:            .strtab
+      - Name:            .text
+      - Name:            .text.main
+      - Name:            .data
+      - Name:            .rela.data
+      - Name:            .symtab
+Symbols:
+  - Name:            main
+    Type:            STT_FUNC
+    Section:         .text.main
+    Binding:         STB_GLOBAL
+    Size:            0x3
+  - Name:            P
+    Type:            STT_OBJECT
+    Section:         .data
+    Binding:         STB_GLOBAL
+    Size:            0x8
+...