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

Unable to parse clang generated bitcode target to wasm32 #55

Open
jw910731 opened this issue Aug 14, 2023 · 1 comment
Open

Unable to parse clang generated bitcode target to wasm32 #55

jw910731 opened this issue Aug 14, 2023 · 1 comment
Labels
bug Something isn't working C:mapper Concerns the llvm-mapper crate.

Comments

@jw910731
Copy link
Contributor

Problem

I compiled a simple C source by using clang and target to two different platform: wasm32 and native(aarch64).

clang -c -emit-llvm --target=wasm32 test.c
clang -c -emit-llvm -fno-unwind-tables test.c

Here is the two bitcode file generated separately by the above two command, test.bc is target to wasm32 and test.arm.bc is target to aarch64.
test_file.zip
These two file are fed to the program with following source code:

use std::{env, fs, io::stdin};

use llvm_bitstream::Bitstream;
use llvm_mapper::unroll::UnrolledBitcode;
fn main() {
    let fname;
    let args: Vec<String> = env::args().collect();
    if args.len() <= 1 {
        fname = stdin().lines().next().unwrap().unwrap();
    } else {
        fname = args[1].clone();
    }
    let content = fs::read(fname).expect("Open file error");
    let (_, bitstream) = Bitstream::from(content).unwrap();
    let bitcode = UnrolledBitcode::try_from(bitstream).unwrap();
    println!("{:?}", bitcode)
}

The result is the file target to aarch64 can be parsed without error, and wasm32 file will generate this error:

... on an `Err` value: Map(Module(DataLayoutRecord(BadInt(ParseIntError { kind: Empty }))))' ...

System Info

clang version: Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Platform: Macbook Air M2 (Darwin 22.6.0 arm64)

@woodruffw
Copy link
Owner

Thanks for the report! I've followed up on your PR.

@woodruffw woodruffw added bug Something isn't working C:mapper Concerns the llvm-mapper crate. labels Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working C:mapper Concerns the llvm-mapper crate.
Projects
None yet
Development

No branches or pull requests

2 participants