summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2015-11-21 21:55:48 +0000
committerTeresa Johnson <tejohnson@google.com>2015-11-21 21:55:48 +0000
commit6290dbc0f7f71dbf9e5408a1b4222cbbfba43bdb (patch)
tree08a37c7cc3b671a0a5a0cd2533adc14c7110f426 /llvm/tools
parent2829c1cf7b21d003e30a214d2414cbdbd40417d1 (diff)
downloadbcm5719-llvm-6290dbc0f7f71dbf9e5408a1b4222cbbfba43bdb.tar.gz
bcm5719-llvm-6290dbc0f7f71dbf9e5408a1b4222cbbfba43bdb.zip
[ThinLTO] Handle bitcode without function summary sections gracefully
Summary: Several fixes to the handling of bitcode files without function summary sections so that they are skipped during ThinLTO processing in llvm-lto and the gold plugin when appropriate instead of aborting. 1 Don't assert when trying to add a FunctionInfo that doesn't have a summary attached. 2 Skip FunctionInfo structures that don't have attached function summary sections when trying to create the combined function summary. 3 In both llvm-lto and gold-plugin, check whether a bitcode file has a function summary section before trying to parse the index, and skip the bitcode file if it does not. 4 Fix hasFunctionSummaryInMemBuffer in BitcodeReader, which had a bug where we returned to early while looking for the summary section. Also added llvm-lto and gold-plugin based tests for cases where we don't have function summaries in the bitcode file. I verified that either the first couple fixes described above are enough to avoid the crashes, or fixes 1,3,4. But have combined them all here for added robustness. Reviewers: joker.eph Subscribers: llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D14903 llvm-svn: 253796
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/gold/gold-plugin.cpp12
-rw-r--r--llvm/tools/llvm-lto/llvm-lto.cpp35
2 files changed, 33 insertions, 14 deletions
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index 77e4b83223c..672c4e3580d 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -620,6 +620,13 @@ getFunctionIndexForFile(claimed_file &F, ld_plugin_input_file &Info) {
MemoryBufferRef BufferRef(StringRef((const char *)View, Info.filesize),
Info.name);
+
+ // Don't bother trying to build an index if there is no summary information
+ // in this bitcode file.
+ if (!object::FunctionIndexObjectFile::hasFunctionSummaryInMemBuffer(
+ BufferRef, diagnosticHandler))
+ return std::unique_ptr<FunctionInfoIndex>(nullptr);
+
ErrorOr<std::unique_ptr<object::FunctionIndexObjectFile>> ObjOrErr =
object::FunctionIndexObjectFile::create(BufferRef, diagnosticHandler);
@@ -911,6 +918,11 @@ static ld_plugin_status allSymbolsReadHook(raw_fd_ostream *ApiFile) {
std::unique_ptr<FunctionInfoIndex> Index =
getFunctionIndexForFile(F, File);
+
+ // Skip files without a function summary.
+ if (!Index)
+ continue;
+
CombinedIndex.mergeFrom(std::move(Index), ++NextModuleId);
}
diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp
index aac82d31a36..e580a5df578 100644
--- a/llvm/tools/llvm-lto/llvm-lto.cpp
+++ b/llvm/tools/llvm-lto/llvm-lto.cpp
@@ -192,24 +192,27 @@ static int listSymbols(StringRef Command, const TargetOptions &Options) {
/// Parse the function index out of an IR file and return the function
/// index object if found, or nullptr if not.
-static std::unique_ptr<FunctionInfoIndex>
-getFunctionIndexForFile(StringRef Path, std::string &Error,
+static ErrorOr<std::unique_ptr<FunctionInfoIndex>>
+getFunctionIndexForFile(StringRef Path,
DiagnosticHandlerFunction DiagnosticHandler) {
std::unique_ptr<MemoryBuffer> Buffer;
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
MemoryBuffer::getFile(Path);
- if (std::error_code EC = BufferOrErr.getError()) {
- Error = EC.message();
- return nullptr;
- }
+ if (std::error_code EC = BufferOrErr.getError())
+ return EC;
Buffer = std::move(BufferOrErr.get());
+
+ // Don't bother trying to build an index if there is no summary information
+ // in this bitcode file.
+ if (!object::FunctionIndexObjectFile::hasFunctionSummaryInMemBuffer(
+ Buffer->getMemBufferRef(), DiagnosticHandler))
+ return std::unique_ptr<FunctionInfoIndex>(nullptr);
+
ErrorOr<std::unique_ptr<object::FunctionIndexObjectFile>> ObjOrErr =
object::FunctionIndexObjectFile::create(Buffer->getMemBufferRef(),
DiagnosticHandler);
- if (std::error_code EC = ObjOrErr.getError()) {
- Error = EC.message();
- return nullptr;
- }
+ if (std::error_code EC = ObjOrErr.getError())
+ return EC;
return (*ObjOrErr)->takeIndex();
}
@@ -221,14 +224,18 @@ static int createCombinedFunctionIndex(StringRef Command) {
FunctionInfoIndex CombinedIndex;
uint64_t NextModuleId = 0;
for (auto &Filename : InputFilenames) {
- std::string Error;
- std::unique_ptr<FunctionInfoIndex> Index =
- getFunctionIndexForFile(Filename, Error, diagnosticHandler);
- if (!Index) {
+ ErrorOr<std::unique_ptr<FunctionInfoIndex>> IndexOrErr =
+ getFunctionIndexForFile(Filename, diagnosticHandler);
+ if (std::error_code EC = IndexOrErr.getError()) {
+ std::string Error = EC.message();
errs() << Command << ": error loading file '" << Filename
<< "': " << Error << "\n";
return 1;
}
+ std::unique_ptr<FunctionInfoIndex> Index = std::move(IndexOrErr.get());
+ // Skip files without a function summary.
+ if (!Index)
+ continue;
CombinedIndex.mergeFrom(std::move(Index), ++NextModuleId);
}
std::error_code EC;
OpenPOWER on IntegriCloud