[lld] 0407197 - [lld-macho] Support GOT relocations to __dso_handle

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 17:44:47 PDT 2020


Author: Jez Ng
Date: 2020-08-27T17:44:17-07:00
New Revision: 0407197711f1004b79e3d7250f0612f67100e640

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

LOG: [lld-macho] Support GOT relocations to __dso_handle

Found such a relocation while testing some real world programs.

Reviewed By: #lld-macho, smeenai

Differential Revision: https://reviews.llvm.org/D86642

Added: 
    

Modified: 
    lld/MachO/Symbols.h
    lld/test/MachO/dso-handle.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Symbols.h b/lld/MachO/Symbols.h
index f12cc8549bd6..33ba00860ef3 100644
--- a/lld/MachO/Symbols.h
+++ b/lld/MachO/Symbols.h
@@ -171,9 +171,13 @@ class DSOHandle : public Symbol {
 
   uint64_t getFileOffset() const override;
 
+  bool isWeakDef() const override { return false; }
+
+  bool isTlv() const override { return false; }
+
   static constexpr StringRef name = "___dso_handle";
 
-  static bool classof(const Symbol *s) { return s->kind() == DefinedKind; }
+  static bool classof(const Symbol *s) { return s->kind() == DSOHandleKind; }
 };
 
 union SymbolUnion {

diff  --git a/lld/test/MachO/dso-handle.s b/lld/test/MachO/dso-handle.s
index f57ec7260fe0..9cef6448b370 100644
--- a/lld/test/MachO/dso-handle.s
+++ b/lld/test/MachO/dso-handle.s
@@ -3,14 +3,17 @@
 
 # RUN: lld -flavor darwinnew %t.o -o %t
 # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
-# CHECK: leaq {{.*}} # 100000000
+# CHECK:      leaq {{.*}} # 100000000
+# CHECK-NEXT: leaq {{.*}} # 100000000
 
 # RUN: lld -flavor darwinnew -dylib %t.o -o %t.dylib
 # RUN: llvm-objdump -d --no-show-raw-insn %t.dylib | FileCheck %s --check-prefix=DYLIB-CHECK
-# DYLIB-CHECK: leaq {{.*}} # 0
+# DYLIB-CHECK:      leaq {{.*}} # 0
+# DYLIB-CHECK-NEXT: leaq {{.*}} # 0
 
 .globl _main
 .text
 _main:
   leaq ___dso_handle(%rip), %rdx
+  movq ___dso_handle at GOTPCREL(%rip), %rdx
   ret


        


More information about the llvm-commits mailing list