<div dir="auto">On Tue, Feb 14, 2017 at 12:43 PM, Nicholas Miell <<a href="mailto:nmiell@gmail.com">nmiell@gmail.com</a>> wrote:<br>> On 02/14/2017 12:30 PM, Chad Versace wrote:<br>>><br>>> On Tue 14 Feb 2017, Matt Turner wrote:<br>>>><br>>>> Provides the ability to read the .note.gnu.build-id section of ELF<br>>>> binaries, which is inserted by the --build-id=... flag to ld.<br>>>> ---<br>>>>  <a href="http://configure.ac">configure.ac</a>              |   2 +<br>>>>  src/util/Makefile.sources |   2 +<br>>>>  src/util/build_id.c       | 109<br>>>> ++++++++++++++++++++++++++++++++++++++++++++++<br>>>>  src/util/build_id.h       |  56 ++++++++++++++++++++++++<br>>>>  4 files changed, 169 insertions(+)<br>>>>  create mode 100644 src/util/build_id.c<br>>>>  create mode 100644 src/util/build_id.h<br>>><br>>><br>>><br>>>> +AC_CHECK_FUNC([dl_iterate_phdr], [DEFINES="$DEFINES<br>>>> -DHAVE_DL_ITERATE_PHDR"])<br>>><br>>><br>>> Nice. I wasn't aware of dl_iterate_phdr(). My code for querying the<br>>> build-id was less slick. It used open(2) on the library, then manually<br>>> parsed the ElfW(Ehdr) and ElfW(Shdr) to find the build-id node.<br>><br>><br>> I also reinvented the build ID lookup wheel and just to record this<br>> knowledge publicly for posterity:<br>><br>> The struct link_map l_addr field seems to corresponds to the struct<br>> dl_phdr_info dlpi_addr field.<br>><br>> You can retrieve the struct link_map for a symbol by passing the<br>> RTLD_DL_LINKMAP flag to dladdr1() or for a library handle returned by<br>> dlopen() by passing RTLD_DI_LINKMAP to dlinfo().<br>><br>> This means you can find the note section for a loaded library directly<br>> without having to resort to string comparisons against library names, which<br>> is probably more future-proof.<br><br>That's really neat. Thanks for the information.<br><br>It doesn't look like the BSDs or musl libc support RTLD_DL_LINKMAP. In the interest of avoiding future problems I'll stick with the string comparison for now.</div>