From 05fb769b72834c62de3ac2d282e4949e77996c60 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 29 Jun 2023 17:59:15 -0700 Subject: [PATCH] [AArch64][MachO] Drop a 2015 ld64 workaround avoiding local relocations 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. Reviewed By: pete Differential Revision: https://reviews.llvm.org/D152831 --- .../Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp | 8 +++----- llvm/test/MC/MachO/AArch64/ld64-workaround.s | 12 ++++++------ llvm/test/MC/MachO/AArch64/mergeable.s | 4 +--- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp index 012661e..04bd852 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp @@ -139,13 +139,11 @@ static bool canUseLocalRelocation(const MCSectionMachO &Section, 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( diff --git a/llvm/test/MC/MachO/AArch64/ld64-workaround.s b/llvm/test/MC/MachO/AArch64/ld64-workaround.s index 807580c..8e59b07 100644 --- a/llvm/test/MC/MachO/AArch64/ld64-workaround.s +++ b/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 diff --git a/llvm/test/MC/MachO/AArch64/mergeable.s b/llvm/test/MC/MachO/AArch64/mergeable.s index 8621b25..4aa2d01 100644 --- a/llvm/test/MC/MachO/AArch64/mergeable.s +++ b/llvm/test/MC/MachO/AArch64/mergeable.s @@ -1,6 +1,4 @@ // RUN: llvm-mc -triple aarch64-apple-darwin14 %s -filetype=obj -o - | llvm-readobj -r --expand-relocs - | FileCheck %s -// FIXME: the final relocation should be internal, but the linker doesn't -// currently handle the it correctly. // Test that we "S + K" produce a relocation with a symbol, but just S produces // a relocation with the section. @@ -47,7 +45,7 @@ L1: // 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: ] -- 2.7.4