diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp index 7fb493088338..ad8f8bfa73e2 100644 --- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -160,6 +160,26 @@ void MachOLinkingContext::configure(HeaderFileType type, Arch arch, OS os, _os = os; _osMinVersion = minOSVersion; + // If min OS not specified on command line, use reasonable defaults. + if (minOSVersion == 0) { + switch (_arch) { + case arch_x86_64: + case arch_x86: + parsePackedVersion("10.8", _osMinVersion); + _os = MachOLinkingContext::OS::macOSX; + break; + case arch_armv6: + case arch_armv7: + case arch_armv7s: + case arch_arm64: + parsePackedVersion("7.0", _osMinVersion); + _os = MachOLinkingContext::OS::iOS; + break; + default: + break; + } + } + switch (_outputMachOType) { case llvm::MachO::MH_EXECUTE: // If targeting newer OS, use _main diff --git a/lld/test/mach-o/exe-segment-overlap.yaml b/lld/test/mach-o/exe-segment-overlap.yaml index ec818969de69..1fbc84123182 100644 --- a/lld/test/mach-o/exe-segment-overlap.yaml +++ b/lld/test/mach-o/exe-segment-overlap.yaml @@ -1,9 +1,9 @@ -# RUN: lld -flavor darwin -arch x86_64 %s -o %t +# RUN: lld -flavor darwin -arch x86_64 %s -o %t %p/Inputs/libSystem.yaml # RUN: llvm-readobj -sections -section-data %t | FileCheck %s --- !native defined-atoms: - - name: start + - name: _main scope: global content: [ 90 ] @@ -19,26 +19,6 @@ defined-atoms: section-name: __CUST/__custom ---- !mach-o -arch: x86_64 -file-type: MH_DYLIB -flags: [ ] -install-name: /usr/lib/libSystem.B.dylib -sections: - - segment: __TEXT - section: __text - type: S_REGULAR - attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] - address: 0x0000000000000000 - content: [ 0x55 ] - -global-symbols: - - name: dyld_stub_binder - type: N_SECT - scope: [ N_EXT ] - sect: 1 - value: 0x0000000000000000 - # CHECK-LABEL: Section { # CHECK: Name: __text # CHECK: Segment: __TEXT diff --git a/lld/test/mach-o/hello-world-arm64.yaml b/lld/test/mach-o/hello-world-arm64.yaml index f6b030648754..a0555e9cc426 100644 --- a/lld/test/mach-o/hello-world-arm64.yaml +++ b/lld/test/mach-o/hello-world-arm64.yaml @@ -1,4 +1,4 @@ -# RUN: lld -flavor darwin -arch arm64 -ios_version_min 7.0 %s -o %t && \ +# RUN: lld -flavor darwin -arch arm64 %s -o %t # RUN: llvm-nm -m -n %t | FileCheck %s # # Test that arm64 hello-world can be linked into a mach-o executable diff --git a/lld/test/mach-o/hello-world-armv6.yaml b/lld/test/mach-o/hello-world-armv6.yaml index c24d0897795c..746ee094da68 100644 --- a/lld/test/mach-o/hello-world-armv6.yaml +++ b/lld/test/mach-o/hello-world-armv6.yaml @@ -1,4 +1,4 @@ -# RUN: lld -flavor darwin -arch armv6 -ios_version_min 7.0 %s -o %t && \ +# RUN: lld -flavor darwin -arch armv6 %s -o %t # RUN: llvm-nm -m %t | FileCheck %s # # Test that armv6 (arm) hello-world can be linked into a mach-o executable diff --git a/lld/test/mach-o/hello-world-armv7.yaml b/lld/test/mach-o/hello-world-armv7.yaml index 54f737bda52e..bfc03c382a05 100644 --- a/lld/test/mach-o/hello-world-armv7.yaml +++ b/lld/test/mach-o/hello-world-armv7.yaml @@ -1,4 +1,4 @@ -# RUN: lld -flavor darwin -arch armv7 -ios_version_min 7.0 %s -o %t && \ +# RUN: lld -flavor darwin -arch armv7 %s -o %t # RUN: llvm-nm -m -n %t | FileCheck %s # # Test that armv7 (thumb) hello-world can be linked into a mach-o executable diff --git a/lld/test/mach-o/hello-world-x86.yaml b/lld/test/mach-o/hello-world-x86.yaml index d8f7b52d6ae0..de453ed1ac45 100644 --- a/lld/test/mach-o/hello-world-x86.yaml +++ b/lld/test/mach-o/hello-world-x86.yaml @@ -1,4 +1,4 @@ -# RUN: lld -flavor darwin -arch i386 -macosx_version_min 10.8 %s -o %t && \ +# RUN: lld -flavor darwin -arch i386 %s -o %t # RUN: llvm-nm -m %t | FileCheck %s # # Test that i386 hello-world can be linked into a mach-o executable diff --git a/lld/test/mach-o/hello-world-x86_64.yaml b/lld/test/mach-o/hello-world-x86_64.yaml index 985ab5f31cf8..83d4fcb32601 100644 --- a/lld/test/mach-o/hello-world-x86_64.yaml +++ b/lld/test/mach-o/hello-world-x86_64.yaml @@ -1,8 +1,8 @@ -# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t && \ +# RUN: lld -flavor darwin -arch x86_64 %s -o %t # RUN: llvm-nm -m -n %t | FileCheck %s # -# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -dead_strip \ -# RUN: -o %t2 && llvm-nm -m -n %t2 | FileCheck %s +# RUN: lld -flavor darwin -arch x86_64 %s -dead_strip -o %t2 +# RUN: llvm-nm -m -n %t2 | FileCheck %s # # Test that x86_64 hello-world can be linked into a mach-o executable #