[lld] r255835 - Fix negDelta32 relocatable fixups for arm64 in mach-o.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 14:50:16 PST 2015


Author: pete
Date: Wed Dec 16 16:50:16 2015
New Revision: 255835

URL: http://llvm.org/viewvc/llvm-project?rev=255835&view=rev
Log:
Fix negDelta32 relocatable fixups for arm64 in mach-o.

negDelta32 is only ever implicitly generated as the FDE->CIE reference.
We therefore don't emit a relocation for it in the object file in -r mode.

The value we write in to the FDE location therefore needs to point to the
final target address of the CIE, and not the inAtomAddress as it was currently
doing.

Added:
    lld/trunk/test/mach-o/arm64-reloc-negDelta32-fixup.yaml
Modified:
    lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp

Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp?rev=255835&r1=255834&r2=255835&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp Wed Dec 16 16:50:16 2015
@@ -674,7 +674,7 @@ void ArchHandler_arm64::applyFixupReloca
     *loc32 = ref.addend() + inAtomAddress - fixupAddress;
     return;
   case negDelta32:
-    *loc32 = fixupAddress - inAtomAddress + ref.addend();
+    *loc32 = fixupAddress - targetAddress + ref.addend();
     return;
   case pointer64ToGOT:
     *loc64 = 0;

Added: lld/trunk/test/mach-o/arm64-reloc-negDelta32-fixup.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/arm64-reloc-negDelta32-fixup.yaml?rev=255835&view=auto
==============================================================================
--- lld/trunk/test/mach-o/arm64-reloc-negDelta32-fixup.yaml (added)
+++ lld/trunk/test/mach-o/arm64-reloc-negDelta32-fixup.yaml Wed Dec 16 16:50:16 2015
@@ -0,0 +1,124 @@
+# RUN: lld -flavor darwin -arch arm64 -r %s -o %t
+# RUN: lld -flavor darwin -arch arm64 -r %t -o %t2
+# RUN: llvm-objdump -s -section="__eh_frame" %t | FileCheck %s
+# RUN: llvm-objdump -s -section="__eh_frame" %t2 | FileCheck %s
+
+# The reference from FDE->CIE is implicitly created as a negDelta32.
+# We don't emit these in to the binary as relocations, so we need to
+# make sure that the offset in the FDE to the CIE is the correct value.
+# CHECK: 0010 10000000 00000000 017a5200 01781e01
+# CHECK: 0020 100c1f00 20000000 18000000 e4ffffff
+# Note, this one that matters   ^~~~~~~~
+# It needs to be 0x18 as that is the offset back to 0 where the CIE is.
+# CHECK: 0030 ffffffff 20000000 00000000 00480e10
+# CHECK: 0040 9e019d02 00000000
+
+---  !mach-o
+arch:            arm64
+file-type:       MH_OBJECT
+flags:           [ MH_SUBSECTIONS_VIA_SYMBOLS ]
+compat-version:  0.0
+current-version: 0.0
+has-UUID:        false
+OS:              unknown
+sections:        
+  - segment:         __TEXT
+    section:         __text
+    type:            S_REGULAR
+    attributes:      [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
+    alignment:       4
+    address:         0x0000000000000000
+    content:         [ 0xFD, 0x7B, 0xBF, 0xA9, 0xFD, 0x03, 0x00, 0x91, 
+                       0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x91, 
+                       0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x80, 0x52, 
+                       0xFD, 0x7B, 0xC1, 0xA8, 0xC0, 0x03, 0x5F, 0xD6 ]
+    relocations:     
+      - offset:          0x00000010
+        type:            ARM64_RELOC_BRANCH26
+        length:          2
+        pc-rel:          true
+        extern:          true
+        symbol:          6
+      - offset:          0x0000000C
+        type:            ARM64_RELOC_PAGEOFF12
+        length:          2
+        pc-rel:          false
+        extern:          true
+        symbol:          1
+      - offset:          0x00000008
+        type:            ARM64_RELOC_PAGE21
+        length:          2
+        pc-rel:          true
+        extern:          true
+        symbol:          1
+  - segment:         __TEXT
+    section:         __cstring
+    type:            S_CSTRING_LITERALS
+    attributes:      [  ]
+    address:         0x0000000000000020
+    content:         [ 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 
+                       0x72, 0x6C, 0x64, 0x00 ]
+  - segment:         __LD
+    section:         __compact_unwind
+    type:            S_REGULAR
+    attributes:      [  ]
+    alignment:       8
+    address:         0x0000000000000030
+    content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+                       0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 
+                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
+    relocations:     
+      - offset:          0x00000000
+        type:            ARM64_RELOC_UNSIGNED
+        length:          3
+        pc-rel:          false
+        extern:          false
+        symbol:          1
+  - segment:         __TEXT
+    section:         __eh_frame
+    type:            S_COALESCED
+    attributes:      [  ]
+    alignment:       8
+    address:         0x0000000000000050
+    content:         [ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+                       0x01, 0x7A, 0x52, 0x00, 0x01, 0x78, 0x1E, 0x01, 
+                       0x10, 0x0C, 0x1F, 0x00, 0x20, 0x00, 0x00, 0x00, 
+                       0x18, 0x00, 0x00, 0x00, 0xE4, 0xFF, 0xFF, 0xFF, 
+                       0xFF, 0xFF, 0xFF, 0xFF, 0x20, 0x00, 0x00, 0x00, 
+                       0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x0E, 0x10, 
+                       0x9E, 0x01, 0x9D, 0x02, 0x00, 0x00, 0x00, 0x00 ]
+local-symbols:   
+  - name:            ltmp0
+    type:            N_SECT
+    sect:            1
+    value:           0x0000000000000000
+  - name:            L_str
+    type:            N_SECT
+    sect:            2
+    value:           0x0000000000000020
+  - name:            ltmp1
+    type:            N_SECT
+    sect:            2
+    value:           0x0000000000000020
+  - name:            ltmp2
+    type:            N_SECT
+    sect:            3
+    value:           0x0000000000000030
+  - name:            ltmp3
+    type:            N_SECT
+    sect:            4
+    value:           0x0000000000000050
+global-symbols:  
+  - name:            __Z3fooi
+    type:            N_SECT
+    scope:           [ N_EXT ]
+    sect:            1
+    value:           0x0000000000000000
+undefined-symbols: 
+  - name:            _puts
+    type:            N_UNDF
+    scope:           [ N_EXT ]
+    value:           0x0000000000000000
+page-size:       0x00000000
+...




More information about the llvm-commits mailing list