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

build error: 'failed to build archive: wasm32.o: section too large' #1381

Closed
baoyachi opened this issue Apr 15, 2024 · 3 comments
Closed

build error: 'failed to build archive: wasm32.o: section too large' #1381

baoyachi opened this issue Apr 15, 2024 · 3 comments

Comments

@baoyachi
Copy link

build log:

➜  rust-demo git:(master) wasm-pack build --target bundler                           
[INFO]: 🎯  Checking for the Wasm target...
[INFO]: πŸŒ€  Compiling to Wasm...
   Compiling cc v1.0.90
   Compiling version_check v0.9.4
   Compiling libc v0.2.153
   Compiling cfg-if v1.0.0
   Compiling once_cell v1.19.0
   Compiling zerocopy v0.7.32
   Compiling chumsky v1.0.0-alpha.7
   Compiling allocator-api2 v0.2.16
   Compiling unicode-ident v1.0.12
   Compiling demo v0.1.0 (~/rust-demo)
   Compiling ahash v0.8.11
   Compiling psm v0.1.21
   Compiling stacker v0.1.15
   Compiling hashbrown v0.14.3
error: failed to build archive: 'wasm32.o': section too large

The following warnings were emitted during compilation:

warning: [email protected]: warning: /Library/Developer/CommandLineTools/usr/bin/ranlib: archive library: ~/rust-demo/target/wasm32-unknown-unknown/release/build/psm-e7819be911e6050d/out/libpsm_s.a the table of contents is empty (no object file members in the library define global symbols)

error: could not compile `psm` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
Error: Compiling your crate to WebAssembly failed
Caused by: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: cd "~/rust-demo" && "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"
➜  rust-demo git:(master)
  • Cargo.toml file
[package]
name = "demo"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
chumsky = "1.0.0-alpha.6"

ref:zesterer/chumsky#622

@baoyachi baoyachi changed the title build error: 'failed to build archive: 'wasm32.o': section too large' build error: 'failed to build archive: wasm32.o: section too large' Apr 15, 2024
@jccampagne
Copy link

jccampagne commented Jun 6, 2024

I had a similar issue on a different project. Installing LLVM from brew and making sure brew's LLVM was called (by updating PATH) instead of using Xcode's worked for me.

~ % clang --version       
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

versus:

~ % export PATH=/opt/homebrew/Cellar/llvm/18.1.6/bin/:$PATH                             
~ % clang --version                                        
Homebrew clang version 18.1.6
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm/18.1.6/bin

@ActuallyHappening
Copy link

I have encountered exact same error when compiling surrealdb

@robtaylor
Copy link

I've encountered the same issue building psm on Apple mac m4, OSx 15.2

to reproduce:

git clone https://github.com/rust-lang/stacker/

add crate-type to Cargo.toml

wasm-pack build

I tried to debug as much as I could. The issue occurs linking libpsm-6197a72eaab962c7.rlib:

RUST_LOG=rustc_codegen_ssa::back::link=debug CARGO=/Users/roberttaylor/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo CARGO_CRATE_NAME=psm CARGO_MANIFEST_DIR=/Users/roberttaylor/Code/temp/stacker/psm CARGO_MANIFEST_PATH=/Users/roberttaylor/Code/temp/stacker/psm/Cargo.toml CARGO_PKG_AUTHORS='Simonas Kazlauskas <[email protected]>' CARGO_PKG_DESCRIPTION='Portable Stack Manipulation: stack manipulation and introspection routines' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=psm CARGO_PKG_README=README.mkd CARGO_PKG_REPOSITORY='https://github.com/rust-lang/stacker/' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.24 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=24 CARGO_PKG_VERSION_PRE='' DYLD_FALLBACK_LIBRARY_PATH='~/.rustup/toolchains/stable-aarch64-apple-darwin/lib:/usr/local/lib:/usr/lib' OUT_DIR=target/wasm32-unknown-unknown/release/build/psm-0bab6548303c9783/out rustc -v --crate-name psm --edition=2015 psm/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=150 --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=6197a72eaab962c7 -C extra-filename=-6197a72eaab962c7 --out-dir target/wasm32-unknown-unknown/release/deps --target wasm32-unknown-unknown -C strip=debuginfo -L dependency=target/wasm32-unknown-unknown/release/deps -L dependency=target/release/deps -L native=target/wasm32-unknown-unknown/release/build/psm-0bab6548303c9783/out -l static=psm_s --cfg asm --cfg link_asm --cfg switchable_stack --check-cfg 'cfg(switchable_stack,asm,link_asm)' -C save-temps

