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

LLVM error with fat LTO and Rust 1.67.0 to Rust 1.69.0 on Windows #107781

Closed
michaelsproul opened this issue Feb 7, 2023 · 14 comments
Closed

LLVM error with fat LTO and Rust 1.67.0 to Rust 1.69.0 on Windows #107781

michaelsproul opened this issue Feb 7, 2023 · 14 comments
Assignees
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. O-windows Operating system: Windows

Comments

@michaelsproul
Copy link
Contributor

michaelsproul commented Feb 7, 2023

While compiling a large Rust binary on Windows I ran into an unusual LLVM error:

The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN8smallvec17SmallVec$LT$A$GT$4push17h42691c75a9092543E"(ptr noalias noundef nonnull align 8 dereferenceable(1328) %26, ptr noalias nocapture noundef nonnull dereferenceable(328) %10)
          to label %32 unwind label %172
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %47 unwind label %172
The unwind destination does not have an exception handling instruction!
  invoke void %95(ptr noundef align 1 %81, ptr noalias noundef nonnull readonly align 8 dereferenceable(128) %3)
          to label %96 unwind label %172
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN8smallvec17SmallVec$LT$A$GT$4push17h42691c75a9092543E"(ptr noalias noundef nonnull align 8 dereferenceable(1328) %99, ptr noalias nocapture noundef nonnull dereferenceable(328) %8)
          to label %105 unwind label %172
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN8smallvec17SmallVec$LT$A$GT$4push17h42691c75a9092543E"(ptr noalias noundef nonnull align 8 dereferenceable(1328) %99, ptr noalias nocapture noundef nonnull dereferenceable(328) %7)
          to label %109 unwind label %172
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN8smallvec17SmallVec$LT$A$GT$4push17h42691c75a9092543E"(ptr noalias noundef nonnull align 8 dereferenceable(1328) %143, ptr noalias nocapture noundef nonnull dereferenceable(328) %5)
          to label %149 unwind label %172
The unwind destination does not have an exception handling instruction!
  %156 = invoke fastcc noundef zeroext i1 @_ZN13futures_timer6native5delay5Delay6_reset17h39450cb69010166bE(ptr noalias noundef nonnull align 8 dereferenceable(8) %151, i64 %153, i32 noundef %155)
          to label %157 unwind label %172
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %167 unwind label %172
CleanupPadInst not the first non-PHI instruction in the block.
  %175 = cleanuppad within none []
in function _ZN94_$LT$libp2p_identify..handler..Handler$u20$as$u20$libp2p_swarm..handler..ConnectionHandler$GT$19on_connection_event17h5b45248c52481422E
LLVM ERROR: Broken function found, compilation aborted!
error: could not compile `lighthouse`
error: failed to compile `lighthouse v3.4.0-tree.2 (C:\Users\Michael\code\lighthouse\lighthouse)`, intermediate artifacts can be found at `C:\Users\Michael\code\lighthouse\target`

I don't know how to produce a more minimal example. My experimenting so far has found that it only happens if all of these conditions are met:

  1. Compiling on Windows. Unaffected: Linux and macOS, as far as I can tell.
  2. Compiling with version 1.67.0 or newer of Rust. I tested v1.65.0 and v1.66.1 and they were unaffected. The 1.68.0-beta.2 is affected, and so is nightly-2023-02-06.
  3. Using the following Cargo profile:
[profile.maxperf]
inherits = "release"
lto = "fat"
codegen-units = 1
incremental = false

The regular release profile does not trigger the error, even when all other conditions are met.


The version of the binary (Lighthouse) built doesn't seem to matter too much, tags v3.4.0 and v3.4.0-tree.2 both trigger the same error.

Lighthouse is open source and can be compiled locally (see build deps). It takes about 10 minutes on a fast machine to compile with the maxperf profile. The exact command I've been using to test is:

cargo +beta install --path lighthouse --force --locked --features modern,gnosis --profile maxperf

