Wasm frontend ignores function export names
- Lingua principale
- Rust
- Stelle
- 115
- Fork
- 84
- Merge medio
- 1g 8h
- PR unite (30g)
- 15
Descrizione
The frontend currently uses the export table only to decide whether a function is public or private. The (optional) name-section name is then used as HIR symbol and the export name is not exposed.
### Symptom and reproduction
```wat
;; export-name.wat
(module $export_name_test.wasm
;; WAT identifier: $foo_1
;; Name-section name: "foo_2"
;; Export name: "foo_3"
(func $foo_1 (@name "foo_2") (result i32)
i32.const 42
)
(export "foo_3" (func $foo_1))
)
```
Generate HIR with
```sh
midenc export-name.wat \
--entrypoint=foo_3 \
--emit=hir=- \
-Canalyze-only
```
The generated HIR contains:
```
builtin.function public extern("C") @foo_2()
```
There is no function named `@foo_3`, even though `foo_3` is the Wasm export name. So the following fails:
```sh
❯ midenc export-name.wat \
--entrypoint=export_name_test::foo_3 \
-o export-name.mas
[ERROR linker] | failed to resolve target "root_ns:root@1.0.0"::export_name_test::foo_3
Error: x undefined symbol reference
help: maybe you are missing an import?
```
(Succeeds with `--entrypoint=export_name_test::foo_2`)
### Possible fixes
- Create a public forwarding function or alias for every function export.
- Use the export name directly when possible, with aliases for additional exports.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
The issue is in the Wasm frontend's handling of export names. Look at the code that processes Wasm modules, likely in a module like `wasm_frontend.rs` or similar. The test case `export-name.wat` shows the problem: the export name `foo_3` is ignored, and the name-section name `foo_2` is used instead. Start by finding where export names are read and how they are mapped to HIR symbols. The fix involves ensuring the export name is used as the public symbol, possibly creating aliases. Run the provided shell commands to reproduce the error and verify the fix.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust, wasm
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Attiva
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 65/100