Gives:

{"$message_type":"artifact","artifact":"target/wasm32-unknown-unknown/release/deps/psm-6197a72eaab962c7.d","emit":"dep-info"}
{"$message_type":"artifact","artifact":"target/wasm32-unknown-unknown/release/deps/libpsm-6197a72eaab962c7.rmeta","emit":"metadata"}
  INFO rustc_codegen_ssa::back::link preparing rlib to "target/wasm32-unknown-unknown/release/deps/libpsm-6197a72eaab962c7.rlib"
{"$message_type":"diagnostic","message":"failed to build archive at `target/wasm32-unknown-unknown/release/deps/libpsm-6197a72eaab962c7.rlib`: LLVM error: section too large","code":null,"level":"error","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror\u001b[0m\u001b[0m\u001b[1m: failed to build archive at `target/wasm32-unknown-unknown/release/deps/libpsm-6197a72eaab962c7.rlib`: LLVM error: section too large\u001b[0m\n\n"}
{"$message_type":"diagnostic","message":"aborting due to 1 previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror\u001b[0m\u001b[0m\u001b[1m: aborting due to 1 previous error\u001b[0m\n\n"}

Using wasm-objdump from wabt Gives the following info for the two generated .o files:

% wasm-objdump -h -x  ./target/wasm32-unknown-unknown/release/deps/psm-6197a72eaab962c7.psm.39e7a8988d52aea1-cgu.0.rcgu.o

psm-6197a72eaab962c7.psm.39e7a8988d52aea1-cgu.0.rcgu.o:	file format wasm 0x1

Sections:

     Type start=0x0000000e end=0x00000013 (size=0x00000005) count: 1
   Import start=0x00000019 end=0x0000006d (size=0x00000054) count: 3
 Function start=0x00000073 end=0x00000076 (size=0x00000003) count: 2
     Code start=0x0000007c end=0x0000008f (size=0x00000013) count: 2
   Custom start=0x00000095 end=0x0000010c (size=0x00000077) "linking"
   Custom start=0x00000112 end=0x00000125 (size=0x00000013) "reloc.CODE"
   Custom start=0x0000012b end=0x00000168 (size=0x0000003d) "producers"
   Custom start=0x0000016e end=0x000001b7 (size=0x00000049) "target_features"

Section Details:

Type[1]:
 - type[0] () -> i32
Import[3]:
 - memory[0] pages: initial=0 <- env.__linear_memory
 - func[0] sig=0 <env.rust_psm_stack_direction> <- env.rust_psm_stack_direction
 - func[1] sig=0 <env.rust_psm_stack_pointer> <- env.rust_psm_stack_pointer
Function[2]:
 - func[2] sig=0 <_ZN3psm14StackDirection3new17hfc019b08e5722fbbE>
 - func[3] sig=0 <_ZN3psm13stack_pointer17h6d43aab70d2fa383E>
Code[2]:
 - func[2] size=8 <_ZN3psm14StackDirection3new17hfc019b08e5722fbbE>
 - func[3] size=8 <_ZN3psm13stack_pointer17h6d43aab70d2fa383E>
Custom:
 - name: "linking"
  - symbol table [count=4]
   - 0: F <_ZN3psm14StackDirection3new17hfc019b08e5722fbbE> func=2 [ binding=global vis=default ]
   - 1: F <env.rust_psm_stack_direction> func=0 [ undefined binding=global vis=default ]
   - 2: F <_ZN3psm13stack_pointer17h6d43aab70d2fa383E> func=3 [ binding=global vis=default ]
   - 3: F <env.rust_psm_stack_pointer> func=1 [ undefined binding=global vis=default ]
