Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ld64.lld.darwinnew crashes linking __DWARF,__debug_ranges section #47736

Closed
tschuett opened this issue Dec 4, 2020 · 12 comments
Closed

ld64.lld.darwinnew crashes linking __DWARF,__debug_ranges section #47736

tschuett opened this issue Dec 4, 2020 · 12 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla lld:MachO

Comments

@tschuett
Copy link
Member

tschuett commented Dec 4, 2020

Bugzilla Link 48392
Resolution FIXED
Resolved on Dec 10, 2020 16:18
Version unspecified
OS MacOS X
CC @int3,@nico,@tschuett
Fixed by commit(s) rG863f7a745e6ba5b9aebca82eeba1a2fb1db53e20

Extended Description

PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: /Users/xxx/modules/clang/git/bin/ld64.lld.darwinnew -demangle -dynamic -arch x86_64 -platform_version macos 11.0.0 11.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o btm -L/Users/xxx/modules/clang/git/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/ lib/Support/ErrorHandling.o lib/Support/MemAlloc.o lib/Support/SmallVector.o lib/Utilities/util.o lib/Checker/checker.o lib/Transactions/GlobalTransaction.o lib/main.o -lc++ -lSystem
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
0 ld64.lld.darwinnew 0x00000001047b6977 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1 ld64.lld.darwinnew 0x00000001047b576a llvm::sys::RunSignalHandlers() + 250
2 ld64.lld.darwinnew 0x00000001047b71d6 SignalHandler(int) + 262
3 libsystem_platform.dylib 0x00007fff20374d7d _sigtramp + 29
4 libsystem_platform.dylib 0x4a8aa596003452d8 _sigtramp + 5371146835525961080
5 ld64.lld.darwinnew 0x0000000104a96c44 unsigned int std::__1::__sort3<lld::macho::RebaseSection::finalizeContents()::$_0&, lld::macho::Location*>(lld::macho::Location*, lld::macho::Location*, lld::macho::Location*, lld::macho::RebaseSection::finalizeContents()::$_0&) + 52
6 ld64.lld.darwinnew 0x0000000104a96eb3 unsigned int std::__1::__sort4<lld::macho::RebaseSection::finalizeContents()::$_0&, lld::macho::Location*>(lld::macho::Location*, lld::macho::Location*, lld::macho::Location*, lld::macho::Location*, lld::macho::RebaseSection::finalizeContents()::$_0&) + 35
7 ld64.lld.darwinnew 0x0000000104a97077 unsigned int std::__1::__sort5<lld::macho::RebaseSection::finalizeContents()::$_0&, lld::macho::Location*>(lld::macho::Location*, lld::macho::Location*, lld::macho::Location*, lld::macho::Location*, lld::macho::Location*, lld::macho::RebaseSection::finalizeContents()::$_0&) + 39
8 ld64.lld.darwinnew 0x0000000104a9634d void std::__1::__sort<lld::macho::RebaseSection::finalizeContents()::$_0&, lld::macho::Location*>(lld::macho::Location*, lld::macho::Location*, lld::macho::RebaseSection::finalizeContents()::$_0&) + 157
9 ld64.lld.darwinnew 0x0000000104a90b64 lld::macho::RebaseSection::finalizeContents() + 180
10 ld64.lld.darwinnew 0x0000000104a9e68e lld::macho::writeResult() + 7358
11 ld64.lld.darwinnew 0x0000000104a7bdab lld::macho::link(llvm::ArrayRef<char const*>, bool, llvm::raw_ostream&, llvm::raw_ostream&) + 15291
12 ld64.lld.darwinnew 0x00000001046a522b lldMain(int, char const**, llvm::raw_ostream&, llvm::raw_ostream&, bool) + 1163
13 ld64.lld.darwinnew 0x00000001046a4c65 main + 245
14 libdyld.dylib 0x00007fff2034b631 start + 1
clang-12: error: unable to execute command: Segmentation fault: 11
clang-12: error: linker command failed due to signal (use -v to see invocation)
make: *** [btm] Error 254

@tschuett
Copy link
Member Author

tschuett commented Dec 4, 2020

assigned to @int3

@tschuett
Copy link
Member Author

tschuett commented Dec 4, 2020

f69936f

@tschuett
Copy link
Member Author

tschuett commented Dec 4, 2020

the crash dump

@tschuett
Copy link
Member Author

tschuett commented Dec 4, 2020

lldb stack trace

@tschuett
Copy link
Member Author

tschuett commented Dec 6, 2020

lldb2

@nico
Copy link
Contributor

nico commented Dec 7, 2020

