@@ -1238,7 +1238,7 @@ def test_odd_suffixes(self):
12381238 for suffix in ('lo',):
12391239 self.clear()
12401240 print(suffix)
1241- self.run_process([EMCC, test_file('hello_world.c'), '-shared', '-o', 'binary.' + suffix])
1241+ self.run_process([EMCC, test_file('hello_world.c'), '-sFAKE_DYLIBS', '- shared', '-o', 'binary.' + suffix])
12421242 self.run_process([EMCC, 'binary.' + suffix])
12431243 self.assertContained('hello, world!', self.run_js('a.out.js'))
12441244
@@ -1419,7 +1419,7 @@ def test_multiply_defined_libsymbols(self):
14191419 ''')
14201420
14211421 self.cflags.remove('-Werror')
1422- self.emcc('libA.c', ['-shared', '-o', 'libA.so'])
1422+ self.emcc('libA.c', ['-shared', '-sFAKE_DYLIBS', '- o', 'libA.so'])
14231423
14241424 self.emcc('a2.c', ['-r', '-L.', '-lA', '-o', 'a2.o'])
14251425 self.emcc('b2.c', ['-r', '-L.', '-lA', '-o', 'b2.o'])
@@ -1552,7 +1552,12 @@ def test_link_group_bitcode(self):
15521552 # We deliberately ignore duplicate input files in order to allow
15531553 # "libA.so" on the command line twice. This is not really .so support
15541554 # and the .so files are really object files.
1555- def test_redundant_link(self):
1555+ @parameterized({
1556+ '': ([],),
1557+ 'fake_dylibs': (['-sFAKE_DYLIBS'],),
1558+ })
1559+ def test_redundant_link(self, args):
1560+ self.cflags += args
15561561 create_file('libA.c', 'int mult() { return 1; }')
15571562 create_file('main.c', r'''
15581563 #include <stdio.h>
@@ -1564,7 +1569,7 @@ def test_redundant_link(self):
15641569 ''')
15651570
15661571 self.cflags.remove('-Werror')
1567- self.emcc('libA.c', ['-shared', '-o', 'libA.so'])
1572+ self.emcc('libA.c', ['-fPIC', '- shared', '-o', 'libA.so'])
15681573 self.emcc('main.c', ['libA.so', 'libA.so', '-o', 'a.out.js'])
15691574 self.assertContained('result: 1', self.run_js('a.out.js'))
15701575
@@ -2159,9 +2164,9 @@ def test_multidynamic_link(self, link_flags, lib_suffix):
21592164 ''')
21602165
21612166 # Build libfile normally into an .so
2162- self.run_process([EMCC, 'libdir/libfile.c', '-shared', '-o', 'libdir/libfile.so' + lib_suffix])
2167+ self.run_process([EMCC, 'libdir/libfile.c', '-sFAKE_DYLIBS', '- shared', '-fPIC ', '-o', 'libdir/libfile.so' + lib_suffix])
21632168 # Build libother and dynamically link it to libfile
2164- self.run_process([EMCC, '-Llibdir', 'libdir/libother.c'] + link_flags + ['-shared', '-o', 'libdir/libother.so'])
2169+ self.run_process([EMCC, '-Llibdir', 'libdir/libother.c'] + link_flags + ['-sFAKE_DYLIBS', '- shared', '-fPIC ', '-o', 'libdir/libother.so'])
21652170 # Build the main file, linking in both the libs
21662171 self.run_process([EMCC, '-Llibdir', os.path.join('main.c')] + link_flags + ['-lother', '-c'])
21672172 print('...')
@@ -4896,20 +4901,6 @@ def test_valid_abspath_2(self):
48964901 self.run_process(cmd)
48974902 self.assertContained('hello, world!', self.run_js('a.out.js'))
48984903
4899- def test_warn_dylibs(self):
4900- shared_suffixes = ['.so', '.dylib', '.dll']
4901-
4902- for suffix in ('.o', '.bc', '.so', '.dylib', '.js', '.html'):
4903- print(suffix)
4904- cmd = [EMCC, test_file('hello_world.c'), '-o', 'out' + suffix]
4905- if suffix in ['.o', '.bc']:
4906- cmd.append('-c')
4907- if suffix in ['.dylib', '.so']:
4908- cmd.append('-shared')
4909- err = self.run_process(cmd, stderr=PIPE).stderr
4910- warning = 'linking a library with `-shared` will emit a static object file'
4911- self.assertContainedIf(warning, err, suffix in shared_suffixes)
4912-
49134904 @crossplatform
49144905 @parameterized({
49154906 'O2': [['-O2']],
@@ -8388,19 +8379,6 @@ def test_side_module_folder_deps(self):
83888379 self.run_process([EMCC, test_file('hello_world.c'), '-sSIDE_MODULE', '-o', 'subdir/libside2.so', '-L', 'subdir', '-lside1'])
83898380 self.run_process([EMCC, test_file('hello_world.c'), '-sMAIN_MODULE', '-o', 'main.js', '-L', 'subdir', '-lside2'])
83908381
8391- @crossplatform
8392- def test_side_module_ignore(self):
8393- self.run_process([EMCC, test_file('hello_world.c'), '-sSIDE_MODULE', '-o', 'libside.so'])
8394-
8395- # Attempting to link statically against a side module (libside.so) should fail.
8396- self.assert_fail([EMCC, '-L.', '-lside'], 'wasm-ld: error: unable to find library -lside')
8397-
8398- # But a static library in the same location (libside.a) should take precedence.
8399- self.run_process([EMCC, test_file('hello_world.c'), '-c'])
8400- self.run_process([EMAR, 'cr', 'libside.a', 'hello_world.o'])
8401- self.run_process([EMCC, '-L.', '-lside'])
8402- self.assertContained('hello, world!', self.run_js('a.out.js'))
8403-
84048382 @is_slow_test
84058383 @parameterized({
84068384 '': ([],),
@@ -11922,42 +11900,40 @@ def test_err(self):
1192211900 def test_euidaccess(self):
1192311901 self.do_other_test('test_euidaccess.c')
1192411902
11925- def test_shared_flag(self):
11926- create_file('side.c', 'int foo;')
11927- self.run_process([EMCC, '-shared', 'side.c', '-o', 'libother.so'])
11903+ def test_fake_dylibs(self):
11904+ create_file('other.c', 'int foo = 10;')
11905+ self.run_process([EMCC, '-shared', '-sFAKE_DYLIBS', '-fPIC', 'other.c', '-o', 'libother.so'])
11906+ self.assertIsObjectFile('libother.so')
1192811907
11929- # Test that `-shared ` flag causes object file generation but gives a warning
11930- err = self.run_process([EMCC, '-shared', test_file('hello_world.c'), '-o', 'out.foo', 'libother.so'], stderr=PIPE).stderr
11931- self.assertContained('linking a library with ` -shared` will emit a static object', err)
11908+ # Test that `-sFAKE_DYLIBS ` flag causes object file generation and will generate a warning about
11909+ # dylink dependencies being ignored.
11910+ err = self.run_process([EMCC, ' -shared', '-sFAKE_DYLIBS', '-fPIC', test_file('hello_world.c'), '-o', 'out.foo', 'libother.so'], stderr=PIPE).stderr
1193211911 self.assertContained('emcc: warning: ignoring dynamic library libother.so when generating an object file, this will need to be included explicitly in the final link', err)
1193311912 self.assertIsObjectFile('out.foo')
1193411913
1193511914 # Test that adding `-sFAKE_DYIBS=0` build a real side module
1193611915 err = self.run_process([EMCC, '-shared', '-fPIC', '-sFAKE_DYLIBS=0', test_file('hello_world.c'), '-o', 'out.foo', 'libother.so'], stderr=PIPE).stderr
11937- self.assertNotContained('linking a library with `-shared` will emit a static object', err)
1193811916 self.assertNotContained('emcc: warning: ignoring dynamic library libother.so when generating an object file, this will need to be included explicitly in the final link', err)
1193911917 self.assertIsWasmDylib('out.foo')
1194011918
1194111919 # Test that using an executable output name overrides the `-shared` flag, but produces a warning.
11942- err = self.run_process([EMCC, '-shared', test_file('hello_world.c'), '-o', 'out.js'],
11920+ err = self.run_process([EMCC, '-shared', '-sFAKE_DYLIBS', '-fPIC', test_file('hello_world.c'), '-o', 'out.js'],
1194311921 stderr=PIPE).stderr
1194411922 self.assertContained('warning: -shared/-r used with executable output suffix', err)
1194511923 self.run_js('out.js')
1194611924
1194711925 def test_shared_soname(self):
11948- self.run_process([EMCC, '-shared', '-Wl,-soname', '-Wl,libfoo.so.13', test_file('hello_world.c'), '-lc', '-o', 'libfoo.so'])
11926+ self.run_process([EMCC, '-shared', '-sFAKE_DYLIBS', '- Wl,-soname', '-Wl,libfoo.so.13', test_file('hello_world.c'), '-lc', '-o', 'libfoo.so'])
1194911927 self.run_process([EMCC, '-sSTRICT', 'libfoo.so'])
1195011928 self.assertContained('hello, world!', self.run_js('a.out.js'))
1195111929
11952- def test_shared_and_side_module_flag(self):
11953- # Test that `-shared` and `-sSIDE_MODULE` flag causes wasm dylib generation without a warning.
11954- err = self.run_process([EMCC, '-shared', '-sSIDE_MODULE', test_file('hello_world.c'), '-o', 'out.foo'], stderr=PIPE).stderr
11955- self.assertNotContained('linking a library with `-shared` will emit a static object', err)
11930+ def test_shared_flag(self):
11931+ # Test that `-shared` flag causes wasm dylib generation
11932+ self.run_process([EMCC, '-shared', '-fPIC', test_file('hello_world.c'), '-o', 'out.foo'])
1195611933 self.assertIsWasmDylib('out.foo')
1195711934
11958- # Test that `-shared` and `-sSIDE_MODULE` flag causes wasm dylib generation without a warning even if given executable output name.
11959- err = self.run_process([EMCC, '-shared', '-sSIDE_MODULE', test_file('hello_world.c'), '-o', 'out.wasm'],
11960- stderr=PIPE).stderr
11935+ # Test that `-shared` causes wasm dylib generation warning even if given executable output name.
11936+ err = self.run_process([EMCC, '-shared', '-fPIC', test_file('hello_world.c'), '-o', 'out.wasm'], stderr=PIPE).stderr
1196111937 self.assertNotContained('warning: -shared/-r used with executable output suffix', err)
1196211938 self.assertIsWasmDylib('out.wasm')
1196311939
0 commit comments