aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-05-16 11:26:34 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-05-16 11:26:34 -0700
commit4de54e3bece9a51a69bd46076acaa7746c1fa996 (patch)
tree29e8c9012bc808aa805c59799290578aeae0ab6c
parentce33f9c21230d619b2b5d42358592f204410eab4 (diff)
when not aliasing tables, keep them all at full size to avoid aliasing through the &M mask in a small table
-rw-r--r--src/modules.js11
-rwxr-xr-xtests/runner.py13
2 files changed, 19 insertions, 5 deletions
diff --git a/src/modules.js b/src/modules.js
index 8e029b27..e4093078 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -301,6 +301,7 @@ var Functions = {
}
var generated = false;
var wrapped = {};
+ var maxTable = 0;
for (var t in tables) {
if (t == 'pre') continue;
generated = true;
@@ -355,13 +356,21 @@ var Functions = {
j += 10;
}
}
+ maxTable = Math.max(maxTable, table.length);
+ }
+ if (ASM_JS) maxTable = ceilPowerOfTwo(maxTable);
+ for (var t in tables) {
+ if (t == 'pre') continue;
+ var table = tables[t];
if (ASM_JS) {
// asm function table mask must be power of two
- var fullSize = ceilPowerOfTwo(table.length);
+ // if nonaliasing, then standardize function table size, to avoid aliasing pointers through the &M mask (in a small table using a big index)
+ var fullSize = ALIASING_FUNCTION_POINTERS ? ceilPowerOfTwo(table.length) : maxTable;
for (var i = table.length; i < fullSize; i++) {
table[i] = 0;
}
}
+ // finalize table
var indices = table.toString().replace('"', '');
if (BUILD_AS_SHARED_LIB) {
// Shared libraries reuse the parent's function table.
diff --git a/tests/runner.py b/tests/runner.py
index b802a68f..1ff917d0 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -7729,15 +7729,20 @@ void*:16
assert 'asm2g' in test_modes
if self.run_name == 'asm2g':
- original = open('src.cpp.o.js').read()
results = {}
- results[Settings.ALIASING_FUNCTION_POINTERS] = len(open('src.cpp.o.js').read())
+ original = open('src.cpp.o.js').read()
+ results[Settings.ALIASING_FUNCTION_POINTERS] = len(original)
Settings.ALIASING_FUNCTION_POINTERS = 1 - Settings.ALIASING_FUNCTION_POINTERS
self.do_run(path_from_root('tests', 'cubescript'), '*\nTemp is 33\n9\n5\nhello, everyone\n*', main_file='command.cpp')
- results[Settings.ALIASING_FUNCTION_POINTERS] = len(open('src.cpp.o.js').read())
+ final = open('src.cpp.o.js').read()
+ results[Settings.ALIASING_FUNCTION_POINTERS] = len(final)
open('original.js', 'w').write(original)
print results
- assert results[1] < results[0]
+ assert results[1] < 0.99*results[0]
+ assert ' & 3]()' in original, 'small function table exists'
+ assert ' & 3]()' not in final, 'small function table does not exist'
+ assert ' & 255]()' not in original, 'big function table does not exist'
+ assert ' & 255]()' in final, 'big function table exists'
def test_gcc_unmangler(self):
Settings.NAMED_GLOBALS = 1 # test coverage for this