If you set LLD_REPRODUCE=foo.tar or pass --reproduce=foo.tar to lld, it'll create an archive you can upload that lets us reproduce the crash.

@tschuett
Copy link
Member Author

tschuett commented Dec 7, 2020

reproducer

@nico
Copy link
Contributor

nico commented Dec 8, 2020

Symbolized stack:

#​0 0x00000000026a7610 in lld::macho::InputSection::getVA at ../../lld/MachO/InputSection.cpp:29
#​1 0x00000000026acdf1 in lld::macho::Location::getVA at ../../lld/MachO/SyntheticSections.cpp:99
#​2 0x00000000026b118a in lld::macho::RebaseSection::finalizeContents()::$_0::operator() const at ../../lld/MachO/SyntheticSections.cpp:168
#​3 0x00000000026b0c52 in __gnu_cxx::__ops::_Iter_comp_iter::operator() at /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/predefined_ops.h:156
#​4 0x00000000026b11ec in std::__move_median_to_first at /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_algo.h:82
#​5 0x00000000026b0976 in std::__unguarded_partition_pivot at /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_algo.h:1924
#​6 0x00000000026b078c in std::__introsort_loop at /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_algo.h:1958
#​7 0x00000000026b0699 in std::__sort at /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_algo.h:1974
#​8 0x00000000026b0622 in std::sort at /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_algo.h:4892
#​9 0x00000000026b05dd in llvm::sort at ../../llvm/include/llvm/ADT/STLExtras.h:1464
#​10 0x00000000026ad093 in llvm::sort at ../../llvm/include/llvm/ADT/STLExtras.h:1469
#​11 0x00000000026acf00 in lld::macho::RebaseSection::finalizeContents at ../../lld/MachO/SyntheticSections.cpp:167
#​12 0x00000000026ce0b0 in (anonymous namespace)::Writer::run at ../../lld/MachO/Writer.cpp:712
#​13 0x00000000026cde5a in lld::macho::writeResult () at ../../lld/MachO/Writer.cpp:735
#​14 0x000000000267b3ac in lld::macho::link at ../../lld/MachO/Driver.cpp:826
#​15 0x00000000021e4cb1 in lldMain at ../../lld/tools/lld/lld.cpp:159
#​16 0x00000000021e48e7 in main at ../../lld/tools/lld/lld.cpp:211

So we're trying to sort the synthetic section locations and then hit an InputSection without parent. It's a debug section:

(gdb) p this->name
$7 = {static npos = 18446744073709551615, Data = 0x7ffff5a7e388 "__debug_ranges", Length = 14}
(gdb) p this->segname
$8 = {static npos = 18446744073709551615, Data = 0x7ffff5a7e398 "__DWARF", Length = 7}

@nico
Copy link
Contributor

nico commented Dec 8, 2020

Here's a small stand-alone repro:

$ cat test.cc
struct A {
A() : a(0) {}
int a;
} a;

$ out/gn/bin/clang --target=x86_64-apple-macos test.cc -g -c

$ out/gn/bin/ld64.lld.darwinnew -dylib test.o
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: out/gn/bin/ld64.lld.darwinnew -dylib test.o
...

@nico
Copy link
Contributor

nico commented Dec 8, 2020

This assert finds the parent-less InputSection Location that we later crash on:

$ git diff
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index fc4e36c9eb5..d2b5c9029bf 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -394,8 +394,10 @@ void Writer::scanRelocations() {
target->prepareSymbolRelocation(s, isec, r);
} else {
assert(r.referent.is<InputSection *>());

  •    if (!r.pcrel)
    
  •    if (!r.pcrel) {
    
  •      assert(isec->parent);
         in.rebase->addEntry(isec, r.offset);
    
  •    }
     }
    
    }
    }

It's hit here (with the repro in comment 8), and adding an && isec->parent to the other if makes the crash go away. However it also breaks MachO/x86-64-reloc-unsigned.s

Should we link __DWARF,__debug_ranges at all or should we just refer to the .o files like with other debug info? (I don't know the debug info handling of the linker well.)

@tschuett
Copy link
Member Author

tschuett commented Dec 8, 2020

I used the open-source clang. The most interesting flags are probably:
-O3 -g0 -glldb

@int3
Copy link
Contributor

int3 commented Dec 8, 2020

Should we link __DWARF,__debug_ranges at all or should we just refer to the .o files like with other debug info?

We don't emit any debug info section, including __debug_ranges. The problem here is that the debug sections are filtered out late in the link process, after rebase/bind opcodes have been emitted for them. I think filtering them out during the parsing stage would be the best fix... I'll put up a diff for it later.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla lld:MachO
Projects
None yet
Development

No branches or pull requests

3 participants