diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -697,29 +697,6 @@ return getenv("LLD_REPRODUCE"); } -static bool isPie(InputArgList &args) { - if (config->outputType != MH_EXECUTE || args.hasArg(OPT_no_pie)) - return false; - if (config->arch() == AK_arm64 || config->arch() == AK_arm64e || - config->arch() == AK_arm64_32) - return true; - - // TODO: add logic here as we support more archs. E.g. i386 should default - // to PIE from 10.7 - assert(config->arch() == AK_x86_64 || config->arch() == AK_x86_64h || - config->arch() == AK_arm64_32); - - PlatformKind kind = config->platformInfo.target.Platform; - if (kind == PlatformKind::macOS && - config->platformInfo.minimum >= VersionTuple(10, 6)) - return true; - - if (kind == PlatformKind::iOSSimulator || kind == PlatformKind::driverKit) - return true; - - return args.hasArg(OPT_pie); -} - static void parseClangOption(StringRef opt, const Twine &msg) { std::string err; raw_string_ostream os(err); @@ -1095,7 +1072,9 @@ createFiles(args); config->isPic = config->outputType == MH_DYLIB || - config->outputType == MH_BUNDLE || isPie(args); + config->outputType == MH_BUNDLE || + (config->outputType == MH_EXECUTE && + args.hasFlag(OPT_pie, OPT_no_pie, true)); // Now that all dylibs have been loaded, search for those that should be // re-exported. diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td --- a/lld/MachO/Options.td +++ b/lld/MachO/Options.td @@ -370,10 +370,10 @@ def grp_main : OptionGroup<"main">, HelpText<"MAIN EXECUTABLE">; def pie : Flag<["-"], "pie">, - HelpText<"Build a position independent executable (default for macOS 10.7 and later)">, + HelpText<"Build a position independent executable (default)">, Group; def no_pie : Flag<["-"], "no_pie">, - HelpText<"Do not build a position independent executable (default for macOS 10.6 and earlier)">, + HelpText<"Do not build a position independent executable">, Group; def pagezero_size : Separate<["-"], "pagezero_size">, MetaVarName<"">, diff --git a/lld/test/MachO/x86-64-reloc-unsigned.s b/lld/test/MachO/x86-64-reloc-unsigned.s --- a/lld/test/MachO/x86-64-reloc-unsigned.s +++ b/lld/test/MachO/x86-64-reloc-unsigned.s @@ -7,16 +7,7 @@ # RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE # RUN: %lld -pie -no_pie -o %t-no-pie %t.o # RUN: llvm-objdump --macho --rebase %t-no-pie | FileCheck %s --check-prefix=NO-PIE -# RUN: %lld -no_pie -pie -o %t-no-pie %t.o -# RUN: llvm-objdump --macho --rebase %t-no-pie | FileCheck %s --check-prefix=NO-PIE - -# RUN: %lld -platform_version macos 10.6.0 11.0 -o %t-pie %t.o -# RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE -# RUN: %lld -platform_version macos 10.5.0 11.0 -o %t-no-pie %t.o -# RUN: llvm-objdump --macho --rebase %t-no-pie | FileCheck %s --check-prefix=NO-PIE -# RUN: %lld -platform_version ios-simulator 11.0.0 14.2 -o %t-pie %t.o -# RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE -# RUN: %lld -platform_version driverkit 19.0 20.0 -o %t-pie %t.o +# RUN: %lld -no_pie -pie -o %t-pie %t.o # RUN: llvm-objdump --macho --rebase %t-pie | FileCheck %s --check-prefix=PIE # CHECK: Contents of section __DATA,foo: