Bug 199943 - document guarantee provided by dl_iterate_phdr(3) callback order
Summary: document guarantee provided by dl_iterate_phdr(3) callback order
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-05 02:13 UTC by Ed Maste
Modified: 2015-05-05 21:42 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer 2015-05-05 02:13:33 UTC
A number of posts found on e.g. http://stackoverflow.com/ and elsewhere ask about the order of objects returned by dl_iterate_phdr. Those questions are typically targeted at Linux, but the question is equally applicable to FreeBSD. The question usually arises from a desire to know which is the main executable.

In practice the executable is passed to the first callback invocation, but there is currently no guarantee that this will not change.  We should choose one of:

1) Document this and add a test so that it remains the case
2) Caution that the order of objects is not guaranteed, and consumers should not rely on a particular order

Equivalent issue for Linux (but probably not in the correct bug tracker): https://bugzilla.kernel.org/show_bug.cgi?id=94141
Comment 1 Ed Maste freebsd_committer 2015-05-05 21:42:33 UTC
Another one I came across - this assumed the callbacks were sorted by address:
http://code.google.com/p/address-sanitizer/issues/detail?id=72

(My point is not that we should do something like sort by address, but rather a variety of dl_iterate_phdr consumers take an interest in the callback order.)