[asan] Always skip first object from dl_iterate_phdr
authorMichael Forney <mforney@mforney.org>
Fri, 8 Apr 2022 05:35:24 +0000 (22:35 -0700)
committerFangrui Song <i@maskray.me>
Fri, 8 Apr 2022 05:35:24 +0000 (22:35 -0700)
commit795b07f5498c7e5783237418f34d7ea69e801f87
treec0b87d7a5079b086a4deae366bb548b336e66610
parent8a0406dcc8ec601e5612638a9d5ca049637c9366
[asan] Always skip first object from dl_iterate_phdr

All platforms return the main executable as the first dl_phdr_info.
FreeBSD, NetBSD, Solaris, and Linux-musl place the executable name
in the dlpi_name field of this entry. It appears that only Linux-glibc
uses the empty string.

To make this work generically on all platforms, unconditionally
skip the first object (like is currently done for FreeBSD and NetBSD).
This fixes first DSO detection on Linux-musl. It also would likely
fix detection on Solaris/Illumos if it were to gain PIE support
(since dlpi_addr would not be NULL).

Additionally, only skip the Linux VDSO on linux.

Finally, use the empty string as the "seen first dl_phdr_info"
marker rather than (char *)-1. If there was no other object, we
would try to dereference it for a string comparison.

Reviewed By: MaskRay, vitalybuka

Differential Revision: https://reviews.llvm.org/D119515
compiler-rt/lib/asan/asan_linux.cpp