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

BOLT triggers assert with mold's synthetic $plt symbol #58498

Closed
ishitatsuyuki opened this issue Oct 20, 2022 · 3 comments
Closed

BOLT triggers assert with mold's synthetic $plt symbol #58498

ishitatsuyuki opened this issue Oct 20, 2022 · 3 comments
Labels
BOLT crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@ishitatsuyuki
Copy link
Contributor

ishitatsuyuki commented Oct 20, 2022

We're trying out BOLT compatibility at rui314/mold#789. During testing we discovered the following assert:

llvm-bolt: /home/ishitatsuyuki/llvm-project/bolt/lib/Core/BinaryContext.cpp:753: llvm::bolt::BinaryFunction *llvm::bolt::BinaryContext::createBinaryFunction(const std::string &, llvm::bolt::BinarySection &, uint64_t, uint64_t, uint64_t, uint16_t): Assertion `Result.second == true && "unexpected duplicate function"' failed.
 #0 0x000055839b75737a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/ishitatsuyuki/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:11
 #1 0x000055839b75752b PrintStackTraceSignalHandler(void*) /home/ishitatsuyuki/llvm-project/llvm/lib/Support/Unix/Signals.inc:636:1
 #2 0x000055839b755b76 llvm::sys::RunSignalHandlers() /home/ishitatsuyuki/llvm-project/llvm/lib/Support/Signals.cpp:104:5
 #3 0x000055839b757c55 SignalHandler(int) /home/ishitatsuyuki/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007fded65a2520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007fded65f6a7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007fded65f6a7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #7 0x00007fded65f6a7c pthread_kill ./nptl/pthread_kill.c:89:10
 #8 0x00007fded65a2476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #9 0x00007fded65887f3 abort ./stdlib/abort.c:81:7
#10 0x00007fded658871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#11 0x00007fded6599e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#12 0x000055839d0e9105 llvm::bolt::BinaryContext::createBinaryFunction(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, llvm::bolt::BinarySection&, unsigned long, unsigned long, unsigned long, unsigned short) /home/ishitatsuyuki/llvm-project/bolt/lib/Core/BinaryContext.cpp:754:32
#13 0x000055839b872746 llvm::bolt::RewriteInstance::createPLTBinaryFunction(unsigned long, unsigned long, unsigned long) /home/ishitatsuyuki/llvm-project/bolt/lib/Rewrite/RewriteInstance.cpp:1268:6
#14 0x000055839b873002 llvm::bolt::RewriteInstance::disassemblePLTSectionX86(llvm::bolt::BinarySection&, unsigned long) /home/ishitatsuyuki/llvm-project/bolt/lib/Rewrite/RewriteInstance.cpp:1386:3
#15 0x000055839b873220 llvm::bolt::RewriteInstance::disassemblePLT()::$_9::operator()(llvm::bolt::BinarySection&, unsigned long) const /home/ishitatsuyuki/llvm-project/bolt/lib/Rewrite/RewriteInstance.cpp:1394:3
#16 0x000055839b871838 llvm::bolt::RewriteInstance::disassemblePLT() /home/ishitatsuyuki/llvm-project/bolt/lib/Rewrite/RewriteInstance.cpp:1401:5
#17 0x000055839b86c4dc llvm::bolt::RewriteInstance::discoverFileObjects() /home/ishitatsuyuki/llvm-project/bolt/lib/Rewrite/RewriteInstance.cpp:1173:3
#18 0x000055839b868952 llvm::bolt::RewriteInstance::run() /home/ishitatsuyuki/llvm-project/bolt/lib/Rewrite/RewriteInstance.cpp:720:3
#19 0x000055839ac9b76b main /home/ishitatsuyuki/llvm-project/bolt/tools/driver/llvm-bolt.cpp:244:17
#20 0x00007fded6589d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#21 0x00007fded6589e40 call_init ./csu/../csu/libc-start.c:128:20
#22 0x00007fded6589e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#23 0x000055839ac9a6d5 _start (./build/bin/llvm-bolt+0x2326d5)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: ./build/bin/llvm-bolt -instrument /home/ishitatsuyuki/rust/obj/build/x86_64-unknown-linux-gnu/llvm/build/lib/libLLVM-15-rust-1.66.0-nightly.so -o /tmp/out.so

It looks like BOLT apparently doesn't like the synthetic PLT symbols mold creates (rui314/mold@a7f1e20 for implementation). The symbols are synthesized to ease looking at the disassembly, and looks like this:

    29: 0000000000001540     0 FUNC    LOCAL  DEFAULT   15 puts$plt
    30: 0000000000001550     0 FUNC    LOCAL  DEFAULT   16 __cxa_finalize$pltgot
    31: 0000000000002890     0 OBJECT  LOCAL  DEFAULT   23 __gmon_start__$got
    32: 0000000000002898     0 OBJECT  LOCAL  DEFAULT   23 _ITM_deregisterTMCloneTable$got
    33: 00000000000028a0     0 OBJECT  LOCAL  DEFAULT   23 _ITM_registerTMCloneTable$got
    34: 00000000000028a8     0 OBJECT  LOCAL  DEFAULT   23 __cxa_finalize$got
    35: 00000000000028b0     0 OBJECT  LOCAL  DEFAULT   23 __libc_start_main$got

To my understanding the mere existence of these local symbols should not prevent BOLT from functioning correctly, so we would like to get this fixed on BOLT side. However, if there's a legitimate reason that these symbols might affect BOLT's operation, we would be more than happy to consider other options to work around this in mold.

(cc @rui314)

@ishitatsuyuki
Copy link
Contributor Author

ishitatsuyuki commented Oct 20, 2022

emit-relocs.zip

Here's a small binary generated from mold's test suite that should reproduce the issue (you can run it to produce the binary by yourself too). Note that we have pending fixes for bugs on the mold side (rui314/mold#798, now merged) but this small scale test case is not affected by that.

@EugeneZelenko EugeneZelenko added BOLT crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Oct 20, 2022
@llvmbot
Copy link
Member

llvmbot commented Oct 20, 2022

@llvm/issue-subscribers-bolt

@maksfb
Copy link
Contributor

maksfb commented Oct 20, 2022

Thanks for letting know. I'll take a look.

@maksfb maksfb closed this as completed in 20204db Oct 25, 2022
sid8123 pushed a commit to sid8123/llvm-project that referenced this issue Oct 25, 2022
mold linker creates symbols for PLT entries and that caught BOLT by
surprise. Add the support for marked PLT entries.

Fixes: llvm#58498

Reviewed By: yota9

Differential Revision: https://reviews.llvm.org/D136655
virnarula pushed a commit to virnarula/llvm-project that referenced this issue Nov 2, 2022
mold linker creates symbols for PLT entries and that caught BOLT by
surprise. Add the support for marked PLT entries.

Fixes: llvm#58498

Reviewed By: yota9

Differential Revision: https://reviews.llvm.org/D136655
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BOLT crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

4 participants