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

[RemoveDIs] Load into new debug info format by default in llvm-link #86274

Merged
merged 2 commits into from
Mar 25, 2024

Conversation

OCHyams
Copy link
Contributor

@OCHyams OCHyams commented Mar 22, 2024

Directly load all bitcode into the new debug info format in llvm-link. This means that new-mode bitcode no longer round-trips back to old-mode after parsing, and that old-mode bitcode gets auto-upgraded to new-mode debug info (which is the current in-memory default in LLVM).

@OCHyams OCHyams requested review from jryans and SLTozer March 22, 2024 12:31
Copy link
Member

@jryans jryans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems sensible to do this for llvm-link, thanks!

@@ -479,6 +480,9 @@ int main(int argc, char **argv) {

cl::HideUnrelatedOptions({&LinkCategory, &getColorCategory()});
cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
// Load bitcode into the new debug info format by default.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultra-nit: Maybe add a blank above this to separate it from the "default" parsing step.

@OCHyams OCHyams merged commit 8263a88 into llvm:main Mar 25, 2024
3 of 4 checks passed
@OCHyams OCHyams deleted the removedis-llvm-link branch March 25, 2024 09:32
estewart08 added a commit to ROCm/flang that referenced this pull request Mar 25, 2024
…lvm-link step

Set load-bitcode-into-experimental-debuginfo-iterators=false.
Fixes flang compilation crash from
llvm/llvm-project#86274.
estewart08 added a commit to ROCm/flang that referenced this pull request Mar 25, 2024
…lvm-link step

Set load-bitcode-into-experimental-debuginfo-iterators=false.
Fixes flang compilation crash from
llvm/llvm-project#86274.
@jsji
Copy link
Member

jsji commented Apr 2, 2024

Looks like this might cause assert failure for some scenarios.

Simple reproducer on x86 Linux:

# Build clang/llvm with -DLLVM_ENABLE_ASSERTIONS=ON

$cat t.cpp
int __attribute__((always_inline)) func(int x) {
   return x * 2;
 }
$ clang++ -g -c -emit-llvm t.cpp
$ llvm-link t.bc
Unknown function for CallBase upgrade.
UNREACHABLE executed at .../llvm-project/llvm/lib/IR/AutoUpgrade.cpp:4268!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: bin/llvm-link t.bc
 #0 0x00007f06b58af4b1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) .../llvm-project/build/bin/../lib/libLLVMSupport.so.19.0git+0x1cd4b1)
 #1 0x00007f06b58aca14 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f06b51f8db0 __restore_rt (/lib64/libc.so.6+0x59db0)
 #3 0x00007f06b524542c __pthread_kill_implementation (/lib64/libc.so.6+0xa642c)
 #4 0x00007f06b51f8d06 gsignal (/lib64/libc.so.6+0x59d06)
 #5 0x00007f06b51cb7d3 abort (/lib64/libc.so.6+0x2c7d3)
 #6 0x00007f06b57ceada (.../llvm-project/build/bin/../lib/libLLVMSupport.so.19.0git+0xecada)
 #7 0x00007f06b5ae5126 llvm::UpgradeIntrinsicCall(llvm::CallBase*, llvm::Function*) (.../llvm-project/build/bin/../lib/libLLVMCore.so.19.0git+0x13c126)
 #8 0x00007f06b5fb9e38 (anonymous namespace)::BitcodeReader::materialize(llvm::GlobalValue*) BitcodeReader.cpp:0:0
 #9 0x00007f06b5c91de7 llvm::Module::materialize(llvm::GlobalValue*) (.../llvm-project/build/bin/../lib/libLLVMCore.so.19.0git+0x2e8de7)
#10 0x00007f06b5bf6d81 llvm::GlobalValue::materialize() (.../llvm-project/build/bin/../lib/libLLVMCore.so.19.0git+0x24dd81)
#11 0x00007f06b65c0330 (anonymous namespace)::IRLinker::materialize(llvm::Value*, bool) IRMover.cpp:0:0
#12 0x00007f06b64b35ad (anonymous namespace)::Mapper::mapValue(llvm::Value const*) ValueMapper.cpp:0:0
#13 0x00007f06b64b8989 llvm::ValueMapper::mapValue(llvm::Value const&) (.../llvm-project/build/bin/../lib/libLLVMTransformUtils.so.19.0git+0x2c2989)
#14 0x00007f06b65c7416 llvm::IRMover::move(std::unique_ptr<llvm::Module, std::default_delete<llvm::Module>>, llvm::ArrayRef<llvm::GlobalValue*>, llvm::unique_function<void (llvm::GlobalValue&, std::function<void (llvm::GlobalValue&)>)>, bool) (.../llvm-project/build/bin/../lib/libLLVMLinker.so.19.0git+0x15416)
#15 0x00007f06b65d1392 (anonymous namespace)::ModuleLinker::run() LinkModules.cpp:0:0
#16 0x00007f06b65d177c llvm::Linker::linkInModule(std::unique_ptr<llvm::Module, std::default_delete<llvm::Module>>, unsigned int, std::function<void (llvm::Module&, llvm::StringSet<llvm::MallocAllocator> const&)>) (.../llvm-project/build/bin/../lib/libLLVMLinker.so.19.0git+0x1f77c)
#17 0x000000000040df9d linkFiles(char const*, llvm::LLVMContext&, llvm::Linker&, llvm::cl::list<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, llvm::cl::parser<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, unsigned int) llvm-link.cpp:0:0
#18 0x000000000040659b main (bin/llvm-link+0x40659b)
#19 0x00007f06b51e3e50 __libc_start_call_main (/lib64/libc.so.6+0x44e50)
#20 0x00007f06b51e3efc __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x44efc)
#21 0x0000000000407ae5 _start (bin/llvm-link+0x407ae5)
Aborted (core dumped)

@SLTozer
Copy link
Contributor

SLTozer commented Apr 3, 2024

Looks like this might cause assert failure for some scenarios.

I think I see the issue, I think it's incidentally fixed by a PR that I have open - the rough outline is that the bitcode loading process for the new debug info format can hit this assertion if we lazy load, and change the debug info format of the module in between parsing the module and materializing its functions; in more detail:

  • We tell the autoupgrader during the parse step that all debug intrinsics should be upgraded to debug records because we desire the new format.
  • Then, we change the module to be in the old debug info format (IRMover.cpp:1552).
  • Then, we materialize the function, converting the inserted debug records to debug intrinsics due to the parent module using the old debug info format.
  • Then, we try to upgrade intrinsics, at which point the module is still in the old debug info format, but we have already requested that debug intrinsics be upgraded; we thus fall into the llvm_unreachable here:
    } else if (IsDbg && CI->getModule()->IsNewDbgInfoFormat) {
      upgradeDbgIntrinsicToDbgRecord(Name, CI);
    } else {
      llvm_unreachable("Unknown function for CallBase upgrade.");
    }

