Skip to content

Commit 53ed867

Browse files
committedJun 27, 2017
Object: Add version and producer fields to the irsymtab header. NFCI.
These will be necessary in order to handle upgrades from old bitcode files. Differential Revision: https://reviews.llvm.org/D33972 llvm-svn: 306486
1 parent 4b23fa0 commit 53ed867

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
 

Diff for: ‎llvm/include/llvm/Object/IRSymtab.h

+12
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ struct Uncommon {
124124
};
125125

126126
struct Header {
127+
/// Version number of the symtab format. This number should be incremented
128+
/// when the format changes, but it does not need to be incremented if a
129+
/// change to LLVM would cause it to create a different symbol table.
130+
Word Version;
131+
enum { kCurrentVersion = 0 };
132+
133+
/// The producer's version string (LLVM_VERSION_STRING " " LLVM_REVISION).
134+
/// Consumers should rebuild the symbol table from IR if the producer's
135+
/// version does not match the consumer's version due to potential differences
136+
/// in symbol table format, symbol enumeration order and so on.
137+
Str Producer;
138+
127139
Range<Module> Modules;
128140
Range<Comdat> Comdats;
129141
Range<Symbol> Symbols;

Diff for: ‎llvm/lib/Object/IRSymtab.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "llvm/Support/Casting.h"
3333
#include "llvm/Support/Error.h"
3434
#include "llvm/Support/StringSaver.h"
35+
#include "llvm/Support/VCSRevision.h"
3536
#include "llvm/Support/raw_ostream.h"
3637
#include <cassert>
3738
#include <string>
@@ -43,6 +44,21 @@ using namespace irsymtab;
4344

4445
namespace {
4546

47+
const char *getExpectedProducerName() {
48+
static char DefaultName[] = LLVM_VERSION_STRING
49+
#ifdef LLVM_REVISION
50+
" " LLVM_REVISION
51+
#endif
52+
;
53+
// Allows for testing of the irsymtab writer and upgrade mechanism. This
54+
// environment variable should not be set by users.
55+
if (char *OverrideName = getenv("LLVM_OVERRIDE_PRODUCER"))
56+
return OverrideName;
57+
return DefaultName;
58+
}
59+
60+
const char *kExpectedProducerName = getExpectedProducerName();
61+
4662
/// Stores the temporary state that is required to build an IR symbol table.
4763
struct Builder {
4864
SmallVector<char, 0> &Symtab;
@@ -231,6 +247,8 @@ Error Builder::build(ArrayRef<Module *> IRMods) {
231247
storage::Header Hdr;
232248

233249
assert(!IRMods.empty());
250+
Hdr.Version = storage::Header::kCurrentVersion;
251+
setStr(Hdr.Producer, kExpectedProducerName);
234252
setStr(Hdr.TargetTriple, IRMods[0]->getTargetTriple());
235253
setStr(Hdr.SourceFileName, IRMods[0]->getSourceFileName());
236254
TT = Triple(IRMods[0]->getTargetTriple());

0 commit comments

Comments
 (0)
Please sign in to comment.