Custom:
 - name: "reloc.CODE"
  - relocations for section: 3 (Code) [2]
   - R_WASM_FUNCTION_INDEX_LEB offset=0x000004(file=0x000080) symbol=1 <env.rust_psm_stack_direction>
   - R_WASM_FUNCTION_INDEX_LEB offset=0x00000d(file=0x000089) symbol=3 <env.rust_psm_stack_pointer>
Custom:
 - name: "producers"
Custom:
 - name: "target_features"
  - [+] multivalue
  - [+] mutable-globals
  - [+] reference-types
  - [+] sign-ext

And:

% wasm-objdump -h -x  ./psm/src/arch/wasm32.o

wasm32.o:	file format wasm 0x1

Sections:

     Type start=0x0000000e end=0x00000029 (size=0x0000001b) count: 5
   Import start=0x0000002f end=0x00000080 (size=0x00000051) count: 3
 Function start=0x00000086 end=0x0000008b (size=0x00000005) count: 4
     Code start=0x00000091 end=0x000000df (size=0x0000004e) count: 4
   Custom start=0x000000e5 end=0x0000015d (size=0x00000078) "linking"
   Custom start=0x00000163 end=0x00000185 (size=0x00000022) "reloc.CODE"

Section Details:

Type[5]:
 - type[0] () -> i32
 - type[1] (i32, i32, i32, i32) -> nil
 - type[2] (i32, i32) -> nil
 - type[3] (i32, i32, i32) -> nil
 - type[4] (i32) -> nil
Import[3]:
 - memory[0] pages: initial=0 <- env.__linear_memory
 - table[0] type=funcref initial=0 <- env.__indirect_function_table
 - global[0] i32 mutable=1 <- env.__stack_pointer
Function[4]:
 - func[0] sig=0 <rust_psm_stack_direction>
 - func[1] sig=0 <rust_psm_stack_pointer>
 - func[2] sig=1 <rust_psm_on_stack>
 - func[3] sig=3 <rust_psm_replace_stack>
Code[4]:
 - func[0] size=4 <rust_psm_stack_direction>
 - func[1] size=8 <rust_psm_stack_pointer>
 - func[2] size=39 <rust_psm_on_stack>
 - func[3] size=22 <rust_psm_replace_stack>
Custom:
 - name: "linking"
  - symbol table [count=5]
   - 0: F <rust_psm_stack_direction> func=0 [ binding=global vis=default ]
   - 1: F <rust_psm_stack_pointer> func=1 [ binding=global vis=default ]
   - 2: G <env.__stack_pointer> global=0 [ undefined binding=global vis=default ]
   - 3: F <rust_psm_on_stack> func=2 [ binding=global vis=default ]
   - 4: F <rust_psm_replace_stack> func=3 [ binding=global vis=default ]
Custom:
 - name: "reloc.CODE"
  - relocations for section: 3 (Code) [7]
   - R_WASM_GLOBAL_INDEX_LEB offset=0x000009(file=0x00009a) symbol=2 <env.__stack_pointer>
   - R_WASM_GLOBAL_INDEX_LEB offset=0x000014(file=0x0000a5) symbol=2 <env.__stack_pointer>
   - R_WASM_GLOBAL_INDEX_LEB offset=0x00001c(file=0x0000ad) symbol=2 <env.__stack_pointer>
   - R_WASM_TYPE_INDEX_LEB offset=0x000028(file=0x0000b9) type=2
   - R_WASM_GLOBAL_INDEX_LEB offset=0x000031(file=0x0000c2) symbol=2 <env.__stack_pointer>
   - R_WASM_GLOBAL_INDEX_LEB offset=0x00003c(file=0x0000cd) symbol=2 <env.__stack_pointer>
   - R_WASM_TYPE_INDEX_LEB offset=0x000046(file=0x0000d7) type=4

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

4 participants