You can also see a failed compilation on our public CI here.

Meta

info for 1.67.0:

rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: x86_64-pc-windows-msvc
release: 1.67.0
LLVM version: 15.0.6

info for 1.66.1:

rustc 1.66.1 (90743e729 2023-01-10)
binary: rustc
commit-hash: 90743e7298aca107ddaa0c202a4d3604e29bfeb6
commit-date: 2023-01-10
host: x86_64-pc-windows-msvc
release: 1.66.1
LLVM version: 15.0.2

info for 1.68.0 beta:

rustc 1.68.0-beta.2 (10b73bf73 2023-02-01)
binary: rustc
commit-hash: 10b73bf73a6b770cd92ad8ff538173bc3298411c
commit-date: 2023-02-01
host: x86_64-pc-windows-msvc
release: 1.68.0-beta.2
LLVM version: 15.0.6

info for nightly:

rustc 1.69.0-nightly (e1eaa2d5d 2023-02-06)
binary: rustc
commit-hash: e1eaa2d5d4d1f5b7b89561a940718058d414e89c
commit-date: 2023-02-06
host: x86_64-pc-windows-msvc
release: 1.69.0-nightly
LLVM version: 15.0.7

MSVC info (not sure if this is relevant):

Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.28.29334
Error from 1.68.0-beta.2

The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN8smallvec17SmallVec$LT$A$GT$4push17h39287a406bf356daE"(ptr noalias noundef nonnull align 8 dereferenceable(1328) %26, ptr noalias nocapture noundef nonnull dereferenceable(328) %10)
          to label %32 unwind label %172
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %47 unwind label %172
The unwind destination does not have an exception handling instruction!
  invoke void %95(ptr noundef align 1 %81, ptr noalias noundef nonnull readonly align 8 dereferenceable(128) %3)
          to label %96 unwind label %172
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN8smallvec17SmallVec$LT$A$GT$4push17h39287a406bf356daE"(ptr noalias noundef nonnull align 8 dereferenceable(1328) %99, ptr noalias nocapture noundef nonnull dereferenceable(328) %8)
          to label %105 unwind label %172
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN8smallvec17SmallVec$LT$A$GT$4push17h39287a406bf356daE"(ptr noalias noundef nonnull align 8 dereferenceable(1328) %99, ptr noalias nocapture noundef nonnull dereferenceable(328) %7)
          to label %109 unwind label %172
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN8smallvec17SmallVec$LT$A$GT$4push17h39287a406bf356daE"(ptr noalias noundef nonnull align 8 dereferenceable(1328) %143, ptr noalias nocapture noundef nonnull dereferenceable(328) %5)
          to label %149 unwind label %172
The unwind destination does not have an exception handling instruction!
  %156 = invoke fastcc noundef zeroext i1 @_ZN13futures_timer6native5delay5Delay6_reset17h6935682b885c489fE(ptr noalias noundef nonnull align 8 dereferenceable(8) %151, i64 noundef %153, i32 noundef %155)
          to label %157 unwind label %172
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %167 unwind label %172
CleanupPadInst not the first non-PHI instruction in the block.
  %175 = cleanuppad within none []
in function _ZN94_$LT$libp2p_identify..handler..Handler$u20$as$u20$libp2p_swarm..handler..ConnectionHandler$GT$19on_connection_event17h8363995df26cfdb2E
LLVM ERROR: Broken function found, compilation aborted!
error: could not compile `lighthouse`
error: failed to compile `lighthouse v3.4.0 (C:\Users\Michael\code\lighthouse\lighthouse)`, intermediate artifacts can be found at `C:\Users\Michael\code\lighthouse\target`

Error from 1.69.0-nightly (2023-02-06)

