@@ -932,7 +932,8 @@ def test_cmake_explicit_generator(self):
932932 # use -Wno-dev to suppress an irrelevant warning about the test files only.
933933 cmd = [EMCMAKE, 'cmake', '-GNinja', '-Wno-dev', test_file('cmake/cpp_lib')]
934934 self.run_process(cmd)
935- self.assertExists(self.get_dir() + '/build.ninja')
935+ self.assertExists('build.ninja')
936+ self.run_process(['ninja', '-v'])
936937
937938 # Tests that it's possible to pass C++17 or GNU++17 build modes to CMake by building code that
938939 # needs C++17 (embind)
@@ -1175,7 +1176,7 @@ def test_odd_suffixes(self):
11751176 for suffix in ('lo',):
11761177 self.clear()
11771178 print(suffix)
1178- self.run_process([EMCC, test_file('hello_world.c'), '-shared', '-o', 'binary.' + suffix])
1179+ self.run_process([EMCC, test_file('hello_world.c'), '-shared', '-fPIC', '- o', 'binary.' + suffix])
11791180 self.run_process([EMCC, 'binary.' + suffix])
11801181 self.assertContained('Hello, world!', self.run_js('a.out.js'))
11811182
@@ -1360,11 +1361,11 @@ def test_multiply_defined_libsymbols(self):
13601361 # we model shared libraries using regular object files. Without special handling
13611362 # fake `libA.so` could get linked multiple times.
13621363 self.cflags.remove('-Werror')
1363- self.emcc('libA.c', ['-shared', '-o', 'libA.so'])
1364+ self.emcc('libA.c', ['-sFAKE_DYLIBS', '- shared', '-fPIC ', '-o', 'libA.so'])
13641365
1365- err = self.emcc('a2.c', ['-shared', '-L.', '-lA', '-o', 'liba2.so'], stderr=PIPE).stderr
1366+ err = self.emcc('a2.c', ['-sFAKE_DYLIBS', '- shared', '-fPIC ', '-L.', '-lA', '-o', 'liba2.so'], stderr=PIPE).stderr
13661367 self.assertContained('emcc: warning: ignoring dynamic library libA.so when generating an object file', err)
1367- err = self.emcc('b2.c', ['-shared', '-L.', '-lA', '-o', 'libb2.so'], stderr=PIPE).stderr
1368+ err = self.emcc('b2.c', ['-sFAKE_DYLIBS', '- shared', '-fPIC ', '-L.', '-lA', '-o', 'libb2.so'], stderr=PIPE).stderr
13681369 self.assertContained('emcc: warning: ignoring dynamic library libA.so when generating an object file', err)
13691370
13701371 self.do_runf('main.c', 'result: 1', cflags=['-L.', '-lA', 'liba2.so', 'libb2.so'])
@@ -1495,7 +1496,12 @@ def test_link_group_bitcode(self):
14951496 # We deliberately ignore duplicate input files in order to allow
14961497 # "libA.so" on the command line twice. This is not really .so support
14971498 # and the .so files are really object files.
1498- def test_redundant_link(self):
1499+ @parameterized({
1500+ '': ([],),
1501+ 'fake_dylibs': (['-sFAKE_DYLIBS'],),
1502+ })
1503+ def test_redundant_link(self, args):
1504+ self.cflags += args
14991505 create_file('libA.c', 'int mult() { return 1; }')
15001506 create_file('main.c', r'''
15011507 #include <stdio.h>
@@ -1507,7 +1513,7 @@ def test_redundant_link(self):
15071513 ''')
15081514
15091515 self.cflags.remove('-Werror')
1510- self.emcc('libA.c', ['-shared', '-o', 'libA.so'])
1516+ self.emcc('libA.c', ['-fPIC', '- shared', '-o', 'libA.so'])
15111517 self.emcc('main.c', ['libA.so', 'libA.so', '-o', 'a.out.js'])
15121518 self.assertContained('result: 1', self.run_js('a.out.js'))
15131519
@@ -2155,9 +2161,9 @@ def test_multidynamic_link(self, link_flags, lib_suffix):
21552161 ''')
21562162
21572163 # Build libfile normally into an .so
2158- self.run_process([EMCC, 'libdir/libfile.c', '-shared', '-o', 'libdir/libfile.so' + lib_suffix])
2164+ self.run_process([EMCC, 'libdir/libfile.c', '-sFAKE_DYLIBS', '- shared', '-fPIC ', '-o', 'libdir/libfile.so' + lib_suffix])
21592165 # Build libother and dynamically link it to libfile
2160- self.run_process([EMCC, '-Llibdir', 'libdir/libother.c'] + link_flags + ['-shared', '-o', 'libdir/libother.so'])
2166+ self.run_process([EMCC, '-Llibdir', 'libdir/libother.c'] + link_flags + ['-sFAKE_DYLIBS', '- shared', '-fPIC ', '-o', 'libdir/libother.so'])
21612167 # Build the main file, linking in both the libs
21622168 self.run_process([EMCC, '-Llibdir', os.path.join('main.c')] + link_flags + ['-lother', '-c'])
21632169 print('...')
@@ -2462,17 +2468,17 @@ def test_dylink_library_search(self):
24622468 }
24632469 ''')
24642470
2465- # By deafult we use static linking and prefer libside.a
2466- self.do_runf('main.c', 'static linking used\n', cflags=['-L.', '-lside'])
2471+ # By default we use dynamic linking
2472+ self.do_runf('main.c', 'dynamic linking used\n', cflags=['-L.', '-lside'])
24672473
2468- # When using -sMAIN_MODULE we choose the dyanmic library
2469- self.do_runf('main.c', 'dynamic linking used\n', cflags=['-sMAIN_MODULE=2 ', '-L.', '-lside'])
2474+ # When using -sMAIN_MODULE=0 we explictly opt out of dynammic linking
2475+ self.do_runf('main.c', 'static linking used\n', cflags=['-sMAIN_MODULE=0 ', '-L.', '-lside'])
24702476
2471- # Same for `-sFAKE_DYLIBS=0
2472- self.do_runf('main.c', 'dynamic linking used\n', cflags=['-sFAKE_DYLIBS=0 ', '-L.', '-lside'])
2477+ # Same for `-sFAKE_DYLIBS
2478+ self.do_runf('main.c', 'static linking used\n', cflags=['-sFAKE_DYLIBS', '-L.', '-lside'])
24732479
24742480 # With can also force static linking using `-Bstatic` linker falgs
2475- self.do_runf('main.c', 'static linking used\n', cflags=['-sMAIN_MODULE=2', '- L.', '-Bstatic', '-lside'])
2481+ self.do_runf('main.c', 'static linking used\n', cflags=['-L.', '-Bstatic', '-lside'])
24762482
24772483 def test_js_link(self):
24782484 create_file('before.js', '''
@@ -4955,20 +4961,6 @@ def test_valid_abspath_2(self):
49554961 self.run_process(cmd)
49564962 self.assertContained('Hello, world!', self.run_js('a.out.js'))
49574963
4958- def test_warn_dylibs(self):
4959- shared_suffixes = ['.so', '.dylib', '.dll']
4960-
4961- for suffix in ('.o', '.bc', '.so', '.dylib', '.js', '.html'):
4962- print(suffix)
4963- cmd = [EMCC, test_file('hello_world.c'), '-o', 'out' + suffix]
4964- if suffix in {'.o', '.bc'}:
4965- cmd.append('-c')
4966- if suffix in {'.dylib', '.so'}:
4967- cmd.append('-shared')
4968- err = self.run_process(cmd, stderr=PIPE).stderr
4969- warning = 'linking a library with `-shared` will emit a static object file'
4970- self.assertContainedIf(warning, err, suffix in shared_suffixes)
4971-
49724964 @crossplatform
49734965 @parameterized({
49744966 'O2': [['-O2']],
@@ -8464,12 +8456,12 @@ def test_side_module_ignore(self):
84648456 self.run_process([EMCC, test_file('hello_world.c'), '-sSIDE_MODULE', '-o', 'libside.so'])
84658457
84668458 # Attempting to link statically against a side module (libside.so) should fail.
8467- self.assert_fail([EMCC, '-L.', '-lside'], 'wasm-ld: error: unable to find library -lside')
8459+ self.assert_fail([EMCC, '-L.', '-Bstatic', '- lside'], 'wasm-ld: error: unable to find library -lside')
84688460
84698461 # But a static library in the same location (libside.a) should take precedence.
84708462 self.run_process([EMCC, test_file('hello_world.c'), '-c'])
84718463 self.run_process([EMAR, 'cr', 'libside.a', 'hello_world.o'])
8472- self.run_process([EMCC, '-L.', '-lside'])
8464+ self.run_process([EMCC, '-L.', '-Bstatic', '- lside'])
84738465 self.assertContained('Hello, world!', self.run_js('a.out.js'))
84748466
84758467 @is_slow_test
@@ -12131,42 +12123,40 @@ def test_err(self):
1213112123 def test_euidaccess(self):
1213212124 self.do_other_test('test_euidaccess.c')
1213312125
12134- def test_shared_flag(self):
12135- create_file('side.c', 'int foo;')
12136- self.run_process([EMCC, '-shared', 'side.c', '-o', 'libother.so'])
12126+ def test_fake_dylibs(self):
12127+ create_file('other.c', 'int foo = 10;')
12128+ self.run_process([EMCC, '-shared', '-sFAKE_DYLIBS', '-fPIC', 'other.c', '-o', 'libother.so'])
12129+ self.assertIsObjectFile('libother.so')
1213712130
12138- # Test that `-shared ` flag causes object file generation but gives a warning
12139- err = self.run_process([EMCC, '-shared', test_file('hello_world.c'), '-o', 'out.foo', 'libother.so'], stderr=PIPE).stderr
12140- self.assertContained('linking a library with ` -shared` will emit a static object', err)
12131+ # Test that `-sFAKE_DYLIBS ` flag causes object file generation and will generate a warning about
12132+ # dylink dependencies being ignored.
12133+ err = self.run_process([EMCC, ' -shared', '-sFAKE_DYLIBS', '-fPIC', test_file('hello_world.c'), '-o', 'out.foo', 'libother.so'], stderr=PIPE).stderr
1214112134 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)
1214212135 self.assertIsObjectFile('out.foo')
1214312136
1214412137 # Test that adding `-sFAKE_DYLIBS=0` build a real side module
1214512138 err = self.run_process([EMCC, '-shared', '-fPIC', '-sFAKE_DYLIBS=0', test_file('hello_world.c'), '-o', 'out.foo', 'libother.so'], stderr=PIPE).stderr
12146- self.assertNotContained('linking a library with `-shared` will emit a static object', err)
1214712139 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)
1214812140 self.assertIsWasmDylib('out.foo')
1214912141
1215012142 # Test that using an executable output name overrides the `-shared` flag, but produces a warning.
12151- err = self.run_process([EMCC, '-shared', test_file('hello_world.c'), '-o', 'out.js'],
12143+ err = self.run_process([EMCC, '-shared', '-sFAKE_DYLIBS', '-fPIC', test_file('hello_world.c'), '-o', 'out.js'],
1215212144 stderr=PIPE).stderr
1215312145 self.assertContained('warning: -shared/-r used with executable output suffix', err)
1215412146 self.run_js('out.js')
1215512147
1215612148 def test_shared_soname(self):
12157- self.run_process([EMCC, '-shared', '-Wl,-soname', '-Wl,libfoo.so.13', test_file('hello_world.c'), '-lc', '-o', 'libfoo.so'])
12149+ self.run_process([EMCC, '-shared', '-sFAKE_DYLIBS', '- Wl,-soname', '-Wl,libfoo.so.13', test_file('hello_world.c'), '-lc', '-o', 'libfoo.so'])
1215812150 self.run_process([EMCC, '-sSTRICT', 'libfoo.so'])
1215912151 self.assertContained('Hello, world!', self.run_js('a.out.js'))
1216012152
12161- def test_shared_and_side_module_flag(self):
12162- # Test that `-shared` and `-sSIDE_MODULE` flag causes wasm dylib generation without a warning.
12163- err = self.run_process([EMCC, '-shared', '-sSIDE_MODULE', test_file('hello_world.c'), '-o', 'out.foo'], stderr=PIPE).stderr
12164- self.assertNotContained('linking a library with `-shared` will emit a static object', err)
12153+ def test_shared_flag(self):
12154+ # Test that `-shared` flag causes wasm dylib generation
12155+ self.run_process([EMCC, '-shared', '-fPIC', test_file('hello_world.c'), '-o', 'out.foo'])
1216512156 self.assertIsWasmDylib('out.foo')
1216612157
12167- # Test that `-shared` and `-sSIDE_MODULE` flag causes wasm dylib generation without a warning even if given executable output name.
12168- err = self.run_process([EMCC, '-shared', '-sSIDE_MODULE', test_file('hello_world.c'), '-o', 'out.wasm'],
12169- stderr=PIPE).stderr
12158+ # Test that `-shared` causes wasm dylib generation warning even if given executable output name.
12159+ err = self.run_process([EMCC, '-shared', '-fPIC', test_file('hello_world.c'), '-o', 'out.wasm'], stderr=PIPE).stderr
1217012160 self.assertNotContained('warning: -shared/-r used with executable output suffix', err)
1217112161 self.assertIsWasmDylib('out.wasm')
1217212162
0 commit comments