Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 869c814

Browse files
committed
emscripten-no-aliasing-function-pointers option
1 parent ff4ab93 commit 869c814

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/Target/JSBackend/JSBackend.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ EmscriptenAssertions("emscripten-assertions",
8383
cl::desc("Additional JS-specific assertions (see emscripten ASSERTIONS)"),
8484
cl::init(0));
8585

86+
static cl::opt<bool>
87+
NoAliasingFunctionPointers("emscripten-no-aliasing-function-pointers",
88+
cl::desc("Forces function pointers to not alias (this is more correct, but rarely needed, and has the cost of much larger function tables; it is useful for debugging though; see emscripten ALIASING_FUNCTION_POINTERS option)"),
89+
cl::init(false));
90+
8691
extern "C" void LLVMInitializeJSBackendTarget() {
8792
// Register the target.
8893
RegisterTargetMachine<JSTargetMachine> X(TheJSBackendTarget);
@@ -120,6 +125,7 @@ namespace {
120125
formatted_raw_ostream &Out;
121126
const Module *TheModule;
122127
unsigned UniqueNum;
128+
unsigned NextFunctionIndex; // used with NoAliasingFunctionPointers
123129
ValueMap ValueNames;
124130
VarMap UsedVars;
125131
AllocaManager Allocas;
@@ -149,7 +155,7 @@ namespace {
149155
public:
150156
static char ID;
151157
JSWriter(formatted_raw_ostream &o, CodeGenOpt::Level OptLevel)
152-
: ModulePass(ID), Out(o), UniqueNum(0), CanValidate(true), UsesSIMD(false), InvokeState(0),
158+
: ModulePass(ID), Out(o), UniqueNum(0), NextFunctionIndex(0), CanValidate(true), UsesSIMD(false), InvokeState(0),
153159
OptLevel(OptLevel) {}
154160

155161
virtual const char *getPassName() const { return "JavaScript backend"; }
@@ -290,12 +296,18 @@ namespace {
290296
if (IndexedFunctions.find(Name) != IndexedFunctions.end()) return IndexedFunctions[Name];
291297
std::string Sig = getFunctionSignature(F->getFunctionType(), &Name);
292298
FunctionTable& Table = ensureFunctionTable(F->getFunctionType());
299+
if (NoAliasingFunctionPointers) {
300+
while (Table.size() < NextFunctionIndex) Table.push_back("0");
301+
}
293302
unsigned Alignment = F->getAlignment() || 1; // XXX this is wrong, it's always 1. but, that's fine in the ARM-like ABI we have which allows unaligned functions.
294303
// the one risk is if someone forces a function to be aligned, and relies on that.
295304
while (Table.size() % Alignment) Table.push_back("0");
296305
unsigned Index = Table.size();
297306
Table.push_back(Name);
298307
IndexedFunctions[Name] = Index;
308+
if (NoAliasingFunctionPointers) {
309+
NextFunctionIndex = Index+1;
310+
}
299311

300312
// invoke the callHandler for this, if there is one. the function may only be indexed but never called directly, and we may need to do things in the handler
301313
CallHandlerMap::const_iterator CH = CallHandlers.find(Name);

0 commit comments

Comments
 (0)