[lld] r256974 - Fix MachO arm64 delta32ToGOT reloc encoding in -r.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 6 12:53:19 PST 2016


Author: pete
Date: Wed Jan  6 14:53:19 2016
New Revision: 256974

URL: http://llvm.org/viewvc/llvm-project?rev=256974&view=rev
Log:
Fix MachO arm64 delta32ToGOT reloc encoding in -r.

The fixup content we encode here should be the offset from the
fixup location back to the last nonlocal label.  We were only encoding
the address of the fixup, and not taking in to account the base address
of the atom we are in.

Updated the test case here to have a text section which will come before
the data section where the relocation lives.  .data being at offset 0 had
previously been hiding this bug.

Modified:
    lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp
    lld/trunk/test/mach-o/parse-data-relocs-arm64.yaml

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=256974&r1=256973&r2=256974&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp Wed Jan  6 14:53:19 2016
@@ -697,7 +697,7 @@ void ArchHandler_arm64::applyFixupReloca
     *loc64 = 0;
     return;
   case delta32ToGOT:
-    *loc32 = -fixupAddress;
+    *loc32 = inAtomAddress - fixupAddress;
     return;
   case addOffset12:
     llvm_unreachable("lazy reference kind implies GOT pass was run");

Modified: lld/trunk/test/mach-o/parse-data-relocs-arm64.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/parse-data-relocs-arm64.yaml?rev=256974&r1=256973&r2=256974&view=diff
==============================================================================
--- lld/trunk/test/mach-o/parse-data-relocs-arm64.yaml (original)
+++ lld/trunk/test/mach-o/parse-data-relocs-arm64.yaml Wed Jan  6 14:53:19 2016
@@ -16,11 +16,18 @@ arch:            arm64
 file-type:       MH_OBJECT
 flags:           [ MH_SUBSECTIONS_VIA_SYMBOLS ]
 sections:
+  - segment:         __TEXT
+    section:         __text
+    type:            S_REGULAR
+    attributes:      [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
+    alignment:       4
+    address:         0x0000000000000000
+    content:         [ 0xC0, 0x03, 0x5F, 0xD6 ]
   - segment:         __DATA
     section:         __data
     type:            S_REGULAR
     attributes:      [  ]
-    address:         0x0000000000000000
+    address:         0x0000000000000004
     content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -28,7 +35,7 @@ sections:
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                        0xDC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
-                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                       0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0xC0, 0xFF, 0xFF, 0xFF, 0xBE, 0xFF, 0xFF, 0xFF,
                        0xB0, 0xFF, 0xFF, 0xFF ]
@@ -38,107 +45,114 @@ sections:
         length:          2
         pc-rel:          true
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x0000004C
         type:            ARM64_RELOC_SUBTRACTOR
         length:          2
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x0000004C
         type:            ARM64_RELOC_UNSIGNED
         length:          2
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x00000048
         type:            ARM64_RELOC_SUBTRACTOR
         length:          2
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x00000048
         type:            ARM64_RELOC_UNSIGNED
         length:          2
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x00000040
         type:            ARM64_RELOC_UNSIGNED
         length:          3
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x00000038
         type:            ARM64_RELOC_UNSIGNED
         length:          3
         pc-rel:          false
         extern:          false
-        symbol:          1
+        symbol:          2
       - offset:          0x00000030
         type:            ARM64_RELOC_SUBTRACTOR
         length:          3
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x00000030
         type:            ARM64_RELOC_UNSIGNED
         length:          3
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x00000028
         type:            ARM64_RELOC_SUBTRACTOR
         length:          3
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x00000028
         type:            ARM64_RELOC_UNSIGNED
         length:          3
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x00000020
         type:            ARM64_RELOC_SUBTRACTOR
         length:          3
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x00000020
         type:            ARM64_RELOC_UNSIGNED
         length:          3
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x00000018
         type:            ARM64_RELOC_POINTER_TO_GOT
         length:          3
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x00000010
         type:            ARM64_RELOC_UNSIGNED
         length:          3
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
       - offset:          0x00000008
         type:            ARM64_RELOC_UNSIGNED
         length:          3
         pc-rel:          false
         extern:          true
-        symbol:          1
+        symbol:          2
 local-symbols:
   - name:            _v1
     type:            N_SECT
+    sect:            2
+    value:           0x000000000000000C
+global-symbols:
+  - name:            _bar
+    type:            N_SECT
+    scope:           [ N_EXT ]
     sect:            1
-    value:           0x0000000000000008
+    value:           0x0000000000000000
 undefined-symbols:
   - name:            _foo
     type:            N_UNDF
     scope:           [ N_EXT ]
     value:           0x0000000000000000
+page-size:       0x00000000
 ...
 
 # CHECK: defined-atoms:
@@ -151,9 +165,9 @@ undefined-symbols:
 # CHECK:                        00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00,
 # CHECK:                        00, 00, 00, 00, 00, 00, 00, 00, E0, FF, FF, FF,
 # CHECK:                        FF, FF, FF, FF, DC, FF, FF, FF, FF, FF, FF, FF,
-# CHECK:                        00, 00, 00, 00, 00, 00, 00, 00, 04, 00, 00, 00,
+# CHECK:                        {{..}}, {{..}}, 00, 00, 00, 00, 00, 00, 04, 00, 00, 00,
 # CHECK:                        00, 00, 00, 00, C0, FF, FF, FF, BE, FF, FF, FF,
-# CHECK:                        B0, FF, FF, FF ]
+# CHECK:                        {{B0|B8}}, {{..}}, FF, FF ]
 # CHECK:     references:
 # CHECK:       - kind:            pointer64
 # CHECK:         offset:          0
@@ -199,11 +213,19 @@ undefined-symbols:
 # CHECK:         offset:          72
 # CHECK:         target:          _foo
 # CHECK-NOT:     addend:
+# CHECK:  - name:            _bar
+# CHECK:    scope:           global
+# CHECK:    content:         [ C0, 03, 5F, D6 ]
+# CHECK:    alignment:       4
 # CHECK: undefined-atoms:
 # CHECK:   - name:            _foo
 
-
-
+# .subsections_via_symbols
+# .text
+# .globl_foo
+# .align2
+# _foo:
+# ret
 #  .data
 #Lanon:
 #  .quad     0




More information about the llvm-commits mailing list