The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN8smallvec17SmallVec$LT$A$GT$4push17h4f3823b6c507c1cfE"(ptr noalias noundef nonnull align 8 dereferenceable(1328) %26, ptr noalias nocapture noundef nonnull dereferenceable(328) %10)
          to label %32 unwind label %172
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %47 unwind label %172
The unwind destination does not have an exception handling instruction!
  invoke void %95(ptr noundef align 1 %81, ptr noalias noundef nonnull readonly align 8 dereferenceable(128) %3)
          to label %96 unwind label %172
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN8smallvec17SmallVec$LT$A$GT$4push17h4f3823b6c507c1cfE"(ptr noalias noundef nonnull align 8 dereferenceable(1328) %99, ptr noalias nocapture noundef nonnull dereferenceable(328) %8)
          to label %105 unwind label %172
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN8smallvec17SmallVec$LT$A$GT$4push17h4f3823b6c507c1cfE"(ptr noalias noundef nonnull align 8 dereferenceable(1328) %99, ptr noalias nocapture noundef nonnull dereferenceable(328) %7)
          to label %109 unwind label %172
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN8smallvec17SmallVec$LT$A$GT$4push17h4f3823b6c507c1cfE"(ptr noalias noundef nonnull align 8 dereferenceable(1328) %143, ptr noalias nocapture noundef nonnull dereferenceable(328) %5)
          to label %149 unwind label %172
The unwind destination does not have an exception handling instruction!
  %156 = invoke fastcc noundef zeroext i1 @_ZN13futures_timer6native5delay5Delay6_reset17h6558842eb872485aE(ptr noalias noundef nonnull align 8 dereferenceable(8) %151, i64 noundef %153, i32 noundef %155)
          to label %157 unwind label %172
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %167 unwind label %172
CleanupPadInst not the first non-PHI instruction in the block.
  %175 = cleanuppad within none []
in function _ZN94_$LT$libp2p_identify..handler..Handler$u20$as$u20$libp2p_swarm..handler..ConnectionHandler$GT$19on_connection_event17hd239e1ec01457673E
LLVM ERROR: Broken function found, compilation aborted!
error: could not compile `lighthouse`
error: failed to compile `lighthouse v3.4.0 (C:\Users\Michael\code\lighthouse\lighthouse)`, intermediate artifacts can be found at `C:\Users\Michael\code\lighthouse\target`

@michaelsproul michaelsproul added the C-bug Category: This is a bug. label Feb 7, 2023
@workingjubilee workingjubilee added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. O-windows Operating system: Windows labels Feb 8, 2023
@Congyuwang
Copy link

Similar problem when compiling a PyO3 project. In my case, it only occur on Windows x86.

The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc7raw_vec17capacity_overflow17h250e7d3b3e97c20eE() #30
          to label %2100 unwind label %2277
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 %2095, i32 noundef 1) #30
          to label %2105 unwind label %2277
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 2, i32 noundef 1) #30
          to label %2271 unwind label %2277
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 8, i32 noundef 4) #30
          to label %2276 unwind label %2277
CleanupPadInst not the first non-PHI instruction in the block.
  %2282 = cleanuppad within none []
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN4core3ptr46drop_in_place$LT$alloc..vec..Vec$LT$u8$GT$$GT$17hcee07cf79bbc96bcE.llvm.1999991953246885693"(ptr nonnull %107) #31 [ "funclet"(token %2306) ]
          to label %2307 unwind label %2277
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %2306 unwind label %2277
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 9, i32 noundef 1) #30
          to label %2314 unwind label %2277
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN4core3ptr46drop_in_place$LT$alloc..vec..Vec$LT$u8$GT$$GT$17hcee07cf79bbc96bcE.llvm.1999991953246885693"(ptr nonnull %109) #31 [ "funclet"(token %2334) ]
          to label %2335 unwind label %2277
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %2334 unwind label %2277
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %2340 unwind label %2277
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %2458 unwind label %2277
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %2563 unwind label %2277
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %2563 unwind label %2277
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc7raw_vec17capacity_overflow17h250e7d3b3e97c20eE() #30
          to label %2951 unwind label %3128
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 %2946, i32 noundef 1) #30
          to label %2956 unwind label %3128
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 2, i32 noundef 1) #30
          to label %3122 unwind label %3128
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 8, i32 noundef 4) #30
          to label %3127 unwind label %3128
