Skip to content
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

write/macho: change output to more closely match LLVM #584

Merged
merged 4 commits into from
Oct 26, 2023
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
12 changes: 12 additions & 0 deletions crates/examples/src/objcopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,17 @@ pub fn copy(in_data: &[u8]) -> Vec<u8> {
});
}

if let Some(in_build_version) = match &in_object {
object::File::MachO32(file) => file.build_version().unwrap(),
object::File::MachO64(file) => file.build_version().unwrap(),
_ => None,
} {
let mut out_build_version = object::write::MachOBuildVersion::default();
out_build_version.platform = in_build_version.platform.get(in_object.endianness());
out_build_version.minos = in_build_version.minos.get(in_object.endianness());
out_build_version.sdk = in_build_version.sdk.get(in_object.endianness());
out_object.set_macho_build_version(out_build_version);
}

out_object.write().unwrap()
}
50 changes: 40 additions & 10 deletions crates/examples/testfiles/macho/base-aarch64.o.objcopy
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ MachHeader {
CpuSubtype: 0x0
CPU_SUBTYPE_ARM64_ALL (0x0)
FileType: MH_OBJECT (0x1)
NumberOfCmds: 2
SizeOfCmds: 0x150
NumberOfCmds: 4
SizeOfCmds: 0x1B8
Flags: MH_SUBSECTIONS_VIA_SYMBOLS (0x2000)
}
SegmentCommand {
Expand All @@ -15,7 +15,7 @@ SegmentCommand {
SegmentName: ""
VmAddress: 0x0
VmSize: 0x68
FileOffset: 0x170
FileOffset: 0x1D8
FileSize: 0x68
MaxProt: 0x7
VM_PROT_READ (0x1)
Expand All @@ -33,9 +33,9 @@ SegmentCommand {
SegmentName: "__TEXT"
Address: 0x0
Size: 0x34
Offset: 0x170
Offset: 0x1D8
Align: 0x2
RelocationOffset: 0x260
RelocationOffset: 0x240
NumberOfRelocations: 0x3
Flags: 0x80000400
S_REGULAR (0x0)
Expand Down Expand Up @@ -72,7 +72,7 @@ SegmentCommand {
SegmentName: "__TEXT"
Address: 0x34
Size: 0xD
Offset: 0x1A4
Offset: 0x20C
Align: 0x0
RelocationOffset: 0x0
NumberOfRelocations: 0x0
Expand All @@ -84,9 +84,9 @@ SegmentCommand {
SegmentName: "__LD"
Address: 0x48
Size: 0x20
Offset: 0x1B8
Offset: 0x220
Align: 0x3
RelocationOffset: 0x278
RelocationOffset: 0x258
NumberOfRelocations: 0x1
Flags: 0x2000000
S_REGULAR (0x0)
Expand All @@ -101,12 +101,20 @@ SegmentCommand {
}
}
}
BuildVersionCommand {
Cmd: LC_BUILD_VERSION (0x32)
CmdSize: 0x18
Platform: PLATFORM_MACOS (0x1)
MinOs: 0xD0000
Sdk: 0xD0300
NumberOfTools: 0x0
}
SymtabCommand {
Cmd: LC_SYMTAB (0x2)
CmdSize: 0x18
SymbolOffset: 0x1D8
SymbolOffset: 0x260
NumberOfSymbols: 0x6
StringOffset: 0x238
StringOffset: 0x2C0
StringSize: 0x28
Nlist {
Index: 0
Expand Down Expand Up @@ -162,3 +170,25 @@ SymtabCommand {
Value: 0x0
}
}
DysymtabCommand {
Cmd: LC_DYSYMTAB (0xB)
CmdSize: 0x50
IndexOfLocalSymbols: 0
NumberOfLocalSymbols: 4
IndexOfExternallyDefinedSymbols: 4
NumberOfExternallyDefinedSymbols: 1
IndexOfUndefinedSymbols: 5
NumberOfUndefinedSymbols: 1
TocOffset: 0x0
NumberOfTocEntries: 0
ModuleTableOffset: 0x0
NumberOfModuleTableEntries: 0
ExternalRefSymbolOffset: 0x0
NumberOfExternalRefSymbols: 0
IndirectSymbolOffset: 0x0
NumberOfIndirectSymbols: 0
ExternalRelocationOffset: 0x0
NumberOfExternalRelocations: 0
LocalRelocationOffset: 0x0
NumberOfLocalRelocations: 0
}
54 changes: 42 additions & 12 deletions crates/examples/testfiles/macho/base-x86_64.o.objcopy
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ MachHeader {
CpuSubtype: 0x3
CPU_SUBTYPE_X86_64_ALL (0x3)
FileType: MH_OBJECT (0x1)
NumberOfCmds: 2
SizeOfCmds: 0x1A0
NumberOfCmds: 4
SizeOfCmds: 0x208
Flags: MH_SUBSECTIONS_VIA_SYMBOLS (0x2000)
}
SegmentCommand {
Expand All @@ -15,7 +15,7 @@ SegmentCommand {
SegmentName: ""
VmAddress: 0x0
VmSize: 0x98
FileOffset: 0x1C0
FileOffset: 0x228
FileSize: 0x98
MaxProt: 0x7
VM_PROT_READ (0x1)
Expand All @@ -33,9 +33,9 @@ SegmentCommand {
SegmentName: "__TEXT"
Address: 0x0
Size: 0x25
Offset: 0x1C0
Offset: 0x228
Align: 0x4
RelocationOffset: 0x288
RelocationOffset: 0x2C0
NumberOfRelocations: 0x2
Flags: 0x80000400
S_REGULAR (0x0)
Expand Down Expand Up @@ -64,7 +64,7 @@ SegmentCommand {
SegmentName: "__TEXT"
Address: 0x25
Size: 0xD
Offset: 0x1E5
Offset: 0x24D
Align: 0x0
RelocationOffset: 0x0
NumberOfRelocations: 0x0
Expand All @@ -76,9 +76,9 @@ SegmentCommand {
SegmentName: "__LD"
Address: 0x38
Size: 0x20
Offset: 0x1F8
Offset: 0x260
Align: 0x3
RelocationOffset: 0x298
RelocationOffset: 0x2D0
NumberOfRelocations: 0x1
Flags: 0x2000000
S_REGULAR (0x0)
Expand All @@ -98,7 +98,7 @@ SegmentCommand {
SegmentName: "__TEXT"
Address: 0x58
Size: 0x40
Offset: 0x218
Offset: 0x280
Align: 0x3
RelocationOffset: 0x0
NumberOfRelocations: 0x0
Expand All @@ -109,13 +109,21 @@ SegmentCommand {
S_ATTR_LIVE_SUPPORT (0x8000000)
}
}
BuildVersionCommand {
Cmd: LC_BUILD_VERSION (0x32)
CmdSize: 0x18
Platform: PLATFORM_MACOS (0x1)
MinOs: 0xC0000
Sdk: 0xD0100
NumberOfTools: 0x0
}
SymtabCommand {
Cmd: LC_SYMTAB (0x2)
CmdSize: 0x18
SymbolOffset: 0x258
SymbolOffset: 0x2D8
NumberOfSymbols: 0x2
StringOffset: 0x278
StringSize: 0xF
StringOffset: 0x2F8
StringSize: 0x10
Nlist {
Index: 0
String: "_main" (0x1)
Expand All @@ -138,3 +146,25 @@ SymtabCommand {
Value: 0x0
}
}
DysymtabCommand {
Cmd: LC_DYSYMTAB (0xB)
CmdSize: 0x50
IndexOfLocalSymbols: 0
NumberOfLocalSymbols: 0
IndexOfExternallyDefinedSymbols: 0
NumberOfExternallyDefinedSymbols: 1
IndexOfUndefinedSymbols: 1
NumberOfUndefinedSymbols: 1
TocOffset: 0x0
NumberOfTocEntries: 0
ModuleTableOffset: 0x0
NumberOfModuleTableEntries: 0
ExternalRefSymbolOffset: 0x0
NumberOfExternalRefSymbols: 0
IndirectSymbolOffset: 0x0
NumberOfIndirectSymbols: 0
ExternalRelocationOffset: 0x0
NumberOfExternalRelocations: 0
LocalRelocationOffset: 0x0
NumberOfLocalRelocations: 0
}
42 changes: 32 additions & 10 deletions crates/examples/testfiles/macho/reloc-aarch64.o.objcopy
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ MachHeader {
CpuSubtype: 0x0
CPU_SUBTYPE_ARM64_ALL (0x0)
FileType: MH_OBJECT (0x1)
NumberOfCmds: 2
SizeOfCmds: 0x100
NumberOfCmds: 3
SizeOfCmds: 0x150
Flags: MH_SUBSECTIONS_VIA_SYMBOLS (0x2000)
}
SegmentCommand {
Expand All @@ -15,7 +15,7 @@ SegmentCommand {
SegmentName: ""
VmAddress: 0x0
VmSize: 0x48
FileOffset: 0x120
FileOffset: 0x170
FileSize: 0x48
MaxProt: 0x7
VM_PROT_READ (0x1)
Expand All @@ -33,9 +33,9 @@ SegmentCommand {
SegmentName: "__TEXT"
Address: 0x0
Size: 0x28
Offset: 0x120
Offset: 0x170
Align: 0x0
RelocationOffset: 0x1D4
RelocationOffset: 0x1B8
NumberOfRelocations: 0xD
Flags: 0x80000400
S_REGULAR (0x0)
Expand Down Expand Up @@ -152,9 +152,9 @@ SegmentCommand {
SegmentName: "__DATA"
Address: 0x28
Size: 0x20
Offset: 0x148
Offset: 0x198
Align: 0x0
RelocationOffset: 0x23C
RelocationOffset: 0x220
NumberOfRelocations: 0x7
Flags: S_REGULAR (0x0)
RelocationInfo {
Expand Down Expand Up @@ -218,10 +218,10 @@ SegmentCommand {
SymtabCommand {
Cmd: LC_SYMTAB (0x2)
CmdSize: 0x18
SymbolOffset: 0x168
SymbolOffset: 0x258
NumberOfSymbols: 0x5
StringOffset: 0x1B8
StringSize: 0x1B
StringOffset: 0x2A8
StringSize: 0x20
Nlist {
Index: 0
String: "ltmp0" (0x11)
Expand Down Expand Up @@ -269,3 +269,25 @@ SymtabCommand {
Value: 0x0
}
}
DysymtabCommand {
Cmd: LC_DYSYMTAB (0xB)
CmdSize: 0x50
IndexOfLocalSymbols: 0
NumberOfLocalSymbols: 3
IndexOfExternallyDefinedSymbols: 3
NumberOfExternallyDefinedSymbols: 0
IndexOfUndefinedSymbols: 3
NumberOfUndefinedSymbols: 2
TocOffset: 0x0
NumberOfTocEntries: 0
ModuleTableOffset: 0x0
NumberOfModuleTableEntries: 0
ExternalRefSymbolOffset: 0x0
NumberOfExternalRefSymbols: 0
IndirectSymbolOffset: 0x0
NumberOfIndirectSymbols: 0
ExternalRelocationOffset: 0x0
NumberOfExternalRelocations: 0
LocalRelocationOffset: 0x0
NumberOfLocalRelocations: 0
}
Loading