Skip to content

[lldb] Set default object format to MachO in ObjectFileMachO #142704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5148,6 +5148,7 @@ void ObjectFileMachO::GetAllArchSpecs(const llvm::MachO::mach_header &header,
llvm::Triple base_triple = base_arch.GetTriple();
base_triple.setOS(llvm::Triple::UnknownOS);
base_triple.setOSName(llvm::StringRef());
base_triple.setObjectFormat(llvm::Triple::MachO);

if (header.filetype == MH_PRELOAD) {
if (header.cputype == CPU_TYPE_ARM) {
Expand Down
55 changes: 55 additions & 0 deletions lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,59 @@ TEST_F(ObjectFileMachOTest, IndirectSymbolsInTheSharedCache) {
for (size_t i = 0; i < 10; i++)
OF->ParseSymtab(symtab);
}

TEST_F(ObjectFileMachOTest, ObjectFormatWithoutVersionLoadCommand) {
// A Mach-O file without the load command LC_BUILD_VERSION.
const char *yamldata = R"(
--- !mach-o
FileHeader:
magic: 0xFEEDFACF
cputype: 0x0100000C
cpusubtype: 0x00000000
filetype: 0x00000001
ncmds: 1
sizeofcmds: 152
flags: 0x00002000
reserved: 0x00000000
LoadCommands:
- cmd: LC_SEGMENT_64
cmdsize: 152
segname: __TEXT
vmaddr: 0
vmsize: 4
fileoff: 184
filesize: 4
maxprot: 7
initprot: 7
nsects: 1
flags: 0
Sections:
- sectname: __text
segname: __TEXT
addr: 0x0000000000000000
content: 'AABBCCDD'
size: 4
offset: 184
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
...
)";

// Perform setup.
llvm::Expected<TestFile> file = TestFile::fromYaml(yamldata);
EXPECT_THAT_EXPECTED(file, llvm::Succeeded());
auto module_sp = std::make_shared<Module>(file->moduleSpec());
ASSERT_NE(module_sp, nullptr);
auto object_file = module_sp->GetObjectFile();
ASSERT_NE(object_file, nullptr);

// Verify that the object file is recognized as Mach-O.
ASSERT_EQ(object_file->GetArchitecture().GetTriple().getObjectFormat(),
llvm::Triple::MachO);
}
#endif
Loading