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

0000099: error: unable to read u32 leb128: stack pointer index #838

Closed
MarkSwanson opened this issue May 14, 2018 · 10 comments
Closed

0000099: error: unable to read u32 leb128: stack pointer index #838

MarkSwanson opened this issue May 14, 2018 · 10 comments
Assignees

Comments

@MarkSwanson
Copy link

I'm compiling Rust code to wasm, and I'm getting the leb128 issue with wasm-validate.

Rust code:

#[no_mangle]
pub extern "C" fn test(n: i32) -> i32 {
n
}

I'm using the latest wabt master branch as of today, and a Rust May 9, 2018 nightly.
$ cargo build --release --target wasm32-unknown-unknown
$ wasm-validate target/wasm32-unknown-unknown/release/test.wasm

Has LLVM perhaps been updated to use a different format? Maybe wabt is expecting an older format?

@binji
Copy link
Member

binji commented May 14, 2018

I chatted with @sbc100 about this, and we're wondering if you're using an older version of wabt. The newest versions should be expecting a linking metadata version which is likely provided by the generated wasm file.

@MarkSwanson
Copy link
Author

$ which wasm2wat
/home/mswanson/src/wabt/bin/wasm2wat

(~/src/wabt is the github repo, and it's up-to-date [last commit May 14])
I've attached the wasm code that rust/llvm is creating. Maybe it will be easy for you to check to see if the right metadata version is used?

test.wasm.gz

@sbc100 sbc100 self-assigned this May 14, 2018
@sbc100
Copy link
Member

sbc100 commented May 14, 2018

I can take a look at this one.

@sbc100
Copy link
Member

sbc100 commented May 14, 2018

Looks like then new version field is not being added to the linking metadata. It was recently added so its not surprising. Also, the issue was being mis-reported due to a bug: #841. Oops.

After that change land the error message is more useful:

/bin/wasm-objdump ~/Downloads/test.wasm -h

test.wasm:	file format wasm 0x1
*ERROR*: @0x00000097: invalid linking metadata version: 3

@MarkSwanson
Copy link
Author

Thanks for looking into this.
Do you think the correct thing to do next would be for me (or someone) to log a bug with llvm / LLD?

@binji
Copy link
Member

binji commented May 15, 2018

@sbc100 wrote the wasm implementation of LLD so I imagine he will fix it.

I did think of another thing to change in wabt though; currently wasm-validate is failing to parse the binary because it hits the linking custom section and it doesn't match. But validation never relies on a custom section, they always should be ignored. You can pass --ignore-custom-section-errors to have it not do this, but it should probably be the default (at least for wasm-validate -- for wasm2wat, I'm not sure).

@sbc100
Copy link
Member

sbc100 commented May 15, 2018

I suspect that the compiler that generated that object file just needs to be updated to a version that writes the newer metadata format. Do you know how that object was generated? By which llvm version exactly?

I don't think --ignore-custom-section-errors should be the default. If you have old/invalid metadata you probably want to catch it early. Thats the point of wasm-validate right?

@MarkSwanson
Copy link
Author

I generated the object like this:
cargo build --release wasm32-unknown-unknown
(verbose mode doesn't provide much more relevant info than that...)

My Rust nightly-2018-05-09 uses LLVM 6. Tracking issue:
rust-lang/rust#47683
LLVM 6.0.0 was merged into Rust on Jan 28, 2018.

I note that there is a tracking issue to upgrade Rust to use LLVM 7:
rust-lang/rust#50543

I also note the changelog for LLVM 7 contains a number of wasm-related LLD enhancements.
So... perhaps this will just work when Rust upgrades to LLVM 7?

@sbc100
Copy link
Member

sbc100 commented May 15, 2018

That sounds right to me.

@MarkSwanson
Copy link
Author

Cool. I'll close this - I can reopen later if necessary.

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

No branches or pull requests

3 participants