CleanupPadInst not the first non-PHI instruction in the block.
  %3133 = cleanuppad within none []
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN4core3ptr46drop_in_place$LT$alloc..vec..Vec$LT$u8$GT$$GT$17hcee07cf79bbc96bcE.llvm.1999991953246885693"(ptr nonnull %132) #31 [ "funclet"(token %3157) ]
          to label %3158 unwind label %3128
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %3157 unwind label %3128
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 9, i32 noundef 1) #30
          to label %3165 unwind label %3128
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN4core3ptr46drop_in_place$LT$alloc..vec..Vec$LT$u8$GT$$GT$17hcee07cf79bbc96bcE.llvm.1999991953246885693"(ptr nonnull %134) #31 [ "funclet"(token %3185) ]
          to label %3186 unwind label %3128
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %3185 unwind label %3128
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %3191 unwind label %3128
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %3309 unwind label %3128
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %3414 unwind label %3128
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %3414 unwind label %3128
in function _ZN9rocksdict5rdict5Rdict11__getitem__17h11dfd8b0f599f69cE
LLVM ERROR: Broken function found, compilation aborted!
error: could not compile `RocksDict`
💥 maturin failed
  Caused by: Failed to build a native library through cargo
  Caused by: Cargo build finished with "exit code: 101": `"cargo" "rustc" "--release" "--target" "i686-pc-windows-msvc" "--message-format" "json" "--lib"`
