@@ -930,7 +930,8 @@ def test_cmake_explicit_generator(self):
930930 # use -Wno-dev to suppress an irrelevant warning about the test files only.
931931 cmd = [EMCMAKE, 'cmake', '-GNinja', '-Wno-dev', test_file('cmake/cpp_lib')]
932932 self.run_process(cmd)
933- self.assertExists(self.get_dir() + '/build.ninja')
933+ self.assertExists('build.ninja')
934+ self.run_process(['ninja', '-v'])
934935
935936 # Tests that it's possible to pass C++17 or GNU++17 build modes to CMake by building code that
936937 # needs C++17 (embind)
@@ -1173,7 +1174,7 @@ def test_odd_suffixes(self):
11731174 for suffix in ('lo',):
11741175 self.clear()
11751176 print(suffix)
1176- self.run_process([EMCC, test_file('hello_world.c'), '-shared', '-o', 'binary.' + suffix])
1177+ self.run_process([EMCC, test_file('hello_world.c'), '-sFAKE_DYLIBS', '- shared', '-o', 'binary.' + suffix])
11771178 self.run_process([EMCC, 'binary.' + suffix])
11781179 self.assertContained('Hello, world!', self.run_js('a.out.js'))
11791180
@@ -1354,7 +1355,7 @@ def test_multiply_defined_libsymbols(self):
13541355 ''')
13551356
13561357 self.cflags.remove('-Werror')
1357- self.emcc('libA.c', ['-shared', '-o', 'libA.so'])
1358+ self.emcc('libA.c', ['-shared', '-sFAKE_DYLIBS', '- o', 'libA.so'])
13581359
13591360 self.emcc('a2.c', ['-r', '-L.', '-lA', '-o', 'a2.o'])
13601361 self.emcc('b2.c', ['-r', '-L.', '-lA', '-o', 'b2.o'])
@@ -1487,7 +1488,12 @@ def test_link_group_bitcode(self):
14871488 # We deliberately ignore duplicate input files in order to allow
14881489 # "libA.so" on the command line twice. This is not really .so support
14891490 # and the .so files are really object files.
1490- def test_redundant_link(self):
1491+ @parameterized({
1492+ '': ([],),
1493+ 'fake_dylibs': (['-sFAKE_DYLIBS'],),
1494+ })
1495+ def test_redundant_link(self, args):
1496+ self.cflags += args
14911497 create_file('libA.c', 'int mult() { return 1; }')
14921498 create_file('main.c', r'''
14931499 #include <stdio.h>
@@ -1499,7 +1505,7 @@ def test_redundant_link(self):
14991505 ''')
15001506
15011507 self.cflags.remove('-Werror')
1502- self.emcc('libA.c', ['-shared', '-o', 'libA.so'])
1508+ self.emcc('libA.c', ['-fPIC', '- shared', '-o', 'libA.so'])
15031509 self.emcc('main.c', ['libA.so', 'libA.so', '-o', 'a.out.js'])
15041510 self.assertContained('result: 1', self.run_js('a.out.js'))
15051511
@@ -2147,9 +2153,9 @@ def test_multidynamic_link(self, link_flags, lib_suffix):
21472153 ''')
21482154
21492155 # Build libfile normally into an .so
2150- self.run_process([EMCC, 'libdir/libfile.c', '-shared', '-o', 'libdir/libfile.so' + lib_suffix])
2156+ self.run_process([EMCC, 'libdir/libfile.c', '-sFAKE_DYLIBS', '- shared', '-fPIC ', '-o', 'libdir/libfile.so' + lib_suffix])
21512157 # Build libother and dynamically link it to libfile
2152- self.run_process([EMCC, '-Llibdir', 'libdir/libother.c'] + link_flags + ['-shared', '-o', 'libdir/libother.so'])
2158+ self.run_process([EMCC, '-Llibdir', 'libdir/libother.c'] + link_flags + ['-sFAKE_DYLIBS', '- shared', '-fPIC ', '-o', 'libdir/libother.so'])
21532159 # Build the main file, linking in both the libs
21542160 self.run_process([EMCC, '-Llibdir', os.path.join('main.c')] + link_flags + ['-lother', '-c'])
21552161 print('...')
@@ -4940,20 +4946,6 @@ def test_valid_abspath_2(self):
49404946 self.run_process(cmd)
49414947 self.assertContained('Hello, world!', self.run_js('a.out.js'))
49424948
4943- def test_warn_dylibs(self):
4944- shared_suffixes = ['.so', '.dylib', '.dll']
4945-
4946- for suffix in ('.o', '.bc', '.so', '.dylib', '.js', '.html'):
4947- print(suffix)
4948- cmd = [EMCC, test_file('hello_world.c'), '-o', 'out' + suffix]
4949- if suffix in {'.o', '.bc'}:
4950- cmd.append('-c')
4951- if suffix in {'.dylib', '.so'}:
4952- cmd.append('-shared')
4953- err = self.run_process(cmd, stderr=PIPE).stderr
4954- warning = 'linking a library with `-shared` will emit a static object file'
4955- self.assertContainedIf(warning, err, suffix in shared_suffixes)
4956-
49574949 @crossplatform
49584950 @parameterized({
49594951 'O2': [['-O2']],
@@ -8446,19 +8438,6 @@ def test_side_module_folder_deps(self):
84468438 self.run_process([EMCC, test_file('hello_world.c'), '-sSIDE_MODULE', '-o', 'subdir/libside2.so', '-L', 'subdir', '-lside1'])
84478439 self.run_process([EMCC, test_file('hello_world.c'), '-sMAIN_MODULE', '-o', 'main.js', '-L', 'subdir', '-lside2'])
84488440
8449- @crossplatform
8450- def test_side_module_ignore(self):
8451- self.run_process([EMCC, test_file('hello_world.c'), '-sSIDE_MODULE', '-o', 'libside.so'])
8452-
8453- # Attempting to link statically against a side module (libside.so) should fail.
8454- self.assert_fail([EMCC, '-L.', '-lside'], 'wasm-ld: error: unable to find library -lside')
8455-
8456- # But a static library in the same location (libside.a) should take precedence.
8457- self.run_process([EMCC, test_file('hello_world.c'), '-c'])
8458- self.run_process([EMAR, 'cr', 'libside.a', 'hello_world.o'])
8459- self.run_process([EMCC, '-L.', '-lside'])
8460- self.assertContained('Hello, world!', self.run_js('a.out.js'))
8461-
84628441 @is_slow_test
84638442 @parameterized({
84648443 '': ([],),
@@ -12114,42 +12093,40 @@ def test_err(self):
1211412093 def test_euidaccess(self):
1211512094 self.do_other_test('test_euidaccess.c')
1211612095
12117- def test_shared_flag(self):
12118- create_file('side.c', 'int foo;')
12119- self.run_process([EMCC, '-shared', 'side.c', '-o', 'libother.so'])
12096+ def test_fake_dylibs(self):
12097+ create_file('other.c', 'int foo = 10;')
12098+ self.run_process([EMCC, '-shared', '-sFAKE_DYLIBS', '-fPIC', 'other.c', '-o', 'libother.so'])
12099+ self.assertIsObjectFile('libother.so')
1212012100
12121- # Test that `-shared ` flag causes object file generation but gives a warning
12122- err = self.run_process([EMCC, '-shared', test_file('hello_world.c'), '-o', 'out.foo', 'libother.so'], stderr=PIPE).stderr
12123- self.assertContained('linking a library with ` -shared` will emit a static object', err)
12101+ # Test that `-sFAKE_DYLIBS ` flag causes object file generation and will generate a warning about
12102+ # dylink dependencies being ignored.
12103+ err = self.run_process([EMCC, ' -shared', '-sFAKE_DYLIBS', '-fPIC', test_file('hello_world.c'), '-o', 'out.foo', 'libother.so'], stderr=PIPE).stderr
1212412104 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)
1212512105 self.assertIsObjectFile('out.foo')
1212612106
1212712107 # Test that adding `-sFAKE_DYLIBS=0` build a real side module
1212812108 err = self.run_process([EMCC, '-shared', '-fPIC', '-sFAKE_DYLIBS=0', test_file('hello_world.c'), '-o', 'out.foo', 'libother.so'], stderr=PIPE).stderr
12129- self.assertNotContained('linking a library with `-shared` will emit a static object', err)
1213012109 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)
1213112110 self.assertIsWasmDylib('out.foo')
1213212111
1213312112 # Test that using an executable output name overrides the `-shared` flag, but produces a warning.
12134- err = self.run_process([EMCC, '-shared', test_file('hello_world.c'), '-o', 'out.js'],
12113+ err = self.run_process([EMCC, '-shared', '-sFAKE_DYLIBS', '-fPIC', test_file('hello_world.c'), '-o', 'out.js'],
1213512114 stderr=PIPE).stderr
1213612115 self.assertContained('warning: -shared/-r used with executable output suffix', err)
1213712116 self.run_js('out.js')
1213812117
1213912118 def test_shared_soname(self):
12140- self.run_process([EMCC, '-shared', '-Wl,-soname', '-Wl,libfoo.so.13', test_file('hello_world.c'), '-lc', '-o', 'libfoo.so'])
12119+ self.run_process([EMCC, '-shared', '-sFAKE_DYLIBS', '- Wl,-soname', '-Wl,libfoo.so.13', test_file('hello_world.c'), '-lc', '-o', 'libfoo.so'])
1214112120 self.run_process([EMCC, '-sSTRICT', 'libfoo.so'])
1214212121 self.assertContained('Hello, world!', self.run_js('a.out.js'))
1214312122
12144- def test_shared_and_side_module_flag(self):
12145- # Test that `-shared` and `-sSIDE_MODULE` flag causes wasm dylib generation without a warning.
12146- err = self.run_process([EMCC, '-shared', '-sSIDE_MODULE', test_file('hello_world.c'), '-o', 'out.foo'], stderr=PIPE).stderr
12147- self.assertNotContained('linking a library with `-shared` will emit a static object', err)
12123+ def test_shared_flag(self):
12124+ # Test that `-shared` flag causes wasm dylib generation
12125+ self.run_process([EMCC, '-shared', '-fPIC', test_file('hello_world.c'), '-o', 'out.foo'])
1214812126 self.assertIsWasmDylib('out.foo')
1214912127
12150- # Test that `-shared` and `-sSIDE_MODULE` flag causes wasm dylib generation without a warning even if given executable output name.
12151- err = self.run_process([EMCC, '-shared', '-sSIDE_MODULE', test_file('hello_world.c'), '-o', 'out.wasm'],
12152- stderr=PIPE).stderr
12128+ # Test that `-shared` causes wasm dylib generation warning even if given executable output name.
12129+ err = self.run_process([EMCC, '-shared', '-fPIC', test_file('hello_world.c'), '-o', 'out.wasm'], stderr=PIPE).stderr
1215312130 self.assertNotContained('warning: -shared/-r used with executable output suffix', err)
1215412131 self.assertIsWasmDylib('out.wasm')
1215512132
0 commit comments