libbpf: don't adjust USDT semaphore address if .stapsdt.base addr is missing
authorAndrii Nakryiko <andrii@kernel.org>
Thu, 21 Nov 2024 22:45:58 +0000 (14:45 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 2 Dec 2024 16:41:17 +0000 (08:41 -0800)
USDT ELF note optionally can record an offset of .stapsdt.base, which is
used to make adjustments to USDT target attach address. Currently,
libbpf will do this address adjustment unconditionally if it finds
.stapsdt.base ELF section in target binary. But there is a corner case
where .stapsdt.base ELF section is present, but specific USDT note
doesn't reference it. In such case, libbpf will basically just add base
address and end up with absolutely incorrect USDT target address.

This adjustment has to be done only if both .stapsdt.sema section is
present and USDT note is recording a reference to it.

Fixes: 74cc6311cec9 ("libbpf: Add USDT notes parsing and resolution logic")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20241121224558.796110-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/usdt.c

index 5f085736c6c45d11e5962535d8ceed1ca24eb599..4e4a52742b01c82261c941da93482e95e1e43b6f 100644 (file)
@@ -661,7 +661,7 @@ static int collect_usdt_targets(struct usdt_manager *man, Elf *elf, const char *
                 *   [0] https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation
                 */
                usdt_abs_ip = note.loc_addr;
-               if (base_addr)
+               if (base_addr && note.base_addr)
                        usdt_abs_ip += base_addr - note.base_addr;
 
                /* When attaching uprobes (which is what USDTs basically are)