Error: The process 'D:\a\_temp\f0b738b8-8220-48e2-a03e-41ef287fd453\maturin.exe' failed with exit code 1
    at ExecState._setResult (D:\a\_actions\messense\maturin-action\v1\dist\index.js:1702:25)
    at ExecState.CheckComplete (D:\a\_actions\messense\maturin-action\v1\dist\index.js:1685:18)
    at ChildProcess.<anonymous> (D:\a\_actions\messense\maturin-action\v1\dist\index.js:1579:27)
    at ChildProcess.emit (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Socket.<anonymous> (node:internal/child_process:451:11)
    at Socket.emit (node:events:527:28)
    at Pipe.<anonymous> (node:net:709:12)
Error: The process 'D:\a\_temp\f0b738b8-8220-48e2-a03e-41ef287fd453\maturin.exe' failed with exit code 1

@nikic
Copy link
Contributor

nikic commented Feb 16, 2023

The errors are related to SEH exception handling, which is only used on Windows.

I don't have a Windows machine so can't debug this directly. I'd suggest to run cargo with -v and then extract the failing rustc invocation, and then rerun it with -C save-temps. This should produce .bc files in the deps directory of the build directory. If you can share those files, it should allow reproduction on Linux.

@genbattle
Copy link
Contributor

genbattle commented Feb 23, 2023

I'd like to confirm I'm also seeing this issue on Windows with rustc 1.67.1 (MSVC) x86_64. I can reproduce the issue with LTO set to both "fat" and false ("local thin LTO") which is the default for the release profile.

The unwind destination does not have an exception handling instruction!
  invoke void @_ZN3std9panicking11begin_panic17h06d72bd16276e249E(ptr noalias noundef nonnull readonly align 1 @anon.de822ab2b20f7769a577e3136c8d4650.29, i64 53, ptr noalias noundef nonnull readonly align 8 dereferenceable(24) @anon.de822ab2b20f7769a577e3136c8d4650.108) #33
          to label %175 unwind label %176
CleanupPadInst not the first non-PHI instruction in the block.
  %180 = cleanuppad within none []
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %190 unwind label %176
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN3log17__private_api_log17h7b3a7ccf9969b414E(ptr noalias nocapture noundef nonnull readonly dereferenceable(48) %14, i64 noundef 2, ptr noalias noundef nonnull readonly align 8 dereferenceable(56) @anon.de822ab2b20f7769a577e3136c8d4650.120, ptr noalias noundef readonly align 8 null, i64 undef)
          to label %450 unwind label %176
The unwind destination does not have an exception handling instruction!
  %456 = invoke fastcc noundef nonnull ptr @_ZN6anyhow9__private10format_err17h1aedc5f595b3a414E(ptr noalias nocapture noundef nonnull readonly dereferenceable(48) %13)
          to label %457 unwind label %176
The unwind destination does not have an exception handling instruction!
  %469 = invoke i64 @_ZN4core4hash11BuildHasher8hash_one17h81d4add725a37804E(ptr noalias noundef nonnull readonly align 8 dereferenceable(16) %468, ptr noalias noundef nonnull readonly align 1 dereferenceable(16) %462)
          to label %470 unwind label %176
The unwind destination does not have an exception handling instruction!
  invoke void @"_ZN9hashbrown3map28HashMap$LT$K$C$V$C$S$C$A$GT$6remove17h7bbd3646bce49305E"(ptr noalias nocapture noundef nonnull sret(%307) dereferenceable(64) %38, ptr noalias noundef nonnull align 8 dereferenceable(48) %511, ptr noalias noundef nonnull readonly align 1 dereferenceable(16) %39)
          to label %512 unwind label %176
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %526 unwind label %176
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN4core3ptr65drop_in_place$LT$notify..windows..ReadDirectoryChangesWatcher$GT$17h9bd052b32e0afedcE"(ptr nonnull %521)
          to label %551 unwind label %176
The unwind destination does not have an exception handling instruction!
  %558 = invoke noundef nonnull align 8 ptr @"_ZN87_$LT$tokio..loom..std..atomic_usize..AtomicUsize$u20$as$u20$core..ops..deref..Deref$GT$5deref17hc0da01bd21d56c60E"(ptr noundef nonnull align 8 %557)
          to label %559 unwind label %176
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN17app_name4scan15project_watcher14ProjectWatcher3new17h439fbb49bbbd4106E(ptr noalias nocapture noundef nonnull sret(%308) dereferenceable(64) %45, ptr noalias noundef nonnull readonly align 8 dereferenceable(8) %565, ptr noundef nonnull %556, ptr noalias nocapture noundef nonnull readonly dereferenceable(16) %44)
          to label %566 unwind label %176
The unwind destination does not have an exception handling instruction!
  invoke void @"_ZN9hashbrown3map28HashMap$LT$K$C$V$C$S$C$A$GT$6insert17hc40dd8c50b7da086E"(ptr noalias nocapture noundef nonnull sret(%307) dereferenceable(64) %43, ptr noalias noundef nonnull align 8 dereferenceable(48) %463, ptr noalias nocapture noundef nonnull dereferenceable(16) %10, ptr noalias nocapture noundef nonnull dereferenceable(64) %9)
          to label %654 unwind label %176
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN4core3ptr65drop_in_place$LT$notify..windows..ReadDirectoryChangesWatcher$GT$17h9bd052b32e0afedcE"(ptr nonnull %667)
          to label %668 unwind label %176
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN3log17__private_api_log17h7b3a7ccf9969b414E(ptr noalias nocapture noundef nonnull readonly dereferenceable(48) %41, i64 noundef 4, ptr noalias noundef nonnull readonly align 8 dereferenceable(56) @anon.de822ab2b20f7769a577e3136c8d4650.129, ptr noalias noundef readonly align 8 null, i64 undef)
          to label %679 unwind label %176
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN3log17__private_api_log17h7b3a7ccf9969b414E(ptr noalias nocapture noundef nonnull readonly dereferenceable(48) %32, i64 noundef 3, ptr noalias noundef nonnull readonly align 8 dereferenceable(56) @anon.de822ab2b20f7769a577e3136c8d4650.132, ptr noalias noundef readonly align 8 null, i64 undef)
          to label %688 unwind label %176
in function _ZN17app_name4scan7scanner17BackgroundScanner3new28_$u7b$$u7b$closure$u7d$$u7d$28_$u7b$$u7b$closure$u7d$$u7d$17hf77b037c79bcab15E.llvm.3981804495839767495
LLVM ERROR: Broken function found, compilation aborted!

I don't have a Windows machine so can't debug this directly. I'd suggest to run cargo with -v and then extract the failing rustc invocation, and then rerun it with -C save-temps. This should produce .bc files in the deps directory of the build directory. If you can share those files, it should allow reproduction on Linux.

I've run the command as described and produced a collection of .bc files, over 200MB worth. I've compressed them and uploaded them to google drive so you can access them here temporarily.

@nikic
Copy link
Contributor

nikic commented Feb 28, 2023

I can reproduce with opt -o /dev/null -passes='thinlto-pre-link<O3>' /home/npopov/Downloads/temps/narrative_maxwell.narrative_maxwell.ed08bfcb-cgu.12.rcgu.thin-lto-after-patch.bc with opt from LLVM 15, but not with opt from LLVM 16, so this should get fixed by the LLVM 16 upgrade.

(Assigning to myself to keep track of this.)

@nikic nikic self-assigned this Feb 28, 2023
@bajtos
Copy link

bajtos commented Mar 6, 2023

What is the recommended workaround to build release binaries on Windows?

Is there a way how to keep using LTO for non-Windows targets? (Sorry for the newbie question. 🙈)

I am using the following profile (our Cargo.toml):

[profile.release]
codegen-units = 1
incremental = true
lto = true
opt-level = 3

@bajtos
Copy link

bajtos commented Mar 6, 2023

Is there a way how to keep using LTO for non-Windows targets? (Sorry for the newbie question. 🙈)

Found the answers. TL;DR: Cargo does not support per-target profiles yet. You can use env variables (e.g. CARGO_PROFILE_RELEASE_LTO) to tweak the config.

@bajtos
Copy link

bajtos commented Mar 14, 2023

so this should get fixed by the LLVM 16 upgrade

LLVM 16 upgrade PRs I was able to found, for anybody trying to keep track of the progress:

@flba-eb
Copy link
Contributor

flba-eb commented Mar 20, 2023

We observed a similar issue when building release for Windows (using Rust 1.66). Changing lto settings did not help. Problem did disappear with 1.68.

@Congyuwang
Copy link

Similar problem when compiling a PyO3 project. In my case, it only occur on Windows x86.

The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc7raw_vec17capacity_overflow17h250e7d3b3e97c20eE() #30
          to label %2100 unwind label %2277
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 %2095, i32 noundef 1) #30
          to label %2105 unwind label %2277
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 2, i32 noundef 1) #30
          to label %2271 unwind label %2277
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 8, i32 noundef 4) #30
          to label %2276 unwind label %2277
