diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2017-06-27 23:50:24 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2017-06-27 23:50:24 +0000 |
commit | 99b98c21f2d479e82a7eccf46825c75b43619bf8 (patch) | |
tree | 2c2f10af9cab5c0db32c9173513862102076b81f /llvm/lib/Object/IRSymtab.cpp | |
parent | 92648c25a451bbb547ea22a88481bef9526d727b (diff) | |
download | bcm5719-llvm-99b98c21f2d479e82a7eccf46825c75b43619bf8.tar.gz bcm5719-llvm-99b98c21f2d479e82a7eccf46825c75b43619bf8.zip |
Object: Teach irsymtab::read() to try to use the irsymtab that we wrote to disk.
Fixes PR27551.
Differential Revision: https://reviews.llvm.org/D33974
llvm-svn: 306488
Diffstat (limited to 'llvm/lib/Object/IRSymtab.cpp')
-rw-r--r-- | llvm/lib/Object/IRSymtab.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp index ecefd141bb0..7a6424a76a9 100644 --- a/llvm/lib/Object/IRSymtab.cpp +++ b/llvm/lib/Object/IRSymtab.cpp @@ -318,7 +318,31 @@ Expected<FileContents> irsymtab::readBitcode(const BitcodeFileContents &BFC) { return make_error<StringError>("Bitcode file does not contain any modules", inconvertibleErrorCode()); - // Right now we have no on-disk representation of symbol tables, so we always - // upgrade. - return upgrade(BFC.Mods); + if (BFC.StrtabForSymtab.empty() || + BFC.Symtab.size() < sizeof(storage::Header)) + return upgrade(BFC.Mods); + + // We cannot use the regular reader to read the version and producer, because + // it will expect the header to be in the current format. The only thing we + // can rely on is that the version and producer will be present as the first + // struct elements. + auto *Hdr = reinterpret_cast<const storage::Header *>(BFC.Symtab.data()); + unsigned Version = Hdr->Version; + StringRef Producer = Hdr->Producer.get(BFC.StrtabForSymtab); + if (Version != storage::Header::kCurrentVersion || + Producer != kExpectedProducerName) + return upgrade(BFC.Mods); + + FileContents FC; + FC.TheReader = {{BFC.Symtab.data(), BFC.Symtab.size()}, + {BFC.StrtabForSymtab.data(), BFC.StrtabForSymtab.size()}}; + + // Finally, make sure that the number of modules in the symbol table matches + // the number of modules in the bitcode file. If they differ, it may mean that + // the bitcode file was created by binary concatenation, so we need to create + // a new symbol table from scratch. + if (FC.TheReader.getNumModules() != BFC.Mods.size()) + return upgrade(std::move(BFC.Mods)); + + return std::move(FC); } |