[lld] 2c508cf - [lld/mac] Don't crash on absolute symbols in order files
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 23 08:33:40 PDT 2021
Author: Nico Weber
Date: 2021-07-23T11:33:23-04:00
New Revision: 2c508cf583f89f811d507b5cab2e869c11a0c0f1
URL: https://github.com/llvm/llvm-project/commit/2c508cf583f89f811d507b5cab2e869c11a0c0f1
DIFF: https://github.com/llvm/llvm-project/commit/2c508cf583f89f811d507b5cab2e869c11a0c0f1.diff
LOG: [lld/mac] Don't crash on absolute symbols in order files
Absolute symbols have a nullptr isec. buildInputSectionPriorities()
would defer isec, causing crashes. Ordering absolute symbols doesn't
make sense, so just ignore them. This seems to match ld64.
Differential Revision: https://reviews.llvm.org/D106628
Added:
Modified:
lld/MachO/Writer.cpp
lld/test/MachO/order-file.s
Removed:
################################################################################
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index 26c03f8787221..81b3491cdb9b7 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -847,6 +847,9 @@ static DenseMap<const InputSection *, size_t> buildInputSectionPriorities() {
return sectionPriorities;
auto addSym = [&](Defined &sym) {
+ if (sym.isAbsolute())
+ return;
+
auto it = config->priorities.find(sym.getName());
if (it == config->priorities.end())
return;
diff --git a/lld/test/MachO/order-file.s b/lld/test/MachO/order-file.s
index d0efefcb0feb0..e0ca735abdbff 100644
--- a/lld/test/MachO/order-file.s
+++ b/lld/test/MachO/order-file.s
@@ -2,6 +2,7 @@
# RUN: rm -rf %t; split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/abs.s -o %t/abs.o
# RUN: llvm-ar rcs %t/foo.a %t/foo.o
# FOO-FIRST: <_bar>:
@@ -101,6 +102,9 @@
# RUN: %lld -lSystem -o %t/test-alias %t/foo.o %t/test.o -order_file %t/ord-alias
# RUN: llvm-objdump -d %t/test-alias | FileCheck %s --check-prefix=FOO-FIRST
+## Absolute in symbols in order files make no sense. Just ignore them.
+# RUN: %lld -lSystem -dylib -o %t/test-abs %t/abs.o -order_file %t/ord-abs
+
#--- ord-1
-[Foo doFoo:andBar:] # just a comment
_main # another comment
@@ -160,6 +164,9 @@ _bar
_main
-[Foo doFoo:andBar:]
+#--- ord-abs
+_abs
+
#--- foo.s
.globl "-[Foo doFoo:andBar:]"
"-[Foo doFoo:andBar:]":
@@ -176,3 +183,6 @@ _main:
.section __DWARF,__debug_aranges,regular,debug
ltmp1:
.byte 0
+
+#--- abs.s
+_abs = 42
More information about the llvm-commits
mailing list