[lld] db8559e - Revert "[lld-macho] Support X86_64_RELOC_UNSIGNED"

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Tue May 19 08:30:12 PDT 2020


Author: Jez Ng
Date: 2020-05-19T08:30:02-07:00
New Revision: db8559eee4a07c44babcc4618eef3d185cf79cc6

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

LOG: Revert "[lld-macho] Support X86_64_RELOC_UNSIGNED"

This reverts commit 1f820e35596bac036a7f759c4de41fcc2e642719.

Added: 
    

Modified: 
    lld/MachO/Arch/X86_64.cpp
    lld/MachO/InputFiles.cpp
    lld/MachO/InputSection.cpp
    lld/MachO/InputSection.h
    lld/MachO/Target.h

Removed: 
    lld/test/MachO/x86-64-reloc-unsigned.s


################################################################################
diff  --git a/lld/MachO/Arch/X86_64.cpp b/lld/MachO/Arch/X86_64.cpp
index 21ae3d2fe790..08b23a57c3d3 100644
--- a/lld/MachO/Arch/X86_64.cpp
+++ b/lld/MachO/Arch/X86_64.cpp
@@ -47,8 +47,6 @@ uint64_t X86_64::getImplicitAddend(const uint8_t *loc, uint8_t type) const {
   case X86_64_RELOC_SIGNED_4:
   case X86_64_RELOC_GOT_LOAD:
     return read32le(loc);
-  case X86_64_RELOC_UNSIGNED:
-    return read64le(loc);
   default:
     error("TODO: Unhandled relocation type " + std::to_string(type));
     return 0;
@@ -67,9 +65,6 @@ void X86_64::relocateOne(uint8_t *loc, uint8_t type, uint64_t val) const {
     // since the RIP has advanced by 4 at this point.
     write32le(loc, val - 4);
     break;
-  case X86_64_RELOC_UNSIGNED:
-    write64le(loc, val);
-    break;
   default:
     llvm_unreachable(
         "getImplicitAddend should have flagged all unhandled relocation types");

diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 9093a08d5851..cfd3df449a9d 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -173,10 +173,11 @@ void InputFile::parseRelocations(const section_64 &sec,
       fatal("TODO: Scattered relocations not supported");
 
     auto rel = reinterpret_cast<const relocation_info &>(anyRel);
+    if (!rel.r_pcrel)
+      fatal("TODO: Only pcrel relocations are supported");
 
     Reloc r;
     r.type = rel.r_type;
-    r.pcrel = rel.r_pcrel;
     uint32_t secRelOffset = rel.r_address;
     uint64_t rawAddend =
         target->getImplicitAddend(buf + sec.offset + secRelOffset, r.type);
@@ -185,9 +186,6 @@ void InputFile::parseRelocations(const section_64 &sec,
       r.target = symbols[rel.r_symbolnum];
       r.addend = rawAddend;
     } else {
-      if (!rel.r_pcrel)
-        fatal("TODO: Only pcrel section relocations are supported");
-
       if (rel.r_symbolnum == 0 || rel.r_symbolnum > subsections.size())
         fatal("invalid section index in relocation for offset " +
               std::to_string(r.offset) + " in section " + sec.sectname +

diff  --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp
index 84ed52d70ce9..5453c0b8cd78 100644
--- a/lld/MachO/InputSection.cpp
+++ b/lld/MachO/InputSection.cpp
@@ -43,7 +43,7 @@ void InputSection::writeTo(uint8_t *buf) {
     }
 
     uint64_t val = va + r.addend;
-    if (r.pcrel)
+    if (1) // TODO: handle non-pcrel relocations
       val -= getVA() + r.offset;
     target->relocateOne(buf + r.offset, r.type, val);
   }

diff  --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h
index 5c21b83d74a5..1d11b8e64c30 100644
--- a/lld/MachO/InputSection.h
+++ b/lld/MachO/InputSection.h
@@ -24,13 +24,12 @@ class Symbol;
 
 struct Reloc {
   uint8_t type;
-  bool pcrel;
+  // Adding this offset to the address of the target symbol or subsection gives
+  // the destination that this relocation refers to.
+  uint32_t addend;
   // The offset from the start of the subsection that this relocation belongs
   // to.
   uint32_t offset;
-  // Adding this offset to the address of the target symbol or subsection gives
-  // the destination that this relocation refers to.
-  uint64_t addend;
   llvm::PointerUnion<Symbol *, InputSection *> target;
 };
 

diff  --git a/lld/MachO/Target.h b/lld/MachO/Target.h
index 1af7c03f70ab..9781b70cb46c 100644
--- a/lld/MachO/Target.h
+++ b/lld/MachO/Target.h
@@ -29,7 +29,6 @@ enum {
 class TargetInfo {
 public:
   virtual ~TargetInfo() = default;
-
   virtual uint64_t getImplicitAddend(const uint8_t *loc,
                                      uint8_t type) const = 0;
   virtual void relocateOne(uint8_t *loc, uint8_t type, uint64_t val) const = 0;

diff  --git a/lld/test/MachO/x86-64-reloc-unsigned.s b/lld/test/MachO/x86-64-reloc-unsigned.s
deleted file mode 100644
index 976532f42ee9..000000000000
--- a/lld/test/MachO/x86-64-reloc-unsigned.s
+++ /dev/null
@@ -1,24 +0,0 @@
-# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
-# RUN: lld -flavor darwinnew -o %t %t.o
-# RUN: llvm-objdump --full-contents %t | FileCheck %s
-# CHECK: Contents of section foo:
-# CHECK:  2000 08200000 00000000
-# CHECK: Contents of section bar:
-# CHECK:  2008 11311111 01000000
-
-.globl _main, _foo, _bar
-
-.section __DATA,foo
-_foo:
-.quad _bar
-
-.section __DATA,bar
-_bar:
-## The unsigned relocation should support 64-bit addends
-.quad _foo + 0x111111111
-
-.text
-_main:
-  mov $0, %rax
-  ret


        


More information about the llvm-commits mailing list