Make sure that all globals are internal, except for "start" functions.
The existing code, when run on a fuzzed example, generates a runtime
assertion. The reason for this is that the input defines "memmove" as
an external global. However, the code generator can generate calls to
"memmove" which assumes it is internal (see PNaCl ABI). As a result,
the assertion that checks that global names are unique (for memmove)
fails.
This code fixes the problem by checking that global names are
internal, unless they are one of the "start" functions,
or the function is an intrinsic. To allow for
non-PNaCl ABI input, a flag was added to allow functions to be
external. However, in such cases the external can't be one of
Subzero's runtime helper functions.
BUG= https://code.google.com/p/nativeclient/issues/detail?id=4330
R=jpp@chromium.org, stichnot@chromium.org
Review URL: https://codereview.chromium.org/1387963002 .
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp
index c1a5919..7124da0 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -475,7 +475,16 @@
// Converts function declarations into constant value IDs.
void createValueIDsForFunctions() {
+ Ice::GlobalContext *Ctx = getTranslator().getContext();
for (const Ice::FunctionDeclaration *Func : FunctionDeclarations) {
+ if (!Func->verifyLinkageCorrect(Ctx)) {
+ std::string Buffer;
+ raw_string_ostream StrBuf(Buffer);
+ StrBuf << "Function " << Func->getName()
+ << " has incorrect linkage: " << Func->getLinkageName();
+ Error(StrBuf.str());
+ continue;
+ }
Ice::Constant *C = nullptr;
if (!isIRGenerationDisabled()) {
C = getConstantSym(Func->getName(), Func->getSuppressMangling(),
@@ -487,7 +496,15 @@
// Converts global variable declarations into constant value IDs.
void createValueIDsForGlobalVars() {
+ Ice::GlobalContext *Ctx = getTranslator().getContext();
for (const Ice::VariableDeclaration *Decl : *VariableDeclarations) {
+ if (!Decl->verifyLinkageCorrect(Ctx)) {
+ std::string Buffer;
+ raw_string_ostream StrBuf(Buffer);
+ StrBuf << "Global " << Decl->getName()
+ << " has incorrect linkage: " << Decl->getLinkageName();
+ Error(StrBuf.str());
+ }
Ice::Constant *C = nullptr;
if (!isIRGenerationDisabled()) {
C = getConstantSym(Decl->getName(), Decl->getSuppressMangling(),