This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssembly] Fail if bitcode objects are pulled in after LTO
ClosedPublic

Authored by sbc100 on Dec 17 2019, 2:49 PM.

Details

Summary

This can happen if lto::LTO::getRuntimeLibcallSymbols doesn't return
an complete/accurate list of libcalls. In this case new bitcode
object can be linked in after LTO.

For example the WebAssembly backend currently calls:
setLibcallName(RTLIB::FPROUND_F32_F16, "__truncsfhf2");

But __truncsfhf2 is not part of getRuntimeLibcallSymbols so if
this symbol is generated during LTO the link will currently fail.

Without this change the linker crashes because the bitcode symbol
makes it all the way to the output phase.

See: https://bugs.llvm.org/show_bug.cgi?id=44353

Event Timeline

sbc100 created this revision.Dec 17 2019, 2:49 PM
sbc100 updated this revision to Diff 234396.Dec 17 2019, 2:51 PM
  • spelling
sbc100 added a reviewer: ruiu.Dec 17 2019, 2:51 PM

I think this problem could also effect other backend.. working on test case to verify if this is true.

dschuff added inline comments.Dec 17 2019, 3:39 PM
lld/wasm/InputFiles.cpp
546

This string is confusing. I think it's not really necessary; emscripten only had this problem because compiler-rt was incorrectly compiled as bitcode.

Actually it looks like we can handle this more gracefully, like ELF does:
https://reviews.llvm.org/D50017
https://reviews.llvm.org/D50475

ruiu added inline comments.Dec 17 2019, 6:27 PM
lld/wasm/InputFiles.cpp
544–546

For a single error call error only once.

I'm going abandon this change in favor of copying the code that already exists in COFF and ELF for handling this.

sbc100 planned changes to this revision.Jan 14 2020, 11:37 AM
sbc100 edited the summary of this revision. (Show Details)
sbc100 edited the summary of this revision. (Show Details)
sbc100 updated this revision to Diff 238059.Jan 14 2020, 11:40 AM
sbc100 marked 2 inline comments as done.
sbc100 edited the summary of this revision. (Show Details)
  • feedback

@ruiu, I tested the ELF linking I an believe it has the same problem. With ELF it looks like the effect is that bitcode symbols all end up with address 0 in the final binary. I think its better to fail at link time.. so we should probably port this change, or something like it to ELF.

Sadly its very hard to test this, since it requires knowledge of what the codegen is going to do, and finding a symbol that is not covered in the static libcall list returned by getRuntimeLibcallSymbols

sbc100 updated this revision to Diff 238887.Jan 17 2020, 2:03 PM
  • revert

@ruiu I'm curious what you think about this problem, and this approach to solving it.

Unit tests: pass. 61985 tests passed, 0 failed and 783 were skipped.

clang-tidy: unknown.

clang-format: pass.

Build artifacts: diff.json, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

sbc100 added a reviewer: pcc.Feb 6 2020, 9:54 AM

Adding @pcc, perhaps @ruiu is OOO?

This change is pretty uncontroversial, and prevents crash bugs that can occur when LTO introduces new symbols that themselves are stored in bitcode. I'm keen to land it to get feedback on if/when this ever happens in the wild.

sbc100 added a comment.EditedFeb 11 2020, 2:00 PM

@pcc or @ruiu could I get your approval?

dschuff accepted this revision.Feb 11 2020, 3:36 PM

FWIW this LGTM, especially if this is the same approach used in the other backends.

This revision is now accepted and ready to land.Feb 11 2020, 3:36 PM
This revision was automatically updated to reflect the committed changes.