Repository navigation
WASI: path_open regression in Rust 1.51 when using LTO #82758
Copy link
Copy link
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/Target: WASM (WebAssembly), http://webassembly.org/P-highHigh priorityHigh priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
Milestone
Description
Code
I tried this code:
fn main() {
let _ = std::fs::File::open("/proxy-wasm-sandbox/regression.txt");
}$ cargo +beta build --target wasm32-wasi --releaseI expected to see this happen:
This is executed inside Envoy Proxy with preopen dir /proxy-wasm-sandbox, but hopefully the output is readable:
[host->vm] _start()
[vm->host] wasi_snapshot_preview1.fd_prestat_get(3, 1048568)
[vm<-host] wasi_snapshot_preview1.fd_prestat_get return: 0
[vm->host] wasi_snapshot_preview1.fd_prestat_dir_name(3, 1114128, 19)
[vm<-host] wasi_snapshot_preview1.fd_prestat_dir_name return: 0
[vm->host] wasi_snapshot_preview1.fd_prestat_get(4, 1048568)
[vm<-host] wasi_snapshot_preview1.fd_prestat_get return: 8
[vm->host] wasi_snapshot_preview1.path_open(3, 1, 1114320, 14, 0, 262667966, 262667966, 0, 1048520)
[vm<-host] wasi_snapshot_preview1.path_open return: 0
[vm->host] wasi_snapshot_preview1.fd_close(4)
[vm<-host] wasi_snapshot_preview1.fd_close return: 0
[host<-vm] _start return: void
The memory address and size passed in the call (path_open(.., 1114320, 14, ..)) correctly point to a regression.txt.
Instead, this happened:
[host->vm] _start()
[vm->host] wasi_snapshot_preview1.fd_prestat_get(3, 1048568)
[vm<-host] wasi_snapshot_preview1.fd_prestat_get return: 0
[vm->host] wasi_snapshot_preview1.fd_prestat_dir_name(3, 1058576, 19)
[vm<-host] wasi_snapshot_preview1.fd_prestat_dir_name return: 0
[vm->host] wasi_snapshot_preview1.fd_prestat_get(4, 1048568)
[vm<-host] wasi_snapshot_preview1.fd_prestat_get return: 8
[vm->host] wasi_snapshot_preview1.path_open(3, 1, 1, 0, 0, 262667966, 262667966, 0, 1048520)
[vm<-host] wasi_snapshot_preview1.path_open return: 44
[host<-vm] _start return: void
The memory address and size passed in the call (path_open(.., 1, 0, ..)) are wrong.
Version it worked on
It most recently worked on: Rust 1.50
rustc --version --verbose:
rustc 1.50.0 (cb75ad5db 2021-02-10)
binary: rustc
commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
commit-date: 2021-02-10
host: x86_64-unknown-linux-gnu
release: 1.50.0
Version with regression
rustc --version --verbose:
rustc 1.51.0-beta.3 (b631c914c 2021-02-24)
binary: rustc
commit-hash: b631c914cdb5b74dac8f182ca96fdfd3e03ab319
commit-date: 2021-02-24
host: x86_64-unknown-linux-gnu
release: 1.51.0-beta.3
LLVM version: 11.0.1
@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/Target: WASM (WebAssembly), http://webassembly.org/P-highHigh priorityHigh priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
Activity
PiotrSikora commentedon Mar 4, 2021
Those PRs look like a possible candidates: #79578, WebAssembly/wasi-libc#214.
Perhaps there is a bug in my code, but it works with Rust 1.50, and the preopens are populated correctly even in Rust 1.51 (otherwise it wouldn't reach
path_open), so there aren't too many places left to make a mistake.cc @alexcrichton
PiotrSikora commentedon Mar 4, 2021
I think I found the culprit.
This happens only in the release builds with LTO enabled, where
__wasilibc_find_relpath_allocgets optimized out:PiotrSikora commentedon Mar 4, 2021
Confirmed: if I "use"
__wasilibc_find_relpath_alloc, so that it doesn't get optimized out, then everything works fine:[-]WASI: path_open regression in Rust 1.51[/-][+]WASI: path_open regression in Rust 1.51 when using LTO[/+]alexcrichton commentedon Mar 4, 2021
@PiotrSikora can you clarify how you're building your project? Are you using an external libc or the one shipped with libstd?
PiotrSikora commentedon Mar 4, 2021
LeSeulArtichaut commentedon Mar 5, 2021
Just to clarify, this does not happen with LTO disabled?
alexcrichton commentedon Mar 5, 2021
Ok I believe that this is fixed in #82804. The
undefinedbit you see there is normal, that's what's happening with weak function references during LTO because that function isn't actually used.PiotrSikora commentedon Mar 5, 2021
Correct.
Thanks! I verified that #82804 fixes the issue for me.
apiraino commentedon Mar 10, 2021
Assigning
P-highas discussed as part of the Prioritization Working Group procedure and removingI-prioritize.@rustbot label -I-prioritize +P-high
std: Fix a bug on the wasm32-wasi target opening files
Rollup merge of rust-lang#82804 - alexcrichton:fix-wasi, r=pnkfelix
Rollup merge of rust-lang#82804 - alexcrichton:fix-wasi, r=pnkfelix
Rollup merge of rust-lang#82804 - alexcrichton:fix-wasi, r=pnkfelix
std: Fix a bug on the wasm32-wasi target opening files
pnkfelix commentedon Apr 1, 2021
Discussed in weekly rustc triage meeting. We believe this was fixed by #82804. Closing as fixed.