Remove host paths from data section in WASM

Hi,
I am compiling to WASM and I have trouble with removing some sensitive host information (paths) from the generated files.

What I am seeing in the wasm (wat) file is the following (I removed a few lines):

(data (;0;) (i32.const 1048576) "/home/kasper/Projects/smart-contracts/contracts-common/src/impls.rs\00\00\00\10\00C\00\00\00<\01\00\00*\00\00\00internal error: entered unreachable code: \00\00T\00\10\00*\00\00\00Host violated precondition.\ [***REMOVED***] \00>\01\10\00U\00\00\00|\00\00\00\0d\00\00\00()called Result::unwrap()on anErrvalue\00\00\00\02\00\00\00\00\00\00\00\01\00\00\00\03\00\00\00Could not initialize contract.src/lib.rs\02\02\10\00\0a\00\00\00\1b\00\00\00\01\00\00\00Could not read state fully.\00\02\02\10\00\0a\00\00\00*\00\00\00\01\00\00\00Could not write state.\00\00\04\00\00\00\08\00\00\00\04\00\00\00\05\00\00\00\06\00\00\00\08\00\00\00\04\00\00\00\07\00\00\00\08\00\00\00\09\00\00\00\00\00\00\00\01\00\00\00\0a\00\00\00\0b\00\00\00\0c\00\00\00\09\00\00\00\04\00\00\00\04\00\00\00\0d\00\00\00\0e\00\00\00\0f\00\00\00\10\00\00\00\00\00\00\00\01\00\00\00\0a\00\00\00\0b\00\00\00\0c\00\00\00\12\00\00\00\04\00\00\00\04\00\00\00\13\00\00\00\14\00\00\00\15\00\00\00\12\00\00\00\00\00\00\00\01\00\00\00\16\00\00\00calledOption::unwrap()on aNone valuelibrary/std/src/panicking.rs\00\1f\03\10\00\1c\00\00\00\e1\01\00\00\1f\00\00\00\1f\03\10\00\1c\00\00\00\e2\01\00\00\1e\00\00\00\17\00\00\00\10\00\00\00\04\00\00\00\18\00\00\00\19\00\00\00\1a\00\00\00\0c\00\00\00\04\00\00\00\1b\00\00\00library/alloc/src/raw_vec.rscapacity overflow\00\00\00\80\03\10\00\1c\00\00\00\1e\02\00\00\05\00\00\00: \00\00\c0\03\10\00\00\00\00\00\c0\03\10\00\02\00\00\00 \00\00\00\00\00\00\00\01\00\00\00!\00\00\00index out of bounds: the len is but the index is \00\00\e4\03\10\00 \00\00\00\04\04\10\00\12\00\00\0000010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899library/core/src/fmt/mod.rs\00\f0\04\10\00\1b\00\00\00W\04\00\00\11\00\00\00\f0\04\10\00\1b\00\00\00a\04\00\00$\00\00\00 out of range for slice of length range end index \00\00N\05\10\00\10\00\00\00,\05\10\00\22\00\00\00slice index starts at but ends at \00p\05\10\00\16\00\00\00\86\05\10\00\0d\00\00\00"))

Since panics are trapped on WASM, I would ideally remove both the paths and the error messages from the data section.

There are no calls or mentions of panic in the remainder of the file.

I am compiling with the most recent nightly and using -Z build-std, however, I see the same data when compiling with stable and no -Z.

You can use --remap-path-prefix foo=bar to turn paths starting with foo into paths starting with bar. It is not possible to guarantee removal of the panic messages without modifying rustc. Using LTO may help though.

1 Like

I really wish compilers wouldn't do this. It's one obstacle to reproducible compilation. But it seems almost unavoidable at the moment.

What I usually do these days is to compile from a container from some "boring" path like /build. YMMV.

The remap trick works for my situation, thanks! :slight_smile: I couldn't get any usable results with the LTO however.

Yes, that would certainly be great. The container solution would not work for me, but thanks anyhow :slight_smile: