aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJez Ng <me@jezng.com>2013-07-11 19:34:01 -0700
committerJez Ng <me@jezng.com>2013-07-11 20:37:58 -0700
commit470b7da45616f7c72794cf3ced71f21db2ebdc2c (patch)
tree66ea2d5aea7699a4b444e093ed666fc0b9ff71aa
parentc1e1d87bc3b9e249795543e44a1224c2f03154ce (diff)
Filter out unnamed_addr globals from symbol table.
-rwxr-xr-xemscripten.py6
-rw-r--r--src/intertyper.js2
-rw-r--r--src/jsifier.js2
-rwxr-xr-xtests/runner.py19
4 files changed, 25 insertions, 4 deletions
diff --git a/emscripten.py b/emscripten.py
index 921ab879..30c7a5ae 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -622,9 +622,11 @@ Runtime.stackRestore = function(top) { asm['stackRestore'](top) };
# Create symbol table for self-dlopen
if settings.get('LINKABLE'):
- GLOBAL_BASE = forwarded_json['Runtime']['GLOBAL_BASE']
- symbol_table = {k:v+8 for k,v in forwarded_json['Variables']['indexedGlobals'].iteritems()}
+ symbol_table = {k:v+forwarded_json['Runtime']['GLOBAL_BASE']
+ for k,v in forwarded_json['Variables']['indexedGlobals'].iteritems()
+ if forwarded_json['Variables']['globals'][k]['named']}
for raw in last_forwarded_json['Functions']['tables'].itervalues():
+ if raw == '': continue
table = raw[raw.find('[')+1:raw.find(']')].split(",")
symbol_table.update(map(lambda x: (x[1], x[0]),
filter(lambda x: x[1] != '0', enumerate(table))))
diff --git a/src/intertyper.js b/src/intertyper.js
index 94d937e1..abfbdacb 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -503,6 +503,7 @@ function intertyper(data, sidePass, baseLineNums) {
// variable
var ident = item.tokens[0].text;
var private_ = findTokenText(item, 'private') >= 0 || findTokenText(item, 'internal') >= 0;
+ var named = findTokenText(item, 'unnamed_addr') < 0;
cleanOutTokens(LLVM.GLOBAL_MODIFIERS, item.tokens, [2, 3]);
var external = false;
if (item.tokens[2].text === 'external') {
@@ -516,6 +517,7 @@ function intertyper(data, sidePass, baseLineNums) {
type: item.tokens[2].text,
external: external,
private_: private_,
+ named: named,
lineNum: item.lineNum
};
if (!NAMED_GLOBALS) {
diff --git a/src/jsifier.js b/src/jsifier.js
index bc073aaa..6faea2b4 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -286,6 +286,8 @@ function JSify(data, functionsOnly, givenFunctions) {
allocator = 'ALLOC_NONE';
}
+ Variables.globals[item.ident].named = item.named;
+
if (ASM_JS && (MAIN_MODULE || SIDE_MODULE) && !item.private_ && !NAMED_GLOBALS && isIndexableGlobal(item.ident)) {
// We need this to be named (and it normally would not be), so that it can be linked to and used from other modules
Variables.globals[item.ident].linkable = 1;
diff --git a/tests/runner.py b/tests/runner.py
index a892eb56..89bf0c56 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -5899,7 +5899,7 @@ extern "C" __attribute__((noinline)) void foo(int x) {
printf("%d\n", x);
}
-void repeatable() {
+extern "C" __attribute__((noinline)) void repeatable() {
void* self = dlopen(NULL, RTLD_LAZY);
int* global_ptr = (int*)dlsym(self, "global");
void (*foo_ptr)(int) = (void (*)(int))dlsym(self, "foo");
@@ -5912,7 +5912,22 @@ int main() {
repeatable();
return 0;
}'''
- self.do_run(src, '123\n123')
+ def post(filename):
+ with open(filename) as f:
+ for line in f:
+ if 'var SYMBOL_TABLE' in line:
+ table = line
+ break
+ else:
+ raise Exception('Could not find symbol table!')
+ import json
+ table = json.loads(table[table.find('{'):table.rfind('}')+1])
+ actual = list(sorted(table.keys()))
+ # ensure there aren't too many globals; we don't want unnamed_addr
+ assert actual == ['_foo', '_global', '_main', '_repeatable'], \
+ "Symbol table does not match: %s" % actual
+
+ self.do_run(src, '123\n123', post_build=(None, post))
def test_rand(self):
return self.skip('rand() is now random') # FIXME