Bug 20090 - [Fix] clang fail on LTO phase with BFD linker (+patch)
Summary: [Fix] clang fail on LTO phase with BFD linker (+patch)
Status: RESOLVED DUPLICATE of bug 20070
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.27
: P2 normal
Target Milestone: 2.27
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-13 11:14 UTC by Igor Venevtsev
Modified: 2016-05-13 12:02 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
reproducer (579 bytes, application/x-compressed)
2016-05-13 11:14 UTC, Igor Venevtsev
Details
PATCH (687 bytes, patch)
2016-05-13 11:15 UTC, Igor Venevtsev
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Venevtsev 2016-05-13 11:14:20 UTC
Created attachment 9256 [details]
reproducer

Reproducer is just trying to make an executable using one object and two archives with LTO info inside. First arch, live.a, contains live() function which is called from main(). The second one, dead.a, contains never called function dead(). During linking phase, clang comply on 'Unexpected resolution' and terminates with UNREACHABLE.

bash-4.3$ make

[...skip...]

Unexpected resolution
UNREACHABLE executed at /users/ivvenevt/llvm/llvm/tools/gold/gold-plugin.cpp:759!
clang-3.9: error: unable to execute command: Aborted (core dumped)
clang-3.9: error: linker command failed due to signal (use -v to see invocation)
Makefile:26: recipe for target 'test' failed

The reason is wrong resolution reported by ld.bfd for dead (never included to link) symbols. When LTO plugin asks for dead symbol resolution via get_symbols() callback, ld.bfd is trying to find BFD entry for this symbol. But there is no BFD entry for dead symbol despite the symbol itself is defined (sym.def != LDPK_UNDEF). As a result ld.bfd set resolution to LDPR_UNKNOWN and confuses the LLVMgold.so plugin. Opposite, GOLD linker reports LDPR_PREEMPTED_REG for dead symbols. (gold/plugin.cc:959)

Please find reproducer and patch in attachments.

To run reproducer you should specify locations for clang and bfd.ld via CLANG_BIN and BINUTILS_BIN vars.

Thanks, Igor
Comment 1 Igor Venevtsev 2016-05-13 11:15:15 UTC
Created attachment 9257 [details]
PATCH
Comment 2 H.J. Lu 2016-05-13 12:02:56 UTC
Dup.

*** This bug has been marked as a duplicate of bug 20070 ***