@@ -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'), '-shared', '-fPIC', '- o', 'binary.' + suffix])
11771178 self.run_process([EMCC, 'binary.' + suffix])
11781179 self.assertContained('Hello, world!', self.run_js('a.out.js'))
11791180
@@ -1358,11 +1359,11 @@ def test_multiply_defined_libsymbols(self):
13581359 # we model shared libraries using regular object files. Without special handling
13591360 # fake `libA.so` could get linked multiple times.
13601361 self.cflags.remove('-Werror')
1361- self.emcc('libA.c', ['-shared', '-o', 'libA.so'])
1362+ self.emcc('libA.c', ['-sFAKE_DYLIBS', '- shared', '-fPIC ', '-o', 'libA.so'])
13621363
1363- err = self.emcc('a2.c', ['-shared', '-L.', '-lA', '-o', 'liba2.so'], stderr=PIPE).stderr
1364+ err = self.emcc('a2.c', ['-sFAKE_DYLIBS', '- shared', '-fPIC ', '-L.', '-lA', '-o', 'liba2.so'], stderr=PIPE).stderr
13641365 self.assertContained('emcc: warning: ignoring dynamic library libA.so when generating an object file', err)
1365- err = self.emcc('b2.c', ['-shared', '-L.', '-lA', '-o', 'libb2.so'], stderr=PIPE).stderr
1366+ err = self.emcc('b2.c', ['-sFAKE_DYLIBS', '- shared', '-fPIC ', '-L.', '-lA', '-o', 'libb2.so'], stderr=PIPE).stderr
13661367 self.assertContained('emcc: warning: ignoring dynamic library libA.so when generating an object file', err)
13671368
13681369 self.do_runf('main.c', 'result: 1', cflags=['-L.', '-lA', 'liba2.so', 'libb2.so'])
@@ -1493,7 +1494,12 @@ def test_link_group_bitcode(self):
14931494 # We deliberately ignore duplicate input files in order to allow
14941495 # "libA.so" on the command line twice. This is not really .so support
14951496 # and the .so files are really object files.
1496- def test_redundant_link(self):
1497+ @parameterized({
1498+ '': ([],),
1499+ 'fake_dylibs': (['-sFAKE_DYLIBS'],),
1500+ })
1501+ def test_redundant_link(self, args):
1502+ self.cflags += args
14971503 create_file('libA.c', 'int mult() { return 1; }')
14981504 create_file('main.c', r'''
14991505 #include <stdio.h>
@@ -1505,7 +1511,7 @@ def test_redundant_link(self):
15051511 ''')
15061512
15071513 self.cflags.remove('-Werror')
1508- self.emcc('libA.c', ['-shared', '-o', 'libA.so'])
1514+ self.emcc('libA.c', ['-fPIC', '- shared', '-o', 'libA.so'])
15091515 self.emcc('main.c', ['libA.so', 'libA.so', '-o', 'a.out.js'])
15101516 self.assertContained('result: 1', self.run_js('a.out.js'))
15111517
@@ -2153,9 +2159,9 @@ def test_multidynamic_link(self, link_flags, lib_suffix):
21532159 ''')
21542160
21552161 # Build libfile normally into an .so
2156- self.run_process([EMCC, 'libdir/libfile.c', '-shared', '-o', 'libdir/libfile.so' + lib_suffix])
2162+ self.run_process([EMCC, 'libdir/libfile.c', '-sFAKE_DYLIBS', '- shared', '-fPIC ', '-o', 'libdir/libfile.so' + lib_suffix])
21572163 # Build libother and dynamically link it to libfile
2158- self.run_process([EMCC, '-Llibdir', 'libdir/libother.c'] + link_flags + ['-shared', '-o', 'libdir/libother.so'])
2164+ self.run_process([EMCC, '-Llibdir', 'libdir/libother.c'] + link_flags + ['-sFAKE_DYLIBS', '- shared', '-fPIC ', '-o', 'libdir/libother.so'])
21592165 # Build the main file, linking in both the libs
21602166 self.run_process([EMCC, '-Llibdir', os.path.join('main.c')] + link_flags + ['-lother', '-c'])
21612167 print('...')
@@ -2460,17 +2466,17 @@ def test_dylink_library_search(self):
24602466 }
24612467 ''')
24622468
2463- # By deafult we use static linking and prefer libside.a
2464- self.do_runf('main.c', 'static linking used\n', cflags=['-L.', '-lside'])
2469+ # By default we use dynamic linking
2470+ self.do_runf('main.c', 'dynamic linking used\n', cflags=['-L.', '-lside'])
24652471
2466- # When using -sMAIN_MODULE we choose the dyanmic library
2467- self.do_runf('main.c', 'dynamic linking used\n', cflags=['-sMAIN_MODULE=2 ', '-L.', '-lside'])
2472+ # When using -sMAIN_MODULE=0 we explictly opt out of dynammic linking
2473+ self.do_runf('main.c', 'static linking used\n', cflags=['-sMAIN_MODULE=0 ', '-L.', '-lside'])
24682474
2469- # Same for `-sFAKE_DYLIBS=0
2470- self.do_runf('main.c', 'dynamic linking used\n', cflags=['-sFAKE_DYLIBS=0 ', '-L.', '-lside'])
2475+ # Same for `-sFAKE_DYLIBS
2476+ self.do_runf('main.c', 'static linking used\n', cflags=['-sFAKE_DYLIBS', '-L.', '-lside'])
24712477
24722478 # With can also force static linking using `-Bstatic` linker falgs
2473- self.do_runf('main.c', 'static linking used\n', cflags=['-sMAIN_MODULE=2', '- L.', '-Bstatic', '-lside'])
2479+ self.do_runf('main.c', 'static linking used\n', cflags=['-L.', '-Bstatic', '-lside'])
24742480
24752481 def test_js_link(self):
24762482 create_file('before.js', '''
@@ -4953,20 +4959,6 @@ def test_valid_abspath_2(self):
49534959 self.run_process(cmd)
49544960 self.assertContained('Hello, world!', self.run_js('a.out.js'))
49554961
4956- def test_warn_dylibs(self):
4957- shared_suffixes = ['.so', '.dylib', '.dll']
4958-
4959- for suffix in ('.o', '.bc', '.so', '.dylib', '.js', '.html'):
4960- print(suffix)
4961- cmd = [EMCC, test_file('hello_world.c'), '-o', 'out' + suffix]
4962- if suffix in {'.o', '.bc'}:
4963- cmd.append('-c')
4964- if suffix in {'.dylib', '.so'}:
4965- cmd.append('-shared')
4966- err = self.run_process(cmd, stderr=PIPE).stderr
4967- warning = 'linking a library with `-shared` will emit a static object file'
4968- self.assertContainedIf(warning, err, suffix in shared_suffixes)
4969-
49704962 @crossplatform
49714963 @parameterized({
49724964 'O2': [['-O2']],
@@ -8462,12 +8454,12 @@ def test_side_module_ignore(self):
84628454 self.run_process([EMCC, test_file('hello_world.c'), '-sSIDE_MODULE', '-o', 'libside.so'])
84638455
84648456 # Attempting to link statically against a side module (libside.so) should fail.
8465- self.assert_fail([EMCC, '-L.', '-lside'], 'wasm-ld: error: unable to find library -lside')
8457+ self.assert_fail([EMCC, '-L.', '-Bstatic', '- lside'], 'wasm-ld: error: unable to find library -lside')
84668458
84678459 # But a static library in the same location (libside.a) should take precedence.
84688460 self.run_process([EMCC, test_file('hello_world.c'), '-c'])
84698461 self.run_process([EMAR, 'cr', 'libside.a', 'hello_world.o'])
8470- self.run_process([EMCC, '-L.', '-lside'])
8462+ self.run_process([EMCC, '-L.', '-Bstatic', '- lside'])
84718463 self.assertContained('Hello, world!', self.run_js('a.out.js'))
84728464
84738465 @is_slow_test
@@ -12129,42 +12121,40 @@ def test_err(self):
1212912121 def test_euidaccess(self):
1213012122 self.do_other_test('test_euidaccess.c')
1213112123
12132- def test_shared_flag(self):
12133- create_file('side.c', 'int foo;')
12134- self.run_process([EMCC, '-shared', 'side.c', '-o', 'libother.so'])
12124+ def test_fake_dylibs(self):
12125+ create_file('other.c', 'int foo = 10;')
12126+ self.run_process([EMCC, '-shared', '-sFAKE_DYLIBS', '-fPIC', 'other.c', '-o', 'libother.so'])
12127+ self.assertIsObjectFile('libother.so')
1213512128
12136- # Test that `-shared ` flag causes object file generation but gives a warning
12137- err = self.run_process([EMCC, '-shared', test_file('hello_world.c'), '-o', 'out.foo', 'libother.so'], stderr=PIPE).stderr
12138- self.assertContained('linking a library with ` -shared` will emit a static object', err)
12129+ # Test that `-sFAKE_DYLIBS ` flag causes object file generation and will generate a warning about
12130+ # dylink dependencies being ignored.
12131+ err = self.run_process([EMCC, ' -shared', '-sFAKE_DYLIBS', '-fPIC', test_file('hello_world.c'), '-o', 'out.foo', 'libother.so'], stderr=PIPE).stderr
1213912132 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)
1214012133 self.assertIsObjectFile('out.foo')
1214112134
1214212135 # Test that adding `-sFAKE_DYLIBS=0` build a real side module
1214312136 err = self.run_process([EMCC, '-shared', '-fPIC', '-sFAKE_DYLIBS=0', test_file('hello_world.c'), '-o', 'out.foo', 'libother.so'], stderr=PIPE).stderr
12144- self.assertNotContained('linking a library with `-shared` will emit a static object', err)
1214512137 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)
1214612138 self.assertIsWasmDylib('out.foo')
1214712139
1214812140 # Test that using an executable output name overrides the `-shared` flag, but produces a warning.
12149- err = self.run_process([EMCC, '-shared', test_file('hello_world.c'), '-o', 'out.js'],
12141+ err = self.run_process([EMCC, '-shared', '-sFAKE_DYLIBS', '-fPIC', test_file('hello_world.c'), '-o', 'out.js'],
1215012142 stderr=PIPE).stderr
1215112143 self.assertContained('warning: -shared/-r used with executable output suffix', err)
1215212144 self.run_js('out.js')
1215312145
1215412146 def test_shared_soname(self):
12155- self.run_process([EMCC, '-shared', '-Wl,-soname', '-Wl,libfoo.so.13', test_file('hello_world.c'), '-lc', '-o', 'libfoo.so'])
12147+ self.run_process([EMCC, '-shared', '-sFAKE_DYLIBS', '- Wl,-soname', '-Wl,libfoo.so.13', test_file('hello_world.c'), '-lc', '-o', 'libfoo.so'])
1215612148 self.run_process([EMCC, '-sSTRICT', 'libfoo.so'])
1215712149 self.assertContained('Hello, world!', self.run_js('a.out.js'))
1215812150
12159- def test_shared_and_side_module_flag(self):
12160- # Test that `-shared` and `-sSIDE_MODULE` flag causes wasm dylib generation without a warning.
12161- err = self.run_process([EMCC, '-shared', '-sSIDE_MODULE', test_file('hello_world.c'), '-o', 'out.foo'], stderr=PIPE).stderr
12162- self.assertNotContained('linking a library with `-shared` will emit a static object', err)
12151+ def test_shared_flag(self):
12152+ # Test that `-shared` flag causes wasm dylib generation
12153+ self.run_process([EMCC, '-shared', '-fPIC', test_file('hello_world.c'), '-o', 'out.foo'])
1216312154 self.assertIsWasmDylib('out.foo')
1216412155
12165- # Test that `-shared` and `-sSIDE_MODULE` flag causes wasm dylib generation without a warning even if given executable output name.
12166- err = self.run_process([EMCC, '-shared', '-sSIDE_MODULE', test_file('hello_world.c'), '-o', 'out.wasm'],
12167- stderr=PIPE).stderr
12156+ # Test that `-shared` causes wasm dylib generation warning even if given executable output name.
12157+ err = self.run_process([EMCC, '-shared', '-fPIC', test_file('hello_world.c'), '-o', 'out.wasm'], stderr=PIPE).stderr
1216812158 self.assertNotContained('warning: -shared/-r used with executable output suffix', err)
1216912159 self.assertIsWasmDylib('out.wasm')
1217012160
0 commit comments