Skip to content

Commit

Permalink
Link in objects when they provide commons we need, not just defs (ems…
Browse files Browse the repository at this point in the history
…cripten-core#4764)

* link in objects when they provide commons we need, not just defs emscripten-core#4763

* test commons linking
  • Loading branch information
kripken authored Dec 9, 2016
1 parent 2ea9c2a commit 84d15f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
27 changes: 27 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,33 @@ def build(path, args):

assert not os.path.exists('a.out') and not os.path.exists('a.exe'), 'Must not leave unneeded linker stubs'

def test_commons_link(self):
open('a.h', 'w').write(r'''
#if !defined(A_H)
#define A_H
extern int foo[8];
#endif
''')
open('a.c', 'w').write(r'''
#include "a.h"
int foo[8];
''')
open('main.c', 'w').write(r'''
#include <stdio.h>
#include "a.h"
int main() {
printf("|%d|\n", foo[0]);
return 0;
}
''')

subprocess.check_call([PYTHON, EMCC, '-o', 'a.o', 'a.c'])
subprocess.check_call([PYTHON, EMAR, 'rv', 'library.a', 'a.o'])
subprocess.check_call([PYTHON, EMCC, '-o', 'main.o', 'main.c'])
subprocess.check_call([PYTHON, EMCC, '-o', 'a.js', 'main.o', 'library.a', '-s', 'ERROR_ON_UNDEFINED_SYMBOLS=1'])
self.assertContained('|0|', run_js('a.js'))

def test_outline(self):
if WINDOWS and not Building.which('mingw32-make'):
return self.skip('Skipping other.test_outline: This test requires "mingw32-make" tool in PATH on Windows to drive a Makefile build of zlib')
Expand Down
7 changes: 4 additions & 3 deletions tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -1456,15 +1456,16 @@ def make_paths_absolute(f):
# returns True.
def consider_object(f, force_add=False):
new_symbols = Building.llvm_nm(f)
do_add = force_add or not unresolved_symbols.isdisjoint(new_symbols.defs)
provided = new_symbols.defs.union(new_symbols.commons)
do_add = force_add or not unresolved_symbols.isdisjoint(provided)
if do_add:
logging.debug('adding object %s to link' % (f))
# Update resolved_symbols table with newly resolved symbols
resolved_symbols.update(new_symbols.defs)
resolved_symbols.update(provided)
# Update unresolved_symbols table by adding newly unresolved symbols and
# removing newly resolved symbols.
unresolved_symbols.update(new_symbols.undefs.difference(resolved_symbols))
unresolved_symbols.difference_update(new_symbols.defs)
unresolved_symbols.difference_update(provided)
actual_files.append(f)
return do_add

Expand Down

0 comments on commit 84d15f1

Please sign in to comment.