1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[LTO] Don't apply LTOPostLink module flag during writeMergedModule

For `ld64` which uses legacy LTOCodeGenerator, it relies on
writeMergedModule to perform `ld -r` (generates a linked object file).
If all the inputs to `ld -r` is fullLTO bitcode, `ld64` will linked the
bitcode module, internalize all the symbols and write out another
fullLTO bitcode object file. This bitcode file doesn't have all the
bitcode inputs and it should not have LTOPostLink module flag. It will
also cause error when this bitcode object file is linked with other LTO
object file.
Fix the issue by not applying LTOPostLink flag during writeMergedModule
function. The flag should only be added when all the bitcode are linked
and ready to be optimized.

rdar://problem/58462798

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D84789
This commit is contained in:
Steven Wu 2020-08-26 11:17:26 -07:00
parent 0829adce54
commit 0298cbfe6d
3 changed files with 21 additions and 3 deletions

View File

@ -466,8 +466,6 @@ void LTOCodeGenerator::applyScopeRestrictions() {
internalizeModule(*MergedModule, mustPreserveGV); internalizeModule(*MergedModule, mustPreserveGV);
MergedModule->addModuleFlag(Module::Error, "LTOPostLink", 1);
ScopeRestrictionsDone = true; ScopeRestrictionsDone = true;
} }
@ -559,6 +557,9 @@ bool LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline,
// Mark which symbols can not be internalized // Mark which symbols can not be internalized
this->applyScopeRestrictions(); this->applyScopeRestrictions();
// Write LTOPostLink flag for passes that require all the modules.
MergedModule->addModuleFlag(Module::Error, "LTOPostLink", 1);
// Instantiate the pass manager to organize the passes. // Instantiate the pass manager to organize the passes.
legacy::PassManager passes; legacy::PassManager passes;

View File

@ -1,7 +1,8 @@
; RUN: opt %s -o %t1.bc ; RUN: opt %s -o %t1.bc
; RUN: llvm-lto %t1.bc -o %t1.save.opt -save-merged-module -O1 --exported-symbol=foo ; RUN: llvm-lto %t1.bc -o %t1.save.opt -save-linked-module -save-merged-module -O1 --exported-symbol=foo
; RUN: llvm-dis < %t1.save.opt.merged.bc | FileCheck %s ; RUN: llvm-dis < %t1.save.opt.merged.bc | FileCheck %s
; RUN: llvm-dis < %t1.save.opt.linked.bc | FileCheck %s --check-prefix=CHECK-LINKED
; RUN: llvm-lto2 run %t1.bc -o %t.out.o -save-temps \ ; RUN: llvm-lto2 run %t1.bc -o %t.out.o -save-temps \
; RUN: -r=%t1.bc,foo,pxl ; RUN: -r=%t1.bc,foo,pxl
@ -17,3 +18,6 @@ entry:
; CHECK: !llvm.module.flags = !{[[MD_NUM:![0-9]+]]} ; CHECK: !llvm.module.flags = !{[[MD_NUM:![0-9]+]]}
; CHECK: [[MD_NUM]] = !{i32 1, !"LTOPostLink", i32 1} ; CHECK: [[MD_NUM]] = !{i32 1, !"LTOPostLink", i32 1}
; CHECK-LINKED: @foo
; CHECK-LINKED-NOT: LTOPostLink

View File

@ -181,6 +181,10 @@ static cl::opt<std::string> ThinLTOGeneratedObjectsDir(
cl::desc("Save ThinLTO generated object files using filenames created in " cl::desc("Save ThinLTO generated object files using filenames created in "
"the given directory.")); "the given directory."));
static cl::opt<bool> SaveLinkedModuleFile(
"save-linked-module", cl::init(false),
cl::desc("Write linked LTO module to file before optimize"));
static cl::opt<bool> static cl::opt<bool>
SaveModuleFile("save-merged-module", cl::init(false), SaveModuleFile("save-merged-module", cl::init(false),
cl::desc("Write merged LTO module to file before CodeGen")); cl::desc("Write merged LTO module to file before CodeGen"));
@ -1029,6 +1033,15 @@ int main(int argc, char **argv) {
CodeGen.setFileType(FT.getValue()); CodeGen.setFileType(FT.getValue());
if (!OutputFilename.empty()) { if (!OutputFilename.empty()) {
if (SaveLinkedModuleFile) {
std::string ModuleFilename = OutputFilename;
ModuleFilename += ".linked.bc";
std::string ErrMsg;
if (!CodeGen.writeMergedModules(ModuleFilename))
error("writing linked module failed.");
}
if (!CodeGen.optimize(DisableVerify, DisableInline, DisableGVNLoadPRE, if (!CodeGen.optimize(DisableVerify, DisableInline, DisableGVNLoadPRE,
DisableLTOVectorization)) { DisableLTOVectorization)) {
// Diagnostic messages should have been printed by the handler. // Diagnostic messages should have been printed by the handler.