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

Side by Side Diff: src/IceGlobalInits.h

Issue 1774383002: PNaCl Dynamic Linking: Force __pnacl_pso_root to be an external declaration. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@fixes
Patch Set: Updated external declaration test Created 4 years, 9 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 | « no previous file | 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 GlobalDeclarationKind getKind() const { return Kind; } 64 GlobalDeclarationKind getKind() const { return Kind; }
65 const IceString &getName() const { return Name; } 65 const IceString &getName() const { return Name; }
66 void setName(const IceString &NewName) { 66 void setName(const IceString &NewName) {
67 Name = getSuppressMangling() ? NewName : mangleName(NewName); 67 Name = getSuppressMangling() ? NewName : mangleName(NewName);
68 } 68 }
69 bool hasName() const { return !Name.empty(); } 69 bool hasName() const { return !Name.empty(); }
70 bool isInternal() const { 70 bool isInternal() const {
71 return Linkage == llvm::GlobalValue::InternalLinkage; 71 return Linkage == llvm::GlobalValue::InternalLinkage;
72 } 72 }
73 llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; } 73 llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; }
74 void setLinkage(llvm::GlobalValue::LinkageTypes L) {
75 assert(!hasName());
76 Linkage = L;
77 }
74 bool isExternal() const { 78 bool isExternal() const {
75 return Linkage == llvm::GlobalValue::ExternalLinkage; 79 return Linkage == llvm::GlobalValue::ExternalLinkage;
76 } 80 }
77 virtual ~GlobalDeclaration() = default; 81 virtual ~GlobalDeclaration() = default;
78 82
79 /// Prints out type of the global declaration. 83 /// Prints out type of the global declaration.
80 virtual void dumpType(Ostream &Stream) const = 0; 84 virtual void dumpType(Ostream &Stream) const = 0;
81 85
82 /// Prints out the global declaration. 86 /// Prints out the global declaration.
83 virtual void dump(Ostream &Stream) const = 0; 87 virtual void dump(Ostream &Stream) const = 0;
84 88
85 /// Returns true if when emitting names, we should suppress mangling. 89 /// Returns true if when emitting names, we should suppress mangling.
86 virtual bool getSuppressMangling() const = 0; 90 virtual bool getSuppressMangling() const = 0;
87 91
88 /// Returns textual name of linkage. 92 /// Returns textual name of linkage.
89 const char *getLinkageName() const { 93 const char *getLinkageName() const {
90 return isInternal() ? "internal" : "external"; 94 return isInternal() ? "internal" : "external";
91 } 95 }
92 96
97 /// Returns true if the name of this GlobalDeclaration indicates that it
98 /// should have ExternalLinkage (as a special case).
99 virtual bool isPNaClABIExternalName(const IceString &Name) const = 0;
100
93 protected: 101 protected:
94 GlobalDeclaration(GlobalDeclarationKind Kind, 102 GlobalDeclaration(GlobalDeclarationKind Kind,
95 llvm::GlobalValue::LinkageTypes Linkage) 103 llvm::GlobalValue::LinkageTypes Linkage)
96 : Kind(Kind), Linkage(Linkage) {} 104 : Kind(Kind), Linkage(Linkage) {}
97 105
98 /// Returns true if linkage is defined correctly for the global declaration, 106 /// Returns true if linkage is defined correctly for the global declaration,
99 /// based on default rules. 107 /// based on default rules.
100 bool verifyLinkageDefault(const GlobalContext *Ctx) const { 108 bool verifyLinkageDefault(const GlobalContext *Ctx) const {
101 switch (Linkage) { 109 switch (Linkage) {
102 default: 110 default:
103 return false; 111 return false;
104 case llvm::GlobalValue::InternalLinkage: 112 case llvm::GlobalValue::InternalLinkage:
105 return true; 113 return true;
106 case llvm::GlobalValue::ExternalLinkage: 114 case llvm::GlobalValue::ExternalLinkage:
107 return Ctx->getFlags().getAllowExternDefinedSymbols(); 115 return Ctx->getFlags().getAllowExternDefinedSymbols();
108 } 116 }
109 } 117 }
110 118
111 const GlobalDeclarationKind Kind; 119 const GlobalDeclarationKind Kind;
112 const llvm::GlobalValue::LinkageTypes Linkage; 120 llvm::GlobalValue::LinkageTypes Linkage;
113 IceString Name; 121 IceString Name;
114 }; 122 };
115 123
116 /// Models a function declaration. This includes the type signature of the 124 /// Models a function declaration. This includes the type signature of the
117 /// function, its calling conventions, and its linkage. 125 /// function, its calling conventions, and its linkage.
118 class FunctionDeclaration : public GlobalDeclaration { 126 class FunctionDeclaration : public GlobalDeclaration {
119 FunctionDeclaration() = delete; 127 FunctionDeclaration() = delete;
120 FunctionDeclaration(const FunctionDeclaration &) = delete; 128 FunctionDeclaration(const FunctionDeclaration &) = delete;
121 FunctionDeclaration &operator=(const FunctionDeclaration &) = delete; 129 FunctionDeclaration &operator=(const FunctionDeclaration &) = delete;
122 130
(...skipping 12 matching lines...) Expand all
135 bool isProto() const { return IsProto; } 143 bool isProto() const { return IsProto; }
136 static bool classof(const GlobalDeclaration *Addr) { 144 static bool classof(const GlobalDeclaration *Addr) {
137 return Addr->getKind() == FunctionDeclarationKind; 145 return Addr->getKind() == FunctionDeclarationKind;
138 } 146 }
139 void dumpType(Ostream &Stream) const final; 147 void dumpType(Ostream &Stream) const final;
140 void dump(Ostream &Stream) const final; 148 void dump(Ostream &Stream) const final;
141 bool getSuppressMangling() const final { return isExternal() && IsProto; } 149 bool getSuppressMangling() const final { return isExternal() && IsProto; }
142 150
143 /// Returns true if linkage is correct for the function declaration. 151 /// Returns true if linkage is correct for the function declaration.
144 bool verifyLinkageCorrect(const GlobalContext *Ctx) const { 152 bool verifyLinkageCorrect(const GlobalContext *Ctx) const {
145 if (isPNaClABIExternalName() || isIntrinsicName(Ctx)) 153 if (isPNaClABIExternalName(getName()) || isIntrinsicName(Ctx)) {
146 return Linkage == llvm::GlobalValue::ExternalLinkage; 154 return Linkage == llvm::GlobalValue::ExternalLinkage;
147 return verifyLinkageDefault(Ctx); 155 } else {
156 return verifyLinkageDefault(Ctx);
157 }
148 } 158 }
149 159
150 /// Validates that the type signature of the function is correct. Returns true 160 /// Validates that the type signature of the function is correct. Returns true
151 /// if valid. 161 /// if valid.
152 bool validateTypeSignature(const GlobalContext *Ctx) const { 162 bool validateTypeSignature(const GlobalContext *Ctx) const {
153 bool IsIntrinsic; 163 bool IsIntrinsic;
154 if (const Intrinsics::FullIntrinsicInfo *Info = 164 if (const Intrinsics::FullIntrinsicInfo *Info =
155 getIntrinsicInfo(Ctx, &IsIntrinsic)) 165 getIntrinsicInfo(Ctx, &IsIntrinsic))
156 return validateIntrinsicTypeSignature(Info); 166 return validateIntrinsicTypeSignature(Info);
157 return !IsIntrinsic && validateRegularTypeSignature(); 167 return !IsIntrinsic && validateRegularTypeSignature();
(...skipping 19 matching lines...) Expand all
177 const Ice::FuncSigType Signature; 187 const Ice::FuncSigType Signature;
178 llvm::CallingConv::ID CallingConv; 188 llvm::CallingConv::ID CallingConv;
179 const bool IsProto; 189 const bool IsProto;
180 190
181 FunctionDeclaration(const FuncSigType &Signature, 191 FunctionDeclaration(const FuncSigType &Signature,
182 llvm::CallingConv::ID CallingConv, 192 llvm::CallingConv::ID CallingConv,
183 llvm::GlobalValue::LinkageTypes Linkage, bool IsProto) 193 llvm::GlobalValue::LinkageTypes Linkage, bool IsProto)
184 : GlobalDeclaration(FunctionDeclarationKind, Linkage), 194 : GlobalDeclaration(FunctionDeclarationKind, Linkage),
185 Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {} 195 Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {}
186 196
187 bool isPNaClABIExternalName() const { 197 bool isPNaClABIExternalName(const IceString &Name) const override {
188 const char *Name = getName().c_str(); 198 return Name == "_start";
189 return strcmp(Name, "_start") == 0 || strcmp(Name, "__pnacl_pso_root") == 0;
190 } 199 }
191 200
192 bool isIntrinsicName(const GlobalContext *Ctx) const { 201 bool isIntrinsicName(const GlobalContext *Ctx) const {
193 bool IsIntrinsic; 202 bool IsIntrinsic;
194 getIntrinsicInfo(Ctx, &IsIntrinsic); 203 getIntrinsicInfo(Ctx, &IsIntrinsic);
195 return IsIntrinsic; 204 return IsIntrinsic;
196 } 205 }
197 206
198 bool validateRegularTypeSignature() const; 207 bool validateRegularTypeSignature() const;
199 208
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 const bool SameMangling = (OldSuppressMangling == getSuppressMangling()); 416 const bool SameMangling = (OldSuppressMangling == getSuppressMangling());
408 (void)SameMangling; 417 (void)SameMangling;
409 assert(!Name.empty() || SameMangling); 418 assert(!Name.empty() || SameMangling);
410 } 419 }
411 420
412 /// Prints out type for initializer associated with the declaration to Stream. 421 /// Prints out type for initializer associated with the declaration to Stream.
413 void dumpType(Ostream &Stream) const final; 422 void dumpType(Ostream &Stream) const final;
414 423
415 /// Prints out the definition of the global variable declaration (including 424 /// Prints out the definition of the global variable declaration (including
416 /// initialization). 425 /// initialization).
417 virtual void dump(Ostream &Stream) const; 426 virtual void dump(Ostream &Stream) const override;
418 427
419 /// Returns true if linkage is correct for the variable declaration. 428 /// Returns true if linkage is correct for the variable declaration.
420 bool verifyLinkageCorrect(const GlobalContext *Ctx) const { 429 bool verifyLinkageCorrect(const GlobalContext *Ctx) const {
430 if (isPNaClABIExternalName(getName())) {
431 return Linkage == llvm::GlobalValue::ExternalLinkage;
432 }
421 return verifyLinkageDefault(Ctx); 433 return verifyLinkageDefault(Ctx);
422 } 434 }
423 435
424 static bool classof(const GlobalDeclaration *Addr) { 436 static bool classof(const GlobalDeclaration *Addr) {
425 return Addr->getKind() == VariableDeclarationKind; 437 return Addr->getKind() == VariableDeclarationKind;
426 } 438 }
427 439
428 bool getSuppressMangling() const final { 440 bool getSuppressMangling() const final {
429 if (ForceSuppressMangling) 441 if (ForceSuppressMangling)
430 return true; 442 return true;
431 return isExternal() && !hasInitializer(); 443 return isExternal() && !hasInitializer();
432 } 444 }
433 445
434 void discardInitializers() { Initializers = nullptr; } 446 void discardInitializers() { Initializers = nullptr; }
435 447
448 bool isPNaClABIExternalName(const IceString &Name) const override {
449 return Name == "__pnacl_pso_root";
450 }
451
436 private: 452 private:
437 /// List of initializers for the declared variable. 453 /// List of initializers for the declared variable.
438 std::unique_ptr<InitializerListType> Initializers; 454 std::unique_ptr<InitializerListType> Initializers;
439 bool HasInitializer = false; 455 bool HasInitializer = false;
440 /// The alignment of the declared variable. 456 /// The alignment of the declared variable.
441 uint32_t Alignment = 0; 457 uint32_t Alignment = 0;
442 /// True if a declared (global) constant. 458 /// True if a declared (global) constant.
443 bool IsConstant = false; 459 bool IsConstant = false;
444 /// If set to true, force getSuppressMangling() to return true. 460 /// If set to true, force getSuppressMangling() to return true.
445 const bool ForceSuppressMangling; 461 const bool ForceSuppressMangling;
(...skipping 15 matching lines...) Expand all
461 template <class StreamType> 477 template <class StreamType>
462 inline StreamType &operator<<(StreamType &Stream, 478 inline StreamType &operator<<(StreamType &Stream,
463 const GlobalDeclaration &Addr) { 479 const GlobalDeclaration &Addr) {
464 Addr.dump(Stream); 480 Addr.dump(Stream);
465 return Stream; 481 return Stream;
466 } 482 }
467 483
468 } // end of namespace Ice 484 } // end of namespace Ice
469 485
470 #endif // SUBZERO_SRC_ICEGLOBALINITS_H 486 #endif // SUBZERO_SRC_ICEGLOBALINITS_H
OLDNEW
« no previous file with comments | « no previous file | src/PNaClTranslator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698