<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57085>57085</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Use of stackmaps with LTO causes `main` symbol to be zero-sized and undefined.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vext01
</td>
</tr>
</table>
<pre>
A recent(ish) change seems to have broken LLVM's symbol table emission, when LTO is used and calls to `@llvm.experimental.stackmap` are present.
Using today's `main`:
```
$ cat stackmap.ll
declare void @llvm.experimental.stackmap(i64, i32, ...)
define void @main(i32 %a1, i32 %a2) {
call void (i64, i32, ...) @llvm.experimental.stackmap(i64 0, i32 0, i32 %a1, i32 %a2)
ret void
}
```
```
$ cat no-stackmap.ll
declare void @llvm.experimental.stackmap(i64, i32, ...)
define void @main(i32 %a1, i32 %a2) {
ret void
}
```
```
$ cat check.sh
#!/bin/sh
set -e
export PATH=`pwd`/build/bin:${PATH}
echo -n "Using clang: "
which clang
clang stackmap.ll -o stackmap
clang -fuse-ld=lld -flto stackmap.ll -o stackmap-lto
clang no-stackmap.ll -o no-stackmap
clang -fuse-ld=lld -flto no-stackmap.ll -o no-stackmap-lto
for i in stackmap stackmap-lto no-stackmap no-stackmap-lto; do
echo "### $i: "
nm -S ${i} | grep main | grep -v libc_start
echo ""
done
```
```
$ sh check.sh
Using clang: /home/vext01/research/llvm-project/build/bin/clang
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
1 warning generated.
/usr/bin/ld: /tmp/stackmap-d50b22.o: warning: relocation against `main' in read-only section `.llvm_stackmaps'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
1 warning generated.
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
1 warning generated.
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
1 warning generated.
### stackmap:
0000000000001130 0000000000000006 T main
### stackmap-lto:
U main
### no-stackmap:
0000000000001130 0000000000000001 T main
### no-stackmap-lto:
0000000000001790 0000000000000001 T main
```
- In most configurations, `main` is defined and has a valid size.
- In the `stackmap-lto` configuration, the `main` symbol is zero-sized and `U`ndefined!
Having `main` like that doesn't prevent the binary running, but it does stifle some introspection tools. For example, `llvm-symboliser` will be unable to find the symbol in that state, and it breaks the `yk` JIT (which currently also uses the symboliser API).
Same info using `llvm-readelf`:
```
$ llvm-readelf --symbols stackmap-lto
Symbol table '.symtab' contains 34 entries:
Num: Value Size Type Bind Vis Ndx Name
...
25: 0000000000001830 0 FUNC GLOBAL DEFAULT UND main
```
Notice also how that configuration also emitted a fishy looking warning and the others didn't:
```
/usr/bin/ld: /tmp/stackmap-d50b22.o: warning: relocation against `main' in read-only section `.llvm_stackmaps'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
```
This doesn't appear to be caused by my stackmap operand legalisation work (e.g. `ed8ef65f3d`), as I had expected.
I'm going to run a `git bisect` to see what caused this...
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWFtv2zYU_jX2y4EEWfL1wQ9OHa8ZsrRYnG5vASXREmdKNEjKjvvrew4l23Lsph3QDcUwwXFC8fBcv3NhYpXupzPQPOGl7YRjYfJOOIEkZ2XGwXBeGLAKcrblEGu15iXc33_6rROODJh9ESsJlsWSAy-EMUKVnfAd7HIiW34AYaAyPAVWppAwKR2vzjDo9AMpt4XPXzZciwJFM-kby5J1wTa4D0xz2GhucMfvBPNOMKu_n4woM2SSsr1TAWkLJkpiGc3ahPSm_tTLsI8KWDjI8KWEeifliSRpWyVSeFsv9M6wT_aJKKRfvu-Tr36Op218yleiPJnkPITKRyF0wgHrNSa4RUgWdEY39UFwUWoOfsXc7_ARBAcRQVvWpeB_0zWAILfOtMZVo_l1qLyFn1J5_wCEflDsfoB9Sc6TtW_yA5zCqBOizEVMWiywNrRYG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