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
Another one I came across - this assumed the callbacks were sorted by address:
(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.)