Commit 0a3c523d by Sean Klein

PNaCl Dynamic Linking: Force __pnacl_pso_root to be an external declaration.

This CL updates "isPNaClABIExternalName" -- Subzero checked for the symbol "__pnacl_pso_root" as a function, but it is a declaration, and should be checked as one. Additionally, when the PNaClTranslator is verifying the linkage of declarations, allow "__pnacl_pso_root" to be flipped to external as a special case. Previously, translating a pso with --use-sz caused the warning: "cannot find entry symbol '__pnacl_pso_root'". That warning is removed with this CL. Fixes revert from https://codereview.chromium.org/1745783002/ TEST=external_declaration.ll BUG=https://bugs.chromium.org/p/nativeclient/issues/detail?id=4351 R=kschimpf@google.com, stichnot@chromium.org Review URL: https://codereview.chromium.org/1774383002 .
parent 4abbb59c
...@@ -71,6 +71,10 @@ public: ...@@ -71,6 +71,10 @@ public:
return Linkage == llvm::GlobalValue::InternalLinkage; return Linkage == llvm::GlobalValue::InternalLinkage;
} }
llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; } llvm::GlobalValue::LinkageTypes getLinkage() const { return Linkage; }
void setLinkage(llvm::GlobalValue::LinkageTypes L) {
assert(!hasName());
Linkage = L;
}
bool isExternal() const { bool isExternal() const {
return Linkage == llvm::GlobalValue::ExternalLinkage; return Linkage == llvm::GlobalValue::ExternalLinkage;
} }
...@@ -90,6 +94,10 @@ public: ...@@ -90,6 +94,10 @@ public:
return isInternal() ? "internal" : "external"; return isInternal() ? "internal" : "external";
} }
/// Returns true if the name of this GlobalDeclaration indicates that it
/// should have ExternalLinkage (as a special case).
virtual bool isPNaClABIExternalName(const IceString &Name) const = 0;
protected: protected:
GlobalDeclaration(GlobalDeclarationKind Kind, GlobalDeclaration(GlobalDeclarationKind Kind,
llvm::GlobalValue::LinkageTypes Linkage) llvm::GlobalValue::LinkageTypes Linkage)
...@@ -109,7 +117,7 @@ protected: ...@@ -109,7 +117,7 @@ protected:
} }
const GlobalDeclarationKind Kind; const GlobalDeclarationKind Kind;
const llvm::GlobalValue::LinkageTypes Linkage; llvm::GlobalValue::LinkageTypes Linkage;
IceString Name; IceString Name;
}; };
...@@ -142,9 +150,11 @@ public: ...@@ -142,9 +150,11 @@ public:
/// Returns true if linkage is correct for the function declaration. /// Returns true if linkage is correct for the function declaration.
bool verifyLinkageCorrect(const GlobalContext *Ctx) const { bool verifyLinkageCorrect(const GlobalContext *Ctx) const {
if (isPNaClABIExternalName() || isIntrinsicName(Ctx)) if (isPNaClABIExternalName(getName()) || isIntrinsicName(Ctx)) {
return Linkage == llvm::GlobalValue::ExternalLinkage; return Linkage == llvm::GlobalValue::ExternalLinkage;
return verifyLinkageDefault(Ctx); } else {
return verifyLinkageDefault(Ctx);
}
} }
/// Validates that the type signature of the function is correct. Returns true /// Validates that the type signature of the function is correct. Returns true
...@@ -184,9 +194,8 @@ private: ...@@ -184,9 +194,8 @@ private:
: GlobalDeclaration(FunctionDeclarationKind, Linkage), : GlobalDeclaration(FunctionDeclarationKind, Linkage),
Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {} Signature(Signature), CallingConv(CallingConv), IsProto(IsProto) {}
bool isPNaClABIExternalName() const { bool isPNaClABIExternalName(const IceString &Name) const override {
const char *Name = getName().c_str(); return Name == "_start";
return strcmp(Name, "_start") == 0 || strcmp(Name, "__pnacl_pso_root") == 0;
} }
bool isIntrinsicName(const GlobalContext *Ctx) const { bool isIntrinsicName(const GlobalContext *Ctx) const {
...@@ -414,10 +423,13 @@ public: ...@@ -414,10 +423,13 @@ public:
/// Prints out the definition of the global variable declaration (including /// Prints out the definition of the global variable declaration (including
/// initialization). /// initialization).
virtual void dump(Ostream &Stream) const; virtual void dump(Ostream &Stream) const override;
/// Returns true if linkage is correct for the variable declaration. /// Returns true if linkage is correct for the variable declaration.
bool verifyLinkageCorrect(const GlobalContext *Ctx) const { bool verifyLinkageCorrect(const GlobalContext *Ctx) const {
if (isPNaClABIExternalName(getName())) {
return Linkage == llvm::GlobalValue::ExternalLinkage;
}
return verifyLinkageDefault(Ctx); return verifyLinkageDefault(Ctx);
} }
...@@ -433,6 +445,10 @@ public: ...@@ -433,6 +445,10 @@ public:
void discardInitializers() { Initializers = nullptr; } void discardInitializers() { Initializers = nullptr; }
bool isPNaClABIExternalName(const IceString &Name) const override {
return Name == "__pnacl_pso_root";
}
private: private:
/// List of initializers for the declared variable. /// List of initializers for the declared variable.
std::unique_ptr<InitializerListType> Initializers; std::unique_ptr<InitializerListType> Initializers;
......
...@@ -3043,8 +3043,17 @@ private: ...@@ -3043,8 +3043,17 @@ private:
void ModuleValuesymtabParser::setValueName(NaClBcIndexSize_t Index, void ModuleValuesymtabParser::setValueName(NaClBcIndexSize_t Index,
StringType &Name) { StringType &Name) {
Context->getGlobalDeclarationByID(Index) Ice::GlobalDeclaration *Decl = Context->getGlobalDeclarationByID(Index);
->setName(StringRef(Name.data(), Name.size())); if (llvm::isa<Ice::VariableDeclaration>(Decl) &&
Decl->isPNaClABIExternalName(Name.str())) {
// Force linkage of (specific) Global Variables be external for the PNaCl
// ABI. PNaCl bitcode has a linkage field for Functions, but not for
// GlobalVariables (because the latter is not needed for pexes, so it has
// been removed).
Decl->setLinkage(llvm::GlobalValue::ExternalLinkage);
}
Decl->setName(StringRef(Name.data(), Name.size()));
} }
void ModuleValuesymtabParser::setBbName(NaClBcIndexSize_t Index, void ModuleValuesymtabParser::setBbName(NaClBcIndexSize_t Index,
......
; Tests that any symbols with special names have specially treated linkage.
; RUN: %if --need=allow_dump --command %p2i -i %s --filetype=asm \
; RUN: --args -nonsfi=0 \
; RUN: | %if --need=allow_dump --command FileCheck %s
; Verify that "__pnacl_pso_root", a specially named symbol, is made global, but
; other global variables are not.
@__pnacl_pso_root = constant [4 x i8] c"abcd";
@__pnacl_pso_not_root = constant [4 x i8] c"efgh";
; CHECK: .globl __pnacl_pso_root
; CHECK-NOT: .globl __pnacl_pso_not_root
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment