[Driver] Infer the correct option to ld64 for -fembed-bitcode

Summary:
-fembed-bitcode infers -bitcode_bundle to ld64 but it is not correctly
passed when using LTO. LTO is a special case of -fembed-bitcode which
it doesn't require embed the bitcode in a special section in the object
file but it requires linker to save that as part of the final executable.

rdar://problem/29274226

Reviewers: mehdi_amini

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D26690

llvm-svn: 287084
This commit is contained in:
Steven Wu 2016-11-16 06:06:44 +00:00
parent 6910fa0ef4
commit 844ab6a012
4 changed files with 39 additions and 27 deletions

View File

@ -289,8 +289,14 @@ public:
bool isSaveTempsEnabled() const { return SaveTemps != SaveTempsNone; }
bool isSaveTempsObj() const { return SaveTemps == SaveTempsObj; }
bool embedBitcodeEnabled() const { return BitcodeEmbed == EmbedBitcode; }
bool embedBitcodeMarkerOnly() const { return BitcodeEmbed == EmbedMarker; }
bool embedBitcodeEnabled() const { return BitcodeEmbed != EmbedNone; }
bool embedBitcodeInObject() const {
// LTO has no object file output so ignore embed bitcode option in LTO.
return (BitcodeEmbed == EmbedBitcode) && !isUsingLTO();
}
bool embedBitcodeMarkerOnly() const {
return (BitcodeEmbed == EmbedMarker) && !isUsingLTO();
}
/// Compute the desired OpenMP runtime from the flags provided.
OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const;

View File

@ -626,26 +626,20 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
setLTOMode(Args);
// Ignore -fembed-bitcode options with LTO
// since the output will be bitcode anyway.
if (getLTOMode() == LTOK_None) {
if (Arg *A = Args.getLastArg(options::OPT_fembed_bitcode_EQ)) {
StringRef Name = A->getValue();
unsigned Model = llvm::StringSwitch<unsigned>(Name)
.Case("off", EmbedNone)
.Case("all", EmbedBitcode)
.Case("bitcode", EmbedBitcode)
.Case("marker", EmbedMarker)
.Default(~0U);
if (Model == ~0U) {
Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args)
<< Name;
} else
BitcodeEmbed = static_cast<BitcodeEmbedMode>(Model);
}
} else {
// claim the bitcode option under LTO so no warning is issued.
Args.ClaimAllArgs(options::OPT_fembed_bitcode_EQ);
// Process -fembed-bitcode= flags.
if (Arg *A = Args.getLastArg(options::OPT_fembed_bitcode_EQ)) {
StringRef Name = A->getValue();
unsigned Model = llvm::StringSwitch<unsigned>(Name)
.Case("off", EmbedNone)
.Case("all", EmbedBitcode)
.Case("bitcode", EmbedBitcode)
.Case("marker", EmbedMarker)
.Default(~0U);
if (Model == ~0U) {
Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args)
<< Name;
} else
BitcodeEmbed = static_cast<BitcodeEmbedMode>(Model);
}
std::unique_ptr<llvm::opt::InputArgList> UArgs =
@ -3059,7 +3053,7 @@ InputInfo Driver::BuildJobsForActionNoCache(
const JobAction *JA = cast<JobAction>(A);
ActionList CollapsedOffloadActions;
ToolSelector TS(JA, *TC, C, isSaveTempsEnabled(), embedBitcodeEnabled());
ToolSelector TS(JA, *TC, C, isSaveTempsEnabled(), embedBitcodeInObject());
const Tool *T = TS.getTool(Inputs, CollapsedOffloadActions);
if (!T)

View File

@ -4162,7 +4162,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
}
// Embed-bitcode option.
if (C.getDriver().embedBitcodeEnabled() &&
if (C.getDriver().embedBitcodeInObject() &&
(isa<BackendJobAction>(JA) || isa<AssembleJobAction>(JA))) {
// Add flags implied by -fembed-bitcode.
Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ);
@ -6352,7 +6352,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// pristine IR generated by the frontend. Ideally, a new compile action should
// be added so both IR can be captured.
if (C.getDriver().isSaveTempsEnabled() &&
!C.getDriver().embedBitcodeEnabled() && isa<CompileJobAction>(JA))
!C.getDriver().embedBitcodeInObject() && isa<CompileJobAction>(JA))
CmdArgs.push_back("-disable-llvm-passes");
if (Output.getType() == types::TY_Dependencies) {
@ -8321,9 +8321,9 @@ void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args,
else
CmdArgs.push_back("-no_pie");
}
// for embed-bitcode, use -bitcode_bundle in linker command
if (C.getDriver().embedBitcodeEnabled() ||
C.getDriver().embedBitcodeMarkerOnly()) {
if (C.getDriver().embedBitcodeEnabled()) {
// Check if the toolchain supports bitcode build flow.
if (MachOTC.SupportsEmbeddedBitcode())
CmdArgs.push_back("-bitcode_bundle");

View File

@ -41,3 +41,15 @@
// CHECK-MARKER: -fembed-bitcode=marker
// CHECK-MARKER-NOT: -cc1
// RUN: %clang -target armv7-apple-darwin -miphoneos-version-min=6.0 %s -fembed-bitcode=all -fintegrated-as 2>&1 -### | FileCheck %s -check-prefix=CHECK-LINKER
// RUN: %clang -target armv7-apple-darwin -miphoneos-version-min=6.0 %s -fembed-bitcode=marker -fintegrated-as 2>&1 -### | FileCheck %s -check-prefix=CHECK-LINKER
// RUN: %clang -target armv7-apple-darwin -miphoneos-version-min=6.0 %s -flto=full -fembed-bitcode=bitcode -fintegrated-as 2>&1 -### | FileCheck %s -check-prefix=CHECK-LINKER
// RUN: %clang -target armv7-apple-darwin -miphoneos-version-min=6.0 %s -flto=thin -fembed-bitcode=bitcode -fintegrated-as 2>&1 -### | FileCheck %s -check-prefix=CHECK-LINKER
// RUN: %clang -target armv7-apple-darwin -miphoneos-version-min=6.0 %s -fembed-bitcode=off -fintegrated-as 2>&1 -### | FileCheck %s -check-prefix=CHECK-NO-LINKER
// CHECK-LINKER: ld
// CHECK-LINKER: -bitcode_bundle
// CHECK-NO-LINKER-NOT: -bitcode_bundle
// RUN: %clang -target armv7-apple-darwin -miphoneos-version-min=5.0 %s -fembed-bitcode -### 2>&1 | \
// RUN: FileCheck %s -check-prefix=CHECK-PLATFORM-UNSUPPORTED
// CHECK-PLATFORM-UNSUPPORTED: -fembed-bitcode is not supported on versions of iOS prior to 6.0