This is an archive of the discontinued LLVM Phabricator instance.

[asan] Always skip first object from dl_iterate_phdr
AbandonedPublic

Authored by mcf on Apr 7 2022, 4:18 PM.

Details

Summary

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 with clang -shared-libsan/-shared-libasan and GCC's
default. 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.

Diff Detail

Event Timeline

mcf created this revision.Apr 7 2022, 4:18 PM
mcf requested review of this revision.Apr 7 2022, 4:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 7 2022, 4:18 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript

FWIW you can reuse the old differential D119515. You can click "Add Action"->"Reopen Revision", and then upload a new diff via web or via arc diff 'HEAD^'.
Reusing the old one may be preferred so that folks have better ideas what's tricky.

mcf abandoned this revision.Apr 7 2022, 5:12 PM

FWIW you can reuse the old differential D119515. You can click "Add Action"->"Reopen Revision", and then upload a new diff via web or via arc diff 'HEAD^'.
Reusing the old one may be preferred so that folks have better ideas what's tricky.

Ah, thanks for the tip. I tried to update it at first but it said I couldn't because it was closed. I didn't realize I could just reopen it. Closing this in favor of the old diff.