[Mesa-dev] [PATCH 1/2] util: Add utility build-id code.
nmiell at gmail.com
Tue Feb 14 20:43:56 UTC 2017
On 02/14/2017 12:30 PM, Chad Versace wrote:
> On Tue 14 Feb 2017, Matt Turner wrote:
>> Provides the ability to read the .note.gnu.build-id section of ELF
>> binaries, which is inserted by the --build-id=... flag to ld.
>> configure.ac | 2 +
>> src/util/Makefile.sources | 2 +
>> src/util/build_id.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++
>> src/util/build_id.h | 56 ++++++++++++++++++++++++
>> 4 files changed, 169 insertions(+)
>> create mode 100644 src/util/build_id.c
>> create mode 100644 src/util/build_id.h
>> +AC_CHECK_FUNC([dl_iterate_phdr], [DEFINES="$DEFINES -DHAVE_DL_ITERATE_PHDR"])
> Nice. I wasn't aware of dl_iterate_phdr(). My code for querying the
> build-id was less slick. It used open(2) on the library, then manually
> parsed the ElfW(Ehdr) and ElfW(Shdr) to find the build-id node.
I also reinvented the build ID lookup wheel and just to record this
knowledge publicly for posterity:
The struct link_map l_addr field seems to corresponds to the struct
dl_phdr_info dlpi_addr field.
You can retrieve the struct link_map for a symbol by passing the
RTLD_DL_LINKMAP flag to dladdr1() or for a library handle returned by
dlopen() by passing RTLD_DI_LINKMAP to dlinfo().
This means you can find the note section for a loaded library directly
without having to resort to string comparisons against library names,
which is probably more future-proof.
More information about the mesa-dev