From 2817d5ac5526f61b748827f0fae9ecdbc16fcef6 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 4 Dec 2012 11:54:07 -0800 Subject: [PATCH] only add in .o inside .a that are needed --- tests/runner.py | 34 ++++++++++++++++++++++++++++++++++ tools/shared.py | 6 ------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/tests/runner.py b/tests/runner.py index f024198ea..3dfef3e9b 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -7880,6 +7880,40 @@ f.close() self.assertContained('result: 1', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_multiply_defined_libsymbols_2(self): + a = "int x() { return 55; }" + a_name = os.path.join(self.get_dir(), 'a.c') + open(a_name, 'w').write(a) + b = "int y() { return 2; }" + b_name = os.path.join(self.get_dir(), 'b.c') + open(b_name, 'w').write(b) + c = "int z() { return 5; }" + c_name = os.path.join(self.get_dir(), 'c.c') + open(c_name, 'w').write(c) + main = r''' + #include + int x(); + int y(); + int z(); + int main() { + printf("result: %d\n", x() + y() + z()); + return 0; + } + ''' + main_name = os.path.join(self.get_dir(), 'main.c') + open(main_name, 'w').write(main) + + Building.emcc(a_name) # a.c.o + Building.emcc(b_name) # b.c.o + Building.emcc(c_name) # c.c.o + lib_name = os.path.join(self.get_dir(), 'libLIB.a') + Building.emar('cr', lib_name, [a_name + '.o', b_name + '.o']) # libLIB.a with a and b + + # a is in the lib AND in an .o, so should be ignored in the lib. We do still need b from the lib though + Building.emcc(main_name, ['-L.', '-lLIB', a_name+'.o', c_name + '.o'], output_filename='a.out.js') + + self.assertContained('result: 62', run_js(os.path.join(self.get_dir(), 'a.out.js'))) + def test_abspaths(self): # Includes with absolute paths are generally dangerous, things like -I/usr/.. will get to system local headers, not our portable ones. diff --git a/tools/shared.py b/tools/shared.py index e292dbf30..6af1b9dff 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -741,17 +741,11 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e Popen([LLVM_AR, 'x', f], stdout=PIPE).communicate() # if absolute paths, files will appear there. otherwise, in this directory contents = map(lambda content: os.path.join(temp_dir, content), contents) contents = filter(os.path.exists, map(os.path.abspath, contents)) - needed = False # We add or do not add the entire archive. We let llvm dead code eliminate parts we do not need, instead of - # doing intra-dependencies between archive contents for content in contents: new_symbols = Building.llvm_nm(content) # Link in the .o if it provides symbols, *or* this is a singleton archive (which is apparently an exception in gcc ld) if new_symbols.defs.intersection(unresolved_symbols) or len(files) == 1: - needed = True - if needed: - for content in contents: if Building.is_bitcode(content): - new_symbols = Building.llvm_nm(content) resolved_symbols = resolved_symbols.union(new_symbols.defs) unresolved_symbols = unresolved_symbols.union(new_symbols.undefs.difference(resolved_symbols)).difference(new_symbols.defs) actual_files.append(content)