CleanupPadInst not the first non-PHI instruction in the block.
  %2282 = cleanuppad within none []
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN4core3ptr46drop_in_place$LT$alloc..vec..Vec$LT$u8$GT$$GT$17hcee07cf79bbc96bcE.llvm.1999991953246885693"(ptr nonnull %107) #31 [ "funclet"(token %2306) ]
          to label %2307 unwind label %2277
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %2306 unwind label %2277
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 9, i32 noundef 1) #30
          to label %2314 unwind label %2277
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN4core3ptr46drop_in_place$LT$alloc..vec..Vec$LT$u8$GT$$GT$17hcee07cf79bbc96bcE.llvm.1999991953246885693"(ptr nonnull %109) #31 [ "funclet"(token %2334) ]
          to label %2335 unwind label %2277
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %2334 unwind label %2277
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %2340 unwind label %2277
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %2458 unwind label %2277
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %2563 unwind label %2277
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %2563 unwind label %2277
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc7raw_vec17capacity_overflow17h250e7d3b3e97c20eE() #30
          to label %2951 unwind label %3128
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 %2946, i32 noundef 1) #30
          to label %2956 unwind label %3128
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 2, i32 noundef 1) #30
          to label %3122 unwind label %3128
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 8, i32 noundef 4) #30
          to label %3127 unwind label %3128
