ObjectFileMachO::GetMachHeaderSection() is used to find the vmaddr of the mach-o header of a binary. It first scans all of the Mach-O segments looking for one at file offset 0. Then it finds no segments at file offset 0 (e.g. binaries in a shared cache), it looks for a segment called __TEXT.
I have an unusual situation where I need to work with a binary where it is laid out in virtual memory the traditional order, TEXT, DATA, LINKEDIT. But the Mach-O binary is ordered DATA, LINKEDIT, TEXT. I would like to argue that while technically allowed, no one does this, but there is no part of the Mach-O standard that forbids such a binary, and lldb needs to roll with it.
I'm moving the search for a segment called "TEXT" to be the first thing we try, and failing that, look for a segment with file offset 0. I don't have any such binary I can include as a test case publicly, so I can't add a test for this specific case right now.
Another possible approach would be to sort the segments by vmaddr order and take the one with the lowest vmaddr as being the mach-o header. It would be a valid approach too, but I haven't stress tested this idea and am reluctant to try something novel when the existing shared cache style search works correctly if we prioritize it ahead of fileoff==0 search.
rdar://109128418