From 1eeae75f3fc8e59305cc7f738b11a0976cb4f0bc Mon Sep 17 00:00:00 2001 From: Jessica Paquette Date: Tue, 26 Mar 2019 21:22:42 +0000 Subject: [PATCH] Make -mno-outline pass -enable-machine-outliner=never to ld in LTO Since AArch64 has default outlining behaviour, we need to make sure that -mno-outline is actually passed along to the linker in this case. Otherwise, it will run by default on minsize functions even when -mno-outline is specified. Also fix the darwin-ld test for this, which wasn't actually doing anything. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357031 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/ToolChains/Darwin.cpp | 21 +++++++++++++++------ test/Driver/darwin-ld.c | 8 +++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index f91ab1946f..e113f9a679 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -494,14 +494,23 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA, } // Propagate the -moutline flag to the linker in LTO. - if (Args.hasFlag(options::OPT_moutline, options::OPT_mno_outline, false)) { - if (getMachOToolChain().getMachOArchName(Args) == "arm64") { - CmdArgs.push_back("-mllvm"); - CmdArgs.push_back("-enable-machine-outliner"); + if (Arg *A = + Args.getLastArg(options::OPT_moutline, options::OPT_mno_outline)) { + if (A->getOption().matches(options::OPT_moutline)) { + if (getMachOToolChain().getMachOArchName(Args) == "arm64") { + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("-enable-machine-outliner"); - // Outline from linkonceodr functions by default in LTO. + // Outline from linkonceodr functions by default in LTO. + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("-enable-linkonceodr-outlining"); + } + } else { + // Disable all outlining behaviour if we have mno-outline. We need to do + // this explicitly, because targets which support default outlining will + // try to do work if we don't. CmdArgs.push_back("-mllvm"); - CmdArgs.push_back("-enable-linkonceodr-outlining"); + CmdArgs.push_back("-enable-machine-outliner=never"); } } diff --git a/test/Driver/darwin-ld.c b/test/Driver/darwin-ld.c index b120bbe8a3..6886fbad25 100644 --- a/test/Driver/darwin-ld.c +++ b/test/Driver/darwin-ld.c @@ -372,5 +372,11 @@ // Check that we can pass the outliner down to the linker. // RUN: env IPHONEOS_DEPLOYMENT_TARGET=7.0 \ // RUN: %clang -target arm64-apple-darwin -moutline -### %t.o 2> %t.log -// MOUTLINE: ld +// RUN: FileCheck -check-prefix=MOUTLINE %s < %t.log +// MOUTLINE: {{ld(.exe)?"}} // MOUTLINE-SAME: "-mllvm" "-enable-machine-outliner" "-mllvm" "-enable-linkonceodr-outlining" +// RUN: env IPHONEOS_DEPLOYMENT_TARGET=7.0 \ +// RUN: %clang -target arm64-apple-darwin -mno-outline -### %t.o 2> %t.log +// RUN: FileCheck -check-prefix=MNO_OUTLINE %s < %t.log +// MNO_OUTLINE: {{ld(.exe)?"}} +// MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" -- 2.50.1