diff options
author | royitaqi <royitaqi@users.noreply.github.com> | 2025-06-04 17:07:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-04 17:07:07 -0700 |
commit | d4d2f069dec4fb8b13447f52752d4ecd08d976d6 (patch) | |
tree | 3b2e5139cf5a47d61d825262705a519d6f72a03d /llvm/lib/Object/ELF.cpp | |
parent | 479f9922912e3385655f0ca6e6238aaf09e6320d (diff) | |
download | llvm-d4d2f069dec4fb8b13447f52752d4ecd08d976d6.zip llvm-d4d2f069dec4fb8b13447f52752d4ecd08d976d6.tar.gz llvm-d4d2f069dec4fb8b13447f52752d4ecd08d976d6.tar.bz2 |
[lldb] Set default object format to `MachO` in `ObjectFileMachO` (#142704)
# The Change
This patch sets the **default** object format of `ObjectFileMachO` to be
`MachO` (instead of what currently ends up to be `ELF`, see below). This
should be **the correct thing to do**, because the code before the line
of change has already verified the Mach-O header.
The existing logic:
* In `ObjectFileMachO`, the object format is unassigned by default. So
it's `UnknownObjectFormat` (see
[code](https://github.com/llvm/llvm-project/blob/54d544b83141dc0b20727673f68793728ed54793/llvm/lib/TargetParser/Triple.cpp#L1024)).
* The code then looks at load commands like `LC_VERSION_MIN_*`
([code](https://github.com/llvm/llvm-project/blob/54d544b83141dc0b20727673f68793728ed54793/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp#L5180-L5217))
and `LC_BUILD_VERSION`
([code](https://github.com/llvm/llvm-project/blob/54d544b83141dc0b20727673f68793728ed54793/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp#L5231-L5252))
and assign the Triple's OS and Environment if they exist.
* If the above sets the Triple's OS to macOS, then the object format
defaults to `MachO`; otherwise it is `ELF`
([code](https://github.com/llvm/llvm-project/blob/54d544b83141dc0b20727673f68793728ed54793/llvm/lib/TargetParser/Triple.cpp#L936-L937))
# Impact
For **production usage** where Mach-O files have the said load commands
(which is
[expected](https://www.google.com/search?q=Are+mach-o+files+expected+to+have+the+LC_BUILD_VERSION+load+command%3F)),
this patch won't change anything.
* **Important note**: It's not clear if there are legitimate production
use cases where the Mach-O files don't have said load commands. If there
is, the exiting code think they are `ELF`. This patch changes it to
`MachO`. This is considered a fix for such files.
For **unit tests**, this patch will simplify the yaml data by not
requiring the said load commands.
# Test
See PR.
Diffstat (limited to 'llvm/lib/Object/ELF.cpp')
0 files changed, 0 insertions, 0 deletions