CleanupPadInst not the first non-PHI instruction in the block.
  %3133 = cleanuppad within none []
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN4core3ptr46drop_in_place$LT$alloc..vec..Vec$LT$u8$GT$$GT$17hcee07cf79bbc96bcE.llvm.1999991953246885693"(ptr nonnull %132) #31 [ "funclet"(token %3157) ]
          to label %3158 unwind label %3128
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %3157 unwind label %3128
The unwind destination does not have an exception handling instruction!
  invoke void @_ZN5alloc5alloc18handle_alloc_error17h7750607dc7de1938E(i32 9, i32 noundef 1) #30
          to label %3165 unwind label %3128
The unwind destination does not have an exception handling instruction!
  invoke fastcc void @"_ZN4core3ptr46drop_in_place$LT$alloc..vec..Vec$LT$u8$GT$$GT$17hcee07cf79bbc96bcE.llvm.1999991953246885693"(ptr nonnull %134) #31 [ "funclet"(token %3185) ]
          to label %3186 unwind label %3128
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %3185 unwind label %3128
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %3191 unwind label %3128
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %3309 unwind label %3128
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %3414 unwind label %3128
CleanupReturnInst must unwind to an EH block which is not a landingpad.
  cleanupret from %3414 unwind label %3128
in function _ZN9rocksdict5rdict5Rdict11__getitem__17h11dfd8b0f599f69cE
LLVM ERROR: Broken function found, compilation aborted!
error: could not compile `RocksDict`
💥 maturin failed
  Caused by: Failed to build a native library through cargo
  Caused by: Cargo build finished with "exit code: 101": `"cargo" "rustc" "--release" "--target" "i686-pc-windows-msvc" "--message-format" "json" "--lib"`
Error: The process 'D:\a\_temp\f0b738b8-8220-48e2-a03e-41ef287fd453\maturin.exe' failed with exit code 1
    at ExecState._setResult (D:\a\_actions\messense\maturin-action\v1\dist\index.js:1702:25)
    at ExecState.CheckComplete (D:\a\_actions\messense\maturin-action\v1\dist\index.js:1685:18)
    at ChildProcess.<anonymous> (D:\a\_actions\messense\maturin-action\v1\dist\index.js:1579:27)
    at ChildProcess.emit (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Socket.<anonymous> (node:internal/child_process:451:11)
    at Socket.emit (node:events:527:28)
    at Pipe.<anonymous> (node:net:709:12)
Error: The process 'D:\a\_temp\f0b738b8-8220-48e2-a03e-41ef287fd453\maturin.exe' failed with exit code 1

My problem is resolved on rust v1.68.0. Though I don't know why.

@flba-eb
Copy link
Contributor

flba-eb commented Mar 20, 2023

My problem is resolved on rust v1.68.0. Though I don't know why.

Sorry for my mistake, we just found out our issue disappeared with 1.68 as well.

@nikic
Copy link
Contributor

nikic commented Mar 26, 2023

Can anyone still reproduce this? If not I'll go ahead and close this, especially as nightly is now on LLVM 16, which should address the root cause.

@Congyuwang
Copy link

My compiling problem is resolved in nightly (1.70.0).

@michaelsproul michaelsproul changed the title LLVM error with fat LTO and Rust 1.67.0+ on Windows LLVM error with fat LTO and Rust 1.67.0 to Rust 1.69.0 on Windows Mar 28, 2023
@michaelsproul
Copy link
Contributor Author

Can confirm my issue is resolved with the latest 1.70.0 nightly as well.

Shall I close this issue as resolved?

@nikic
Copy link
Contributor

nikic commented Apr 3, 2023

Thanks everyone for confirming!

@nikic nikic closed this as completed Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

7 participants