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

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: 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 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 protected: 90 protected:
91 GlobalDeclaration(GlobalDeclarationKind Kind, 91 GlobalDeclaration(GlobalDeclarationKind Kind,
92 llvm::GlobalValue::LinkageTypes Linkage) 92 llvm::GlobalValue::LinkageTypes Linkage)
93 : Kind(Kind), Linkage(Linkage) {} 93 : Kind(Kind), Linkage(Linkage) {}
94 94
95 /// Returns true if linkage is defined correctly for the global declaration,
96 /// based on default rules.
97 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.
98 switch (Linkage) {
99 default:
100 return false;
101 case llvm::GlobalValue::InternalLinkage:
102 return true;
103 case llvm::GlobalValue::ExternalLinkage:
104 return Ctx->getFlags().getAllowExternDefinedSymbols();
105 }
106 }
107
95 const GlobalDeclarationKind Kind; 108 const GlobalDeclarationKind Kind;
96 IceString Name; 109 IceString Name;
97 llvm::GlobalValue::LinkageTypes Linkage; 110 llvm::GlobalValue::LinkageTypes Linkage;
98 }; 111 };
99 112
100 /// Models a function declaration. This includes the type signature of the 113 /// Models a function declaration. This includes the type signature of the
101 /// function, its calling conventions, and its linkage. 114 /// function, its calling conventions, and its linkage.
102 class FunctionDeclaration : public GlobalDeclaration { 115 class FunctionDeclaration : public GlobalDeclaration {
103 FunctionDeclaration() = delete; 116 FunctionDeclaration() = delete;
104 FunctionDeclaration(const FunctionDeclaration &) = delete; 117 FunctionDeclaration(const FunctionDeclaration &) = delete;
(...skipping 12 matching lines...) Expand all
117 llvm::CallingConv::ID getCallingConv() const { return CallingConv; } 130 llvm::CallingConv::ID getCallingConv() const { return CallingConv; }
118 /// isProto implies that there isn't a (local) definition for the function. 131 /// isProto implies that there isn't a (local) definition for the function.
119 bool isProto() const { return IsProto; } 132 bool isProto() const { return IsProto; }
120 static bool classof(const GlobalDeclaration *Addr) { 133 static bool classof(const GlobalDeclaration *Addr) {
121 return Addr->getKind() == FunctionDeclarationKind; 134 return Addr->getKind() == FunctionDeclarationKind;
122 } 135 }
123 void dumpType(Ostream &Stream) const final; 136 void dumpType(Ostream &Stream) const final;
124 void dump(GlobalContext *Ctx, Ostream &Stream) const final; 137 void dump(GlobalContext *Ctx, Ostream &Stream) const final;
125 bool getSuppressMangling() const final { return isExternal() && IsProto; } 138 bool getSuppressMangling() const final { return isExternal() && IsProto; }
126 139
140 /// Returns true if linkage is correct for the function declaration.
141 bool verifyLinkageCorrect(GlobalContext *Ctx) const {
142 if (isPNaClABIExternalName() || isIntrinsicName(Ctx))
143 return Linkage == llvm::GlobalValue::ExternalLinkage;
144 return verifyLinkageDefault(Ctx);
145 }
146
127 private: 147 private:
128 const Ice::FuncSigType Signature; 148 const Ice::FuncSigType Signature;
129 llvm::CallingConv::ID CallingConv; 149 llvm::CallingConv::ID CallingConv;
130 bool IsProto; 150 bool IsProto;
131 151
132 FunctionDeclaration(const FuncSigType &Signature, 152 FunctionDeclaration(const FuncSigType &Signature,
133 llvm::CallingConv::ID CallingConv, 153 llvm::CallingConv::ID CallingConv,
134 llvm::GlobalValue::LinkageTypes Linkage, bool IsProto) 154 llvm::GlobalValue::LinkageTypes Linkage, bool IsProto)
135 : GlobalDeclaration(FunctionDeclarationKind, Linkage), 155 : GlobalDeclaration(FunctionDeclarationKind, Linkage),
136 Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {} 156 Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {}
157
158 bool isPNaClABIExternalName() const {
159 const char *Name = getName().c_str();
160 return strcmp(Name, "_start") == 0 || strcmp(Name, "__pnacl_pso_root") == 0;
161 }
162
163 bool isIntrinsicName(GlobalContext *Ctx) const {
164 if (!hasName()) return false;
Jim Stichnoth 2015/10/06 20:16:21 make format
Karl 2015/10/06 21:47:18 Done.
165 bool BadIntrinsic;
166 return Ctx->getIntrinsicsInfo().find(getName(), BadIntrinsic)
167 && !BadIntrinsic;
168 }
137 }; 169 };
138 170
139 /// Models a global variable declaration, and its initializers. 171 /// Models a global variable declaration, and its initializers.
140 class VariableDeclaration : public GlobalDeclaration { 172 class VariableDeclaration : public GlobalDeclaration {
141 VariableDeclaration(const VariableDeclaration &) = delete; 173 VariableDeclaration(const VariableDeclaration &) = delete;
142 VariableDeclaration &operator=(const VariableDeclaration &) = delete; 174 VariableDeclaration &operator=(const VariableDeclaration &) = delete;
143 175
144 public: 176 public:
145 /// Base class for a global variable initializer. 177 /// Base class for a global variable initializer.
146 class Initializer { 178 class Initializer {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 HasInitializer = true; 334 HasInitializer = true;
303 } 335 }
304 336
305 /// Prints out type for initializer associated with the declaration to Stream. 337 /// Prints out type for initializer associated with the declaration to Stream.
306 void dumpType(Ostream &Stream) const final; 338 void dumpType(Ostream &Stream) const final;
307 339
308 /// Prints out the definition of the global variable declaration (including 340 /// Prints out the definition of the global variable declaration (including
309 /// initialization). 341 /// initialization).
310 void dump(GlobalContext *Ctx, Ostream &Stream) const final; 342 void dump(GlobalContext *Ctx, Ostream &Stream) const final;
311 343
344 /// Returns true if linkage is correct for the variable declaration.
345 bool verifyLinkageCorrect(GlobalContext *Ctx) const {
346 return verifyLinkageDefault(Ctx);
347 }
348
312 static bool classof(const GlobalDeclaration *Addr) { 349 static bool classof(const GlobalDeclaration *Addr) {
313 return Addr->getKind() == VariableDeclarationKind; 350 return Addr->getKind() == VariableDeclarationKind;
314 } 351 }
315 352
316 bool getSuppressMangling() const final { 353 bool getSuppressMangling() const final {
317 if (ForceSuppressMangling) 354 if (ForceSuppressMangling)
318 return true; 355 return true;
319 return isExternal() && !hasInitializer(); 356 return isExternal() && !hasInitializer();
320 } 357 }
321 358
(...skipping 29 matching lines...) Expand all
351 template <class StreamType> 388 template <class StreamType>
352 inline StreamType &operator<<(StreamType &Stream, 389 inline StreamType &operator<<(StreamType &Stream,
353 const GlobalDeclaration &Addr) { 390 const GlobalDeclaration &Addr) {
354 Addr.dump(Stream); 391 Addr.dump(Stream);
355 return Stream; 392 return Stream;
356 } 393 }
357 394
358 } // end of namespace Ice 395 } // end of namespace Ice
359 396
360 #endif // SUBZERO_SRC_ICEGLOBALINITS_H 397 #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