Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: src/IceGlobalInits.h

Issue 1387963002: Make sure that all globals are internal, except for "start" functions. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Merge in new tests from master Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceELFSection.cpp ('k') | src/PNaClTranslator.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceGlobalInits.h
diff --git a/src/IceGlobalInits.h b/src/IceGlobalInits.h
index 8f51db243f02d229ee057634a1d9b3e6e60a5246..6c82fea3ebc3923db222c2b7abce8d4cacc12532 100644
--- a/src/IceGlobalInits.h
+++ b/src/IceGlobalInits.h
@@ -92,6 +92,19 @@ protected:
llvm::GlobalValue::LinkageTypes Linkage)
: Kind(Kind), Linkage(Linkage) {}
+ /// Returns true if linkage is defined correctly for the global declaration,
+ /// based on default rules.
+ bool verifyLinkageDefault(GlobalContext *Ctx) const {
Jim Stichnoth 2015/10/06 20:16:21 Here and below, maybe you can use "const GlobalCon
Karl 2015/10/06 21:47:18 Done.
+ switch (Linkage) {
+ default:
+ return false;
+ case llvm::GlobalValue::InternalLinkage:
+ return true;
+ case llvm::GlobalValue::ExternalLinkage:
+ return Ctx->getFlags().getAllowExternDefinedSymbols();
+ }
+ }
+
const GlobalDeclarationKind Kind;
IceString Name;
llvm::GlobalValue::LinkageTypes Linkage;
@@ -124,6 +137,13 @@ public:
void dump(GlobalContext *Ctx, Ostream &Stream) const final;
bool getSuppressMangling() const final { return isExternal() && IsProto; }
+ /// Returns true if linkage is correct for the function declaration.
+ bool verifyLinkageCorrect(GlobalContext *Ctx) const {
+ if (isPNaClABIExternalName() || isIntrinsicName(Ctx))
+ return Linkage == llvm::GlobalValue::ExternalLinkage;
+ return verifyLinkageDefault(Ctx);
+ }
+
private:
const Ice::FuncSigType Signature;
llvm::CallingConv::ID CallingConv;
@@ -134,6 +154,18 @@ private:
llvm::GlobalValue::LinkageTypes Linkage, bool IsProto)
: GlobalDeclaration(FunctionDeclarationKind, Linkage),
Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {}
+
+ bool isPNaClABIExternalName() const {
+ const char *Name = getName().c_str();
+ return strcmp(Name, "_start") == 0 || strcmp(Name, "__pnacl_pso_root") == 0;
+ }
+
+ bool isIntrinsicName(GlobalContext *Ctx) const {
+ if (!hasName()) return false;
Jim Stichnoth 2015/10/06 20:16:21 make format
Karl 2015/10/06 21:47:18 Done.
+ bool BadIntrinsic;
+ return Ctx->getIntrinsicsInfo().find(getName(), BadIntrinsic)
+ && !BadIntrinsic;
+ }
};
/// Models a global variable declaration, and its initializers.
@@ -309,6 +341,11 @@ public:
/// initialization).
void dump(GlobalContext *Ctx, Ostream &Stream) const final;
+ /// Returns true if linkage is correct for the variable declaration.
+ bool verifyLinkageCorrect(GlobalContext *Ctx) const {
+ return verifyLinkageDefault(Ctx);
+ }
+
static bool classof(const GlobalDeclaration *Addr) {
return Addr->getKind() == VariableDeclarationKind;
}
« no previous file with comments | « src/IceELFSection.cpp ('k') | src/PNaClTranslator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698