<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/80258>80258</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wasm: Functions forcefully marked export by linker
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ryandurkoske
</td>
</tr>
</table>
<pre>
If I generate a relocatable wasm object file using wat2wasm, link the object in with the rest of my C program on wasm-ld, then all the functions defined in the object file are forcefully marked as exports.
I'm excited that _it just works_, except for this particular annoyance. Marking the extern declaration with hidden visibility does not make a difference.
I know its not an issue on wabt's part. Here is the disassembly of the relocatable obj file generated by wat2wasm:
```
(module
(type (;0;) (func (param i32)))
(import "env" "memory" (memory (;0;) 2 65536 shared))
(func $mtx_lock (type 0) (param i32)
...instructions...)
(func $mtx_unlock (type 0) (param i32)
...instructions...)
(@custom "linking" "\02\08\1b\02\00\00\00\08mtx_lock\00\00\01\0amtx_unlock"))
```
Here is my extern declaration of the functions in a header file:
```
__attribute__((visibility("default"))) extern void mtx_lock(mtx_t* mut_ptr);
__attribute__((visibility("default"))) extern void mtx_unlock(mtx_t* mutex_ptr);
```
Clang C Source compiler flags: (clang version 17.0.6)
```
-std=c17 -target wasm32 -flto
-Wall -g -O3
-nostdlib -fvisibility=hidden
-mbulk-memory -msimd128 -matomics -mmutable-globals
```
wasm-ld flags: (LLD version 17.0.6)
```
--export-dynamic --unresolved-symbols=report-all --import-memory --error-limit=0 --stack-first --gc-sections
-O3 --shared-memory --max-memory=4294967296 -zstack-size=65536
```
For further clarity, heres the undesirable result from the disassembly of the wasm linker output:
```
...function definitions...
...more exports...
(export "mtx_lock" (func $mtx_lock))
(export "mtx_unlock" (func $mtx_unlock))
... data ...
... @custom data ...
```
This is the reverse behavior of a similar issue with llvm-ar generated archive files. The linker or the archiver is stripping the visibility off of C declared/defined functions.
</pre>
<img width="1px" height="1px"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