File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -53,11 +53,23 @@ uint64_t MachHeaderSection::getSize() const {
53
53
return sizeof (MachO::mach_header_64) + sizeOfCmds + config->headerPad ;
54
54
}
55
55
56
+ static uint32_t cpuSubtype () {
57
+ uint32_t subtype = target->cpuSubtype ;
58
+
59
+ if (config->outputType == MachO::MH_EXECUTE && !config->staticLink &&
60
+ target->cpuSubtype == MachO::CPU_SUBTYPE_X86_64_ALL &&
61
+ config->platform .kind == MachO::PlatformKind::macOS &&
62
+ config->platform .minimum >= VersionTuple (10 , 5 ))
63
+ subtype |= MachO::CPU_SUBTYPE_LIB64;
64
+
65
+ return subtype;
66
+ }
67
+
56
68
void MachHeaderSection::writeTo (uint8_t *buf) const {
57
69
auto *hdr = reinterpret_cast <MachO::mach_header_64 *>(buf);
58
70
hdr->magic = MachO::MH_MAGIC_64;
59
71
hdr->cputype = target->cpuType ;
60
- hdr->cpusubtype = target-> cpuSubtype | MachO::CPU_SUBTYPE_LIB64 ;
72
+ hdr->cpusubtype = cpuSubtype () ;
61
73
hdr->filetype = config->outputType ;
62
74
hdr->ncmds = loadCommands.size ();
63
75
hdr->sizeofcmds = sizeOfCmds;
Original file line number Diff line number Diff line change
1
+ # RUN: rm -rf %t && mkdir -p %t
2
+ # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o
3
+ # RUN: %lld -arch x86_64 -platform_version macos 10.5.0 11.0 -o %t/x86-64-executable %t/test.o
4
+ # RUN: %lld -arch arm64 -o %t/arm64-executable %t/test.o
5
+ # RUN: %lld -arch x86_64 -dylib -o %t/x86-64-dylib %t/test.o
6
+ # RUN: %lld -arch arm64 -dylib -o %t/arm64-dylib %t/test.o
7
+
8
+ # RUN: llvm-objdump --macho --all-headers %t/x86-64-executable | FileCheck %s -DCAPS=LIB64
9
+ # RUN: llvm-objdump --macho --all-headers %t/arm64-executable | FileCheck %s -DCAPS=0x00
10
+ # RUN: llvm-objdump --macho --all-headers %t/x86-64-dylib | FileCheck %s -DCAPS=0x00
11
+ # RUN: llvm-objdump --macho --all-headers %t/arm64-dylib | FileCheck %s -DCAPS=0x00
12
+
13
+ # CHECK: magic cputype cpusubtype caps filetype
14
+ # CHECK-NEXT: MH_MAGIC_64 {{.*}} ALL [[CAPS]] {{.*}}
15
+
16
+ .globl _main
17
+ _main:
18
+ ret
You can’t perform that action at this time.
0 commit comments