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

Side by Side 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: Fix new tests. 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 unified diff | Download patch
« no previous file with comments | « src/IceELFSection.cpp ('k') | src/PNaClTranslator.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceGlobalInits.h - Global declarations -------*- C++ -*-===// 1 //===- subzero/src/IceGlobalInits.h - Global declarations -------*- C++ -*-===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 /// Returns true if when emitting names, we should suppress mangling. 81 /// Returns true if when emitting names, we should suppress mangling.
82 virtual bool getSuppressMangling() const = 0; 82 virtual bool getSuppressMangling() const = 0;
83 83
84 /// Mangles name for cross tests, unless external and not defined locally (so 84 /// Mangles name for cross tests, unless external and not defined locally (so
85 /// that relocations across pnacl-sz and pnacl-llc will work). 85 /// that relocations across pnacl-sz and pnacl-llc will work).
86 virtual IceString mangleName(GlobalContext *Ctx) const { 86 virtual IceString mangleName(GlobalContext *Ctx) const {
87 return getSuppressMangling() ? Name : Ctx->mangleName(Name); 87 return getSuppressMangling() ? Name : Ctx->mangleName(Name);
88 } 88 }
89 89
90 /// Returns textual name of linkage.
91 const char *getLinkageName() const {
92 return isInternal() ? "internal" : "external";
93 }
94
90 protected: 95 protected:
91 GlobalDeclaration(GlobalDeclarationKind Kind, 96 GlobalDeclaration(GlobalDeclarationKind Kind,
92 llvm::GlobalValue::LinkageTypes Linkage) 97 llvm::GlobalValue::LinkageTypes Linkage)
93 : Kind(Kind), Linkage(Linkage) {} 98 : Kind(Kind), Linkage(Linkage) {}
94 99
100 /// Returns true if linkage is defined correctly for the global declaration,
101 /// based on default rules.
102 bool verifyLinkageDefault(const GlobalContext *Ctx) const {
103 switch (Linkage) {
104 default:
105 return false;
106 case llvm::GlobalValue::InternalLinkage:
107 return true;
108 case llvm::GlobalValue::ExternalLinkage:
109 return Ctx->getFlags().getAllowExternDefinedSymbols();
110 }
111 }
112
95 const GlobalDeclarationKind Kind; 113 const GlobalDeclarationKind Kind;
96 IceString Name; 114 IceString Name;
97 llvm::GlobalValue::LinkageTypes Linkage; 115 llvm::GlobalValue::LinkageTypes Linkage;
98 }; 116 };
99 117
100 /// Models a function declaration. This includes the type signature of the 118 /// Models a function declaration. This includes the type signature of the
101 /// function, its calling conventions, and its linkage. 119 /// function, its calling conventions, and its linkage.
102 class FunctionDeclaration : public GlobalDeclaration { 120 class FunctionDeclaration : public GlobalDeclaration {
103 FunctionDeclaration() = delete; 121 FunctionDeclaration() = delete;
104 FunctionDeclaration(const FunctionDeclaration &) = delete; 122 FunctionDeclaration(const FunctionDeclaration &) = delete;
(...skipping 12 matching lines...) Expand all
117 llvm::CallingConv::ID getCallingConv() const { return CallingConv; } 135 llvm::CallingConv::ID getCallingConv() const { return CallingConv; }
118 /// isProto implies that there isn't a (local) definition for the function. 136 /// isProto implies that there isn't a (local) definition for the function.
119 bool isProto() const { return IsProto; } 137 bool isProto() const { return IsProto; }
120 static bool classof(const GlobalDeclaration *Addr) { 138 static bool classof(const GlobalDeclaration *Addr) {
121 return Addr->getKind() == FunctionDeclarationKind; 139 return Addr->getKind() == FunctionDeclarationKind;
122 } 140 }
123 void dumpType(Ostream &Stream) const final; 141 void dumpType(Ostream &Stream) const final;
124 void dump(GlobalContext *Ctx, Ostream &Stream) const final; 142 void dump(GlobalContext *Ctx, Ostream &Stream) const final;
125 bool getSuppressMangling() const final { return isExternal() && IsProto; } 143 bool getSuppressMangling() const final { return isExternal() && IsProto; }
126 144
145 /// Returns true if linkage is correct for the function declaration.
146 bool verifyLinkageCorrect(const GlobalContext *Ctx) const {
147 if (isPNaClABIExternalName() || isIntrinsicName(Ctx))
148 return Linkage == llvm::GlobalValue::ExternalLinkage;
149 return verifyLinkageDefault(Ctx);
150 }
151
127 private: 152 private:
128 const Ice::FuncSigType Signature; 153 const Ice::FuncSigType Signature;
129 llvm::CallingConv::ID CallingConv; 154 llvm::CallingConv::ID CallingConv;
130 bool IsProto; 155 bool IsProto;
131 156
132 FunctionDeclaration(const FuncSigType &Signature, 157 FunctionDeclaration(const FuncSigType &Signature,
133 llvm::CallingConv::ID CallingConv, 158 llvm::CallingConv::ID CallingConv,
134 llvm::GlobalValue::LinkageTypes Linkage, bool IsProto) 159 llvm::GlobalValue::LinkageTypes Linkage, bool IsProto)
135 : GlobalDeclaration(FunctionDeclarationKind, Linkage), 160 : GlobalDeclaration(FunctionDeclarationKind, Linkage),
136 Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {} 161 Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {}
162
163 bool isPNaClABIExternalName() const {
164 const char *Name = getName().c_str();
165 return strcmp(Name, "_start") == 0 || strcmp(Name, "__pnacl_pso_root") == 0;
166 }
167
168 bool isIntrinsicName(const GlobalContext *Ctx) const {
169 if (!hasName())
170 return false;
171 bool BadIntrinsic;
172 return Ctx->getIntrinsicsInfo().find(getName(), BadIntrinsic) &&
173 !BadIntrinsic;
174 }
137 }; 175 };
138 176
139 /// Models a global variable declaration, and its initializers. 177 /// Models a global variable declaration, and its initializers.
140 class VariableDeclaration : public GlobalDeclaration { 178 class VariableDeclaration : public GlobalDeclaration {
141 VariableDeclaration(const VariableDeclaration &) = delete; 179 VariableDeclaration(const VariableDeclaration &) = delete;
142 VariableDeclaration &operator=(const VariableDeclaration &) = delete; 180 VariableDeclaration &operator=(const VariableDeclaration &) = delete;
143 181
144 public: 182 public:
145 /// Base class for a global variable initializer. 183 /// Base class for a global variable initializer.
146 class Initializer { 184 class Initializer {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 HasInitializer = true; 340 HasInitializer = true;
303 } 341 }
304 342
305 /// Prints out type for initializer associated with the declaration to Stream. 343 /// Prints out type for initializer associated with the declaration to Stream.
306 void dumpType(Ostream &Stream) const final; 344 void dumpType(Ostream &Stream) const final;
307 345
308 /// Prints out the definition of the global variable declaration (including 346 /// Prints out the definition of the global variable declaration (including
309 /// initialization). 347 /// initialization).
310 void dump(GlobalContext *Ctx, Ostream &Stream) const final; 348 void dump(GlobalContext *Ctx, Ostream &Stream) const final;
311 349
350 /// Returns true if linkage is correct for the variable declaration.
351 bool verifyLinkageCorrect(const GlobalContext *Ctx) const {
352 return verifyLinkageDefault(Ctx);
353 }
354
312 static bool classof(const GlobalDeclaration *Addr) { 355 static bool classof(const GlobalDeclaration *Addr) {
313 return Addr->getKind() == VariableDeclarationKind; 356 return Addr->getKind() == VariableDeclarationKind;
314 } 357 }
315 358
316 bool getSuppressMangling() const final { 359 bool getSuppressMangling() const final {
317 if (ForceSuppressMangling) 360 if (ForceSuppressMangling)
318 return true; 361 return true;
319 return isExternal() && !hasInitializer(); 362 return isExternal() && !hasInitializer();
320 } 363 }
321 364
(...skipping 29 matching lines...) Expand all
351 template <class StreamType> 394 template <class StreamType>
352 inline StreamType &operator<<(StreamType &Stream, 395 inline StreamType &operator<<(StreamType &Stream,
353 const GlobalDeclaration &Addr) { 396 const GlobalDeclaration &Addr) {
354 Addr.dump(Stream); 397 Addr.dump(Stream);
355 return Stream; 398 return Stream;
356 } 399 }
357 400
358 } // end of namespace Ice 401 } // end of namespace Ice
359 402
360 #endif // SUBZERO_SRC_ICEGLOBALINITS_H 403 #endif // SUBZERO_SRC_ICEGLOBALINITS_H
OLDNEW
« 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