aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNick Bray <ncbray@chromium.org>2013-08-07 12:39:33 -0700
committerNick Bray <ncbray@chromium.org>2013-08-07 12:46:41 -0700
commit8999e0e20212d736b539f15debad25a69dda2f98 (patch)
tree59b46aa56ed834f8806684c09029d931f39e8c00 /tests
parent1b7122c6aaa19cb6e2a62598dca8e0fd9e3cc7a7 (diff)
Ensure the linker pulls in static libraries containing exported functions.
Previously, an exported function contained in a library would not be found by the linker if the library did not contain symbols transitively reachable from main.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/runner.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py
index 84e8b69e..86ae5bdb 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -11595,6 +11595,39 @@ int main(int argc, char const *argv[])
self.assertContained('a\nb\n', run_js(os.path.join(self.get_dir(), 'a.out.js')))
+ def test_export_in_a(self):
+ export_name = 'this_is_an_entry_point'
+
+ open('export.c', 'w').write(r'''
+ #include <stdio.h>
+ void %s(void) {
+ printf("Hello, world!\n");
+ }
+ ''' % export_name)
+ Popen([PYTHON, EMCC, 'export.c', '-c', '-o', 'export.o']).communicate()
+ Popen([PYTHON, EMAR, 'rc', 'libexport.a', 'export.o']).communicate()
+
+ open('main.c', 'w').write(r'''
+ int main() {
+ return 0;
+ }
+ ''')
+
+ definition = 'function _%s(' % export_name
+
+ # Sanity check: the symbol should not be linked in if not requested.
+ Popen([PYTHON, EMCC, 'main.c', '-L.', '-lexport']).communicate()
+ self.assertNotContained(definition, open(os.path.join(self.get_dir(), 'a.out.js')).read())
+
+ # Sanity check: exporting without a definition does not cause it to appear.
+ # Note: exporting main prevents emcc from warning that it generated no code.
+ Popen([PYTHON, EMCC, 'main.c', '-s', '''EXPORTED_FUNCTIONS=['_main', '_%s']''' % export_name]).communicate()
+ self.assertNotContained(definition, open(os.path.join(self.get_dir(), 'a.out.js')).read())
+
+ # Actual test: defining symbol in library and exporting it causes it to appear in the output.
+ Popen([PYTHON, EMCC, 'main.c', '-L.', '-lexport', '-s', '''EXPORTED_FUNCTIONS=['_%s']''' % export_name]).communicate()
+ self.assertContained(definition, open(os.path.join(self.get_dir(), 'a.out.js')).read())
+
def test_embed_file(self):
open(os.path.join(self.get_dir(), 'somefile.txt'), 'w').write('''hello from a file with lots of data and stuff in it thank you very much''')
open(os.path.join(self.get_dir(), 'main.cpp'), 'w').write(r'''