aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/IRSymtab.cpp
diff options
context:
space:
mode:
authorHongtao Yu <hoy@fb.com>2022-01-26 11:29:00 -0800
committerHongtao Yu <hoy@fb.com>2022-01-27 08:46:52 -0800
commit8d121f636b74c45366ff89504184cebe49507f4c (patch)
tree18b636778a586b8e2280fe5ff69e2affe705a73b /llvm/lib/Object/IRSymtab.cpp
parent8ce99dadb007dd0dbbf1ddbe4090e9ff43e780c5 (diff)
downloadllvm-8d121f636b74c45366ff89504184cebe49507f4c.zip
llvm-8d121f636b74c45366ff89504184cebe49507f4c.tar.gz
llvm-8d121f636b74c45366ff89504184cebe49507f4c.tar.bz2
[LTO] An option to disable automatic bitcode upgrade
Bitcode upgrade automatically takes in place when the current compiler version doesn't match the one building the input modules. The upgrade is very expansive for large applications and unnecessary when users are sure the two compilers do not have a version issue, even if their versions mismatch literally. An optional to disable the automatic bitcode upgrade will be handy in such case. Reviewed By: wenlei Differential Revision: https://reviews.llvm.org/D109869
Diffstat (limited to 'llvm/lib/Object/IRSymtab.cpp')
-rw-r--r--llvm/lib/Object/IRSymtab.cpp37
1 files changed, 22 insertions, 15 deletions
diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp
index 093ae1bbc..dea3d90 100644
--- a/llvm/lib/Object/IRSymtab.cpp
+++ b/llvm/lib/Object/IRSymtab.cpp
@@ -14,6 +14,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
+#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/IR/Comdat.h"
#include "llvm/IR/DataLayout.h"
@@ -22,13 +23,13 @@
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
-#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/MC/StringTableBuilder.h"
#include "llvm/Object/IRObjectFile.h"
#include "llvm/Object/ModuleSymbolTable.h"
#include "llvm/Object/SymbolicFile.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Casting.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/VCSRevision.h"
@@ -41,6 +42,10 @@
using namespace llvm;
using namespace irsymtab;
+cl::opt<bool> DisableBitcodeVersionUpgrade(
+ "disable-bitcode-version-upgrade", cl::init(false), cl::Hidden,
+ cl::desc("Disable automatic bitcode upgrade for version mismatch"));
+
static const char *PreservedSymbols[] = {
#define HANDLE_LIBCALL(code, name) name,
#include "llvm/IR/RuntimeLibcalls.def"
@@ -402,20 +407,22 @@ Expected<FileContents> irsymtab::readBitcode(const BitcodeFileContents &BFC) {
return make_error<StringError>("Bitcode file does not contain any modules",
inconvertibleErrorCode());
- 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);
+ if (!DisableBitcodeVersionUpgrade) {
+ 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()},