<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/66630>66630</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Broken `STAP_PROBE()` when linking with LLD
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lld
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
cj-tommi-rantala
</td>
</tr>
</table>
<pre>
I'm using `STAP_PROBE`s in C code to add static tracepoints into my program.
But when using the LLD linker with `-fuse-ld=lld` the tracepoints do not work (at least) with the `perf` tool.
Something goes wrong with the probe address?
I'm testing in Ubuntu 22.04:
```
$ ld.lld --version
Ubuntu LLD 16.0.6 (compatible with GNU linkers)
```
Small reproducer, put this into `Makefile`:
```
main: main.c
$(CC) $< -o $@ -g -Wall -O2 -Wl,--build-id=sha1 $(LLL)
@echo ====================================================================
readelf --notes main
@echo ====================================================================
objdump --disassemble=main main
main.c:
printf "#include <sys/sdt.h>\nint main(void) { STAP_PROBE(foo, bar); }\n" >$@
probe:
@-perf probe --quiet -d 'sdt_foo:*'
perf buildid-cache --purge=main
perf buildid-cache --add=main
perf buildid-cache --list | grep main
file main
@echo
perf probe -a 'sdt_foo:*'
perf probe -l
trace:
perf trace -e 'sdt_foo:*' bash -c './main; sleep 0.1'
clean:
-perf probe --quiet -d 'sdt_foo:*'
$(RM) main main.c
```
Then build and run, with default linker the probe should work:
```
$ make && sudo make probe && sudo make trace && sudo make clean
[...]
perf probe -l
sdt_foo:bar (on main@main.c in .../main)
perf trace -e 'sdt_foo:*' bash -c './main; sleep 0.1'
0.000 main/312053 sdt_foo:bar(__probe_ip: 94479394426948)
[...]
```
After adding `-fuse-ld=lld` it does not work, `perf probe -l` output looks suspicious and no output from the `perf trace` command:
```
$ make LLL='-fuse-ld=lld' && sudo make probe && sudo make trace && sudo make clean
[...]
perf probe -l
Failed to find debug information for address 2754
sdt_foo:bar (on __TMC_END__+3452 in .../main)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