diff options
author | Nico Rieck <nico.rieck@gmail.com> | 2014-01-14 11:55:03 +0000 |
---|---|---|
committer | Nico Rieck <nico.rieck@gmail.com> | 2014-01-14 11:55:03 +0000 |
commit | e43aaf7967915408e5fb4dafed7fb391abdcbbe1 (patch) | |
tree | 304048f7c03b4245c22c925dc0da7bf4c38e693d /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | da881a2742387360206798093624f6b226807d1b (diff) | |
download | bcm5719-llvm-e43aaf7967915408e5fb4dafed7fb391abdcbbe1.tar.gz bcm5719-llvm-e43aaf7967915408e5fb4dafed7fb391abdcbbe1.zip |
Decouple dllexport/dllimport from linkage
Representing dllexport/dllimport as distinct linkage types prevents using
these attributes on templates and inline functions.
Instead of introducing further mixed linkage types to include linkonce and
weak ODR, the old import/export linkage types are replaced with a new
separate visibility-like specifier:
define available_externally dllimport void @f() {}
@Var = dllexport global i32 1, align 4
Linkage for dllexported globals and functions is now equal to their linkage
without dllexport. Imported globals and functions must be either
declarations with external linkage, or definitions with
AvailableExternallyLinkage.
llvm-svn: 199204
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 39a0dfa5006..81ed803ba04 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -80,8 +80,8 @@ static GlobalValue::LinkageTypes GetDecodedLinkage(unsigned Val) { case 2: return GlobalValue::AppendingLinkage; case 3: return GlobalValue::InternalLinkage; case 4: return GlobalValue::LinkOnceAnyLinkage; - case 5: return GlobalValue::DLLImportLinkage; - case 6: return GlobalValue::DLLExportLinkage; + case 5: return GlobalValue::ExternalLinkage; // Obsolete DLLImportLinkage + case 6: return GlobalValue::ExternalLinkage; // Obsolete DLLExportLinkage case 7: return GlobalValue::ExternalWeakLinkage; case 8: return GlobalValue::CommonLinkage; case 9: return GlobalValue::PrivateLinkage; @@ -102,6 +102,16 @@ static GlobalValue::VisibilityTypes GetDecodedVisibility(unsigned Val) { } } +static GlobalValue::DLLStorageClassTypes +GetDecodedDLLStorageClass(unsigned Val) { + switch (Val) { + default: // Map unknown values to default. + case 0: return GlobalValue::DefaultStorageClass; + case 1: return GlobalValue::DLLImportStorageClass; + case 2: return GlobalValue::DLLExportStorageClass; + } +} + static GlobalVariable::ThreadLocalMode GetDecodedThreadLocalMode(unsigned Val) { switch (Val) { case 0: return GlobalVariable::NotThreadLocal; @@ -193,6 +203,13 @@ static SynchronizationScope GetDecodedSynchScope(unsigned Val) { } } +static void UpgradeDLLImportExportLinkage(llvm::GlobalValue *GV, unsigned Val) { + switch (Val) { + case 5: GV->setDLLStorageClass(GlobalValue::DLLImportStorageClass); break; + case 6: GV->setDLLStorageClass(GlobalValue::DLLExportStorageClass); break; + } +} + namespace llvm { namespace { /// @brief A class for maintaining the slot number definition @@ -1797,7 +1814,7 @@ error_code BitcodeReader::ParseModule(bool Resume) { } // GLOBALVAR: [pointer type, isconst, initid, // linkage, alignment, section, visibility, threadlocal, - // unnamed_addr] + // unnamed_addr, dllstorageclass] case bitc::MODULE_CODE_GLOBALVAR: { if (Record.size() < 6) return Error(InvalidRecord); @@ -1843,6 +1860,11 @@ error_code BitcodeReader::ParseModule(bool Resume) { NewGV->setVisibility(Visibility); NewGV->setUnnamedAddr(UnnamedAddr); + if (Record.size() > 10) + NewGV->setDLLStorageClass(GetDecodedDLLStorageClass(Record[10])); + else + UpgradeDLLImportExportLinkage(NewGV, Record[3]); + ValueList.push_back(NewGV); // Remember which value to use for the global initializer. @@ -1851,7 +1873,8 @@ error_code BitcodeReader::ParseModule(bool Resume) { break; } // FUNCTION: [type, callingconv, isproto, linkage, paramattr, - // alignment, section, visibility, gc, unnamed_addr] + // alignment, section, visibility, gc, unnamed_addr, + // dllstorageclass] case bitc::MODULE_CODE_FUNCTION: { if (Record.size() < 8) return Error(InvalidRecord); @@ -1891,6 +1914,12 @@ error_code BitcodeReader::ParseModule(bool Resume) { Func->setUnnamedAddr(UnnamedAddr); if (Record.size() > 10 && Record[10] != 0) FunctionPrefixes.push_back(std::make_pair(Func, Record[10]-1)); + + if (Record.size() > 11) + Func->setDLLStorageClass(GetDecodedDLLStorageClass(Record[11])); + else + UpgradeDLLImportExportLinkage(Func, Record[3]); + ValueList.push_back(Func); // If this is a function with a body, remember the prototype we are @@ -1902,7 +1931,7 @@ error_code BitcodeReader::ParseModule(bool Resume) { break; } // ALIAS: [alias type, aliasee val#, linkage] - // ALIAS: [alias type, aliasee val#, linkage, visibility] + // ALIAS: [alias type, aliasee val#, linkage, visibility, dllstorageclass] case bitc::MODULE_CODE_ALIAS: { if (Record.size() < 3) return Error(InvalidRecord); @@ -1917,6 +1946,10 @@ error_code BitcodeReader::ParseModule(bool Resume) { // Old bitcode files didn't have visibility field. if (Record.size() > 3) NewGA->setVisibility(GetDecodedVisibility(Record[3])); + if (Record.size() > 4) + NewGA->setDLLStorageClass(GetDecodedDLLStorageClass(Record[4])); + else + UpgradeDLLImportExportLinkage(NewGA, Record[2]); ValueList.push_back(NewGA); AliasInits.push_back(std::make_pair(NewGA, Record[1])); break; |