History log of /freebsd-current/lib/libpmcstat/libpmcstat_image.c
Revision Date Author Comments
# a2f733ab 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

lib: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 53d0b9e4 30-May-2023 Jessica Clarke <jrtc27@FreeBSD.org>

pmc: Provide full path to modules from kernel linker

This unifies the user object and kernel module paths in libpmcstat,
allows modules loaded from non-standard locations (e.g. from a user's
home directory when testing) to be found and, since buffer is what all
the warnings here use (they were never updated when buffer_modules were
added to pick based on where the file was found) has the side-effect of
ensuring the messages are correct.

This includes obsoleting the now-superfluous -k option in pmcstat.

This change breaks the hwpmc ABI and will be followed by a bump to the
pmc major version.

Reviewed by: jhb, jkoshy, mhorne
Differential Revision: https://reviews.freebsd.org/D40048


# a6db407f 10-Mar-2022 John Baldwin <jhb@FreeBSD.org>

libpmcstat: Fix a few ARM-specific issues with function symbols.

- Refine the checks for ARM mapping symbols and apply them on arm64 as
well as 32-bit arm. In particular, mapping symbols can have
additional characters and are not strictly limited to just "$a" but
can append additional characters (e.g. "$a.1"). Add "$x" to the
list of mapping symbol prefixes.

- Clear the LSB of function symbol addresses. Thumb function
addresses set the LSB to enable Thumb mode. However, the actual
function starts at the aligned address with LSB clear. Not clearing
the LSB can cause pmcannotate to pass misaligned addresses to
objdump when extracting disassembly.

Reviewed by: andrew
Obtained from: CheriBSD
Sponsored by: University of Cambridge, Google, Inc.
Differential Revision: https://reviews.freebsd.org/D34416


# 517a7adb 15-Dec-2021 Andrew Gallatin <gallatin@FreeBSD.org>

Make hwpmc work for userspace binaries again

hwpmc has been utterly broken for userspace binaries, and has been
labeling all samples from userspace binaries as dubious frames. The
issues are that:

-The check for ph.p_offset & (-ph.p_align) == 0 was mostly bogus. The
intent was to ignore all executable segments other than the first,
which when using BFD appeared in the first page, but with current LLD
a read-only data segment appears before the executable segment,
pushing the latter into the second page or later. This meant no
executable segment was ever found, and thus pi_vaddr remained
0. Instead of relying on BFD's layout, track whether we've seen an
executable segment explicitly with a local bool.

-Shared libraries were not parsing the segments to calculate pi_vaddr,
resulting in it always being 0. Again, when using BFD, the executable
segment started at the first page, and so pi_vaddr was genuinely
meant to be 0, but not with LLD's current layout. This meant that
pmcstat_image_link's offset calculation gave the base address of the
segment in memory, rather than the base address of the whole library
in memory, and so when adding that to pi_start/pi_end to get the
range of the executable sections in memory it double-counted the
offset of the first executable segment within the library. Thus we
need to do the exact same parsing for ET_DYN as we do for ET_EXEC,
which is simpler to write as special-casing ET_REL to not look for
segments. Note that, whilst PT_INTERP isn't needed for shared
libraries, it will be for PIEs, which pmcstat still fails to handle
due to not knowing the base address of the PIE; we get the base
address for libraries by MAP_IN events, and for rtld by virtue of the
process's entry address being rtld's, but have no equivalent for the
executable.

Fixes courtesy of jrtc27@.

Reviewed by: jrtc27, jhb (earlier version)
Differential Revision: https://reviews.freebsd.org/D33055
Sponsored by: Netflix


# 926da049 05-Nov-2020 Leandro Lupori <luporl@FreeBSD.org>

pmcstat: fix PPC kernel symbol resolution

PowerPC kernel is of DYN type and it has a base address where it is
initially loaded, before being relocated. As the start address passed to
pmcstat_image_link() is where the kernel was relocated to, but the symbols
always use the original base address, we need to subtract it to get the
correct offset.

Reviewed by: jhibbits
Sponsored by: Eldorado Research Institute (eldorado.org.br)
Differential Revision: https://reviews.freebsd.org/D26114


# 797711a8 12-Mar-2020 Ryan Moeller <freqlabs@FreeBSD.org>

libpmcstat: Try /boot/modules if module not found

Modules from ports/pkg are commonly installed to /boot/modules rather than to
the same directory the kernel resides in. Look there if a module is not found
next to the kernel.

Submitted by: mmacy
Reported by: Nick Principe <nap@iXsystems.com>
Approved by: mmacy (mentor)
MFC after: 2 weeks
Sponsored by: iXsystems, Inc.


# d27927f7 24-Oct-2017 Ruslan Bukin <br@FreeBSD.org>

Extract a set of pmcstat functions and interfaces to the new internal
library -- libpmcstat.

This includes PMC logging module, symbols lookup functions,
ELF parsing, process management, PMC attachment, etc.

This allows to reuse code while building new hwpmc(4)-based applications.

Also add pmcstat_symbol_search_by_name() function that allows to find
mapped IP range for a given function name.

Reviewed by: kib
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D12718