[PATCH] D152831: [AArch64][MachO] Drop a 2015 ld64 workaround avoiding local relocations

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 13 09:48:18 PDT 2023


MaskRay created this revision.
MaskRay added reviewers: lhames, t.p.northover.
Herald added subscribers: pengfei, hiraditya, kristof.beyls.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Commit d6223a24718df3c30b67422c2eb6d0e93af9c4e8 introduced an ld64 workaround
that disables local relocations for many pointer-sized relocations (e.g.
relocations referencing __DATA,__literal*).

ld64 has been fixed long ago (2015). Drop this workaround so that the
behavior matches x86-64.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152831

Files:
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
  llvm/test/MC/MachO/AArch64/ld64-workaround.s
  llvm/test/MC/MachO/AArch64/mergeable.s


Index: llvm/test/MC/MachO/AArch64/mergeable.s
===================================================================
--- llvm/test/MC/MachO/AArch64/mergeable.s
+++ llvm/test/MC/MachO/AArch64/mergeable.s
@@ -47,7 +47,7 @@
 // CHECK-NEXT:       PCRel: 0
 // CHECK-NEXT:       Length: 3
 // CHECK-NEXT:       Type: ARM64_RELOC_UNSIGNED (0)
-// CHECK-NEXT:       Symbol: L0
+// CHECK-NEXT:       Section: __literal4
 // CHECK-NEXT:     }
 // CHECK-NEXT:   }
 // CHECK-NEXT: ]
Index: llvm/test/MC/MachO/AArch64/ld64-workaround.s
===================================================================
--- llvm/test/MC/MachO/AArch64/ld64-workaround.s
+++ llvm/test/MC/MachO/AArch64/ld64-workaround.s
@@ -1,8 +1,8 @@
 ; RUN: llvm-mc -triple arm64-apple-darwin10 %s -filetype=obj -o - | llvm-readobj -r --expand-relocs - | FileCheck %s
 
-; Test that we produce an external relocation. This is a known and temporary bug
-; in ld64, where it mishandles pointer-sized internal relocations. We should be
-; able to remove this entirely soon.
+/// To work around an ld64 arm64 bug before 2015, we used to disable local
+/// relocations for many pointer-sized relocations. Test that the workaround
+/// is dropped and the behavior now matches x86-64.
 
 // CHECK:      Relocations [
 // CHECK-NEXT:   Section __data {
@@ -11,21 +11,21 @@
 // CHECK-NEXT:       PCRel: 0
 // CHECK-NEXT:       Length: 3
 // CHECK-NEXT:       Type: ARM64_RELOC_UNSIGNED (0)
-// CHECK-NEXT:       Symbol: Llit16
+// CHECK-NEXT:       Section: __literal16
 // CHECK-NEXT:     }
 // CHECK-NEXT:     Relocation {
 // CHECK-NEXT:       Offset: 0x10
 // CHECK-NEXT:       PCRel: 0
 // CHECK-NEXT:       Length: 3
 // CHECK-NEXT:       Type: ARM64_RELOC_UNSIGNED (0)
-// CHECK-NEXT:       Symbol: Llit8
+// CHECK-NEXT:       Section: __literal8
 // CHECK-NEXT:     }
 // CHECK-NEXT:     Relocation {
 // CHECK-NEXT:       Offset: 0x8
 // CHECK-NEXT:       PCRel: 0
 // CHECK-NEXT:       Length: 3
 // CHECK-NEXT:       Type: ARM64_RELOC_UNSIGNED (0)
-// CHECK-NEXT:       Symbol: Llit4
+// CHECK-NEXT:       Section: __literal4
 // CHECK-NEXT:     }
 // CHECK-NEXT:     Relocation {
 // CHECK-NEXT:       Offset: 0x0
Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
===================================================================
--- llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
+++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
@@ -139,13 +139,11 @@
     return false;
 
   if (RefSec.getSegmentName() == "__DATA" &&
-      RefSec.getName() == "__objc_classrefs")
+      (RefSec.getName() == "__cfstring" ||
+       RefSec.getName() == "__objc_classrefs"))
     return false;
 
-  // FIXME: ld64 currently handles internal pointer-sized relocations
-  // incorrectly (applying the addend twice). We should be able to return true
-  // unconditionally by this point when that's fixed.
-  return false;
+  return true;
 }
 
 void AArch64MachObjectWriter::recordRelocation(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152831.530949.patch
Type: text/x-patch
Size: 2991 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230613/d61181ca/attachment.bin>


More information about the llvm-commits mailing list