A simple immediate fix for this would be to avoid catching IsNewDbgInfoFormat in the clause above, but instead fold it as a separate check:

    } else if (IsDbg) {
      if (CI->getModule()->IsNewDbgInfoFormat)
        upgradeDbgIntrinsicToDbgRecord(Name, CI);
    } else {
      llvm_unreachable("Unknown function for CallBase upgrade.");
    }

It's not an ideal solution, but it only needs to be temporary since a patch that fixes it is already ready.

@OCHyams
Copy link
Contributor Author

OCHyams commented Apr 3, 2024

Thanks for the report and analysis.

I think I see the issue, I think it's incidentally fixed by a PR that I have open

Do you have a link to it?

A simple immediate fix for this would be to avoid...

We could also revert this till your patch lands if it fixes the issue.

SLTozer added a commit to SLTozer/llvm-project that referenced this pull request Apr 3, 2024
…at modules

Fixes issue noted at: llvm#86274

When loading bitcode lazily, we may request debug intrinsics be upgraded to
debug records during the module parsing phase; later on we perform this
upgrade when materializing the module functions. If we change the module's
debug info format between parsing and materializing however, then the
requested upgrade is no longer correct and leads to an assertion. This patch
fixes the issue by adding an extra check in the autoupgrader to see if the
upgrade is no longer suitable, and either exit-out or fall back to the
correct intrinsic->intrinsic upgrade if one is required.

Adding this check in the autoupgrader is technically not optimal, since we
could run the check a single time in a higher up call, but there's no way
(that I can see) to do so without leaking through abstractions and making
the bitcode/linking/materializing steps more complicated and brittle, and
the check isn't particularly expensive.
@SLTozer
Copy link
Contributor

SLTozer commented Apr 3, 2024

My mistake, my existing patch doesn't fix the issue (the reproducer needed ToT clang as well as llvm-link), but the fix is straightforward enough - I've added one here, which has a slight overlap with my other review (which adds a new flag). @jsji does the linked patch fix all your crashes if applied?

jsji pushed a commit to intel/llvm that referenced this pull request Apr 3, 2024
…at modules

Fixes issue noted at: llvm/llvm-project#86274

When loading bitcode lazily, we may request debug intrinsics be upgraded to
debug records during the module parsing phase; later on we perform this
upgrade when materializing the module functions. If we change the module's
debug info format between parsing and materializing however, then the
requested upgrade is no longer correct and leads to an assertion. This patch
fixes the issue by adding an extra check in the autoupgrader to see if the
upgrade is no longer suitable, and either exit-out or fall back to the
correct intrinsic->intrinsic upgrade if one is required.

Adding this check in the autoupgrader is technically not optimal, since we
could run the check a single time in a higher up call, but there's no way
(that I can see) to do so without leaking through abstractions and making
the bitcode/linking/materializing steps more complicated and brittle, and
the check isn't particularly expensive.
@jsji
Copy link
Member

jsji commented Apr 3, 2024

My mistake, my existing patch doesn't fix the issue (the reproducer needed ToT clang as well as llvm-link), but the fix is straightforward enough - I've added one here, which has a slight overlap with my other review (which adds a new flag). @jsji does the linked patch fix all your crashes if applied?

Yes, looks like #87494 fixed the crashes. Thanks.

SLTozer added a commit that referenced this pull request Apr 4, 2024
…les (#87494)

Fixes issue noted at: #86274

When loading bitcode lazily, we may request debug intrinsics be upgraded
to debug records during the module parsing phase; later on we perform
this upgrade when materializing the module functions. If we change the
module's debug info format between parsing and materializing however,
then the requested upgrade is no longer correct and leads to an
assertion. This patch fixes the issue by adding an extra check in the
autoupgrader to see if the upgrade is no longer suitable, and either
exit-out or fall back to the correct intrinsic->intrinsic upgrade if one
is required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants