[lld] 3a8c6a3 - [lld-macho] Fix __objc_stubs ordering
Keith Smiley via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 13 13:24:46 PST 2022
Author: Keith Smiley
Date: 2022-12-13T13:23:27-08:00
New Revision: 3a8c6a3039afa064719a498a37428ded7874188f
URL: https://github.com/llvm/llvm-project/commit/3a8c6a3039afa064719a498a37428ded7874188f
DIFF: https://github.com/llvm/llvm-project/commit/3a8c6a3039afa064719a498a37428ded7874188f.diff
LOG: [lld-macho] Fix __objc_stubs ordering
In the case of large binaries previously you could end up getting
relocation failures. This mirrors ld64's ordering of these sections. I'm
not sure this solves all cases but it should help in some.
Fixes https://github.com/llvm/llvm-project/issues/58298
Differential Revision: https://reviews.llvm.org/D139909
Added:
Modified:
lld/MachO/OutputSegment.cpp
lld/test/MachO/x86-64-objc-stubs.s
Removed:
################################################################################
diff --git a/lld/MachO/OutputSegment.cpp b/lld/MachO/OutputSegment.cpp
index 3b28dfd306c38..a887bc4d515de 100644
--- a/lld/MachO/OutputSegment.cpp
+++ b/lld/MachO/OutputSegment.cpp
@@ -90,10 +90,11 @@ static int sectionOrder(OutputSection *osec) {
// Sections are uniquely identified by their segment + section name.
if (segname == segment_names::text) {
return StringSwitch<int>(osec->name)
- .Case(section_names::header, -5)
- .Case(section_names::text, -4)
- .Case(section_names::stubs, -3)
- .Case(section_names::stubHelper, -2)
+ .Case(section_names::header, -6)
+ .Case(section_names::text, -5)
+ .Case(section_names::stubs, -4)
+ .Case(section_names::stubHelper, -3)
+ .Case(section_names::objcStubs, -2)
.Case(section_names::initOffsets, -1)
.Case(section_names::unwindInfo, std::numeric_limits<int>::max() - 1)
.Case(section_names::ehFrame, std::numeric_limits<int>::max())
diff --git a/lld/test/MachO/x86-64-objc-stubs.s b/lld/test/MachO/x86-64-objc-stubs.s
index f29326939c7f6..5e8b9fb165f25 100644
--- a/lld/test/MachO/x86-64-objc-stubs.s
+++ b/lld/test/MachO/x86-64-objc-stubs.s
@@ -2,17 +2,35 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: %lld -arch x86_64 -lSystem -o %t.out %t.o
-# RUN: llvm-otool -vs __TEXT __objc_stubs %t.out | FileCheck %s
+# RUN: llvm-objdump --macho --section-headers %t.out > %t.txt
+# RUN: llvm-otool -vs __DATA __objc_selrefs %t.out >> %t.txt
+# RUN: llvm-otool -vs __TEXT __objc_stubs %t.out >> %t.txt
+# RUN: FileCheck %s < %t.txt
+
+# CHECK: Sections:
+# CHECK: __got {{[0-9a-f]*}} [[#%x, GOTSTART:]] DATA
+# CHECK: __objc_selrefs {{[0-9a-f]*}} [[#%x, SELSTART:]] DATA
+
+# CHECK: Contents of (__DATA,__objc_selrefs) section
+
+# CHECK-NEXT: {{[0-9a-f]*}} __TEXT:__objc_methname:foo
+# CHECK-NEXT: {{[0-9a-f]*}} __TEXT:__objc_methname:bar
+# CHECK-NEXT: [[#%x, FOOSELREF:]] __TEXT:__objc_methname:foo
+# CHECK-NEXT: [[#%x, LENGTHSELREF:]] __TEXT:__objc_methname:length
# CHECK: Contents of (__TEXT,__objc_stubs) section
# CHECK-NEXT: _objc_msgSend$foo:
-# CHECK-NEXT: 00000001000004b8 movq 0x1b51(%rip), %rsi
-# CHECK-NEXT: 00000001000004bf jmpq *0xb3b(%rip)
+# CHECK-NEXT: [[#%x, PC1:]]
+# CHECK-SAME: movq 0x[[#%x, FOOSELREF - PC1 - 7]](%rip), %rsi
+# CHECK-NEXT: [[#%x, PC2:]]
+# CHECK-SAME: jmpq *0x[[#%x, GOTSTART - PC2 - 6]](%rip)
# CHECK-NEXT: _objc_msgSend$length:
-# CHECK-NEXT: 00000001000004c5 movq 0x1b4c(%rip), %rsi
-# CHECK-NEXT: 00000001000004cc jmpq *0xb2e(%rip)
+# CHECK-NEXT: [[#%x, PC3:]]
+# CHECK-SAME: movq 0x[[#%x, LENGTHSELREF - PC3 - 7]](%rip), %rsi
+# CHECK-NEXT: [[#%x, PC4:]]
+# CHECK-SAME: jmpq *0x[[#%x, GOTSTART - PC4 - 6]](%rip)
# CHECK-EMPTY:
More information about the llvm-commits
mailing list