Skip to content

Commit

Permalink
Allow wasm object files as input, even when WASM_OBJECT_FILES=0 is set (
Browse files Browse the repository at this point in the history
emscripten-core#8600)

Specifying WASM_OBJECT_FILES=0 on the link line is current needed if
one want to select LTO libraries.  However this should not exclude
some input being wasm object files.

Fixes emscripten-core#8599
  • Loading branch information
sbc100 authored and belraquib committed Dec 23, 2020
1 parent 152f886 commit a9bd24f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
6 changes: 3 additions & 3 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,9 @@ def optimizing(opts):
has_header_inputs = True
elif file_suffix.endswith(ASSEMBLY_ENDINGS) or shared.Building.is_bitcode(arg) or shared.Building.is_ar(arg):
input_files.append((i, arg))
elif 'WASM_OBJECT_FILES=0' not in settings_changes and shared.Building.is_wasm(arg):
# this is before libraries, since wasm static libraries (wasm.so that contains wasm) are just
# object files to be linked
elif shared.Building.is_wasm(arg):
if not shared.Settings.WASM_BACKEND:
exit_with_error('fastcomp is not compatible with wasm object files:' + arg)
input_files.append((i, arg))
elif file_suffix.endswith(STATICLIB_ENDINGS + DYNAMICLIB_ENDINGS):
# if it's not, and it's a library, just add it to libs to find later
Expand Down
2 changes: 2 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,8 @@ var WASM_BACKEND = 0;

// Whether to compile object files as wasm as opposed to the default
// of using LLVM IR.
// Setting to zero will enable LTO and at link time will also enable bitcode
// versions of the standard libraries.
var WASM_OBJECT_FILES = 1;

// An optional comma-separated list of script hooks to run after binaryen,
Expand Down
31 changes: 23 additions & 8 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -8130,24 +8130,39 @@ def test_wasm_targets_side_module(self):
assert not x.endswith('.js'), 'we should not emit js when making a wasm side module: ' + x
self.assertIn(b'dylink', open(target, 'rb').read())

@no_fastcomp('uses upstream specific option: WASM_OBJECT_FILES')
def test_wasm_backend_lto(self):
# test building of non-wasm-object-files libraries, building with them, and running them
if not self.is_wasm_backend():
self.skipTest('not using wasm backend')

src = path_from_root('tests', 'hello_libcxx.cpp')
# test codegen in lto mode, and compare to normal (wasm object) mode
for args in [[], ['-O1'], ['-O2'], ['-O3'], ['-Os'], ['-Oz']]:
print(args)

print('wasm in object')
run_process([PYTHON, EMCC, path_from_root('tests', 'hello_libcxx.cpp')] + args + ['-c', '-o', 'a.o'])
assert shared.Building.is_wasm('a.o') and not shared.Building.is_bitcode('a.o')
run_process([PYTHON, EMXX, src] + args + ['-c', '-o', 'hello_obj.o'])
self.assertTrue(shared.Building.is_wasm('hello_obj.o'))
self.assertFalse(shared.Building.is_bitcode('hello_obj.o'))

print('bitcode in object')
run_process([PYTHON, EMCC, path_from_root('tests', 'hello_libcxx.cpp')] + args + ['-c', '-o', 'a.o', '-s', 'WASM_OBJECT_FILES=0'])
assert not shared.Building.is_wasm('a.o') and shared.Building.is_bitcode('a.o')
print('build bitcode object')
run_process([PYTHON, EMCC, 'a.o'] + args + ['-s', 'WASM_OBJECT_FILES=0'])
run_process([PYTHON, EMXX, src] + args + ['-c', '-o', 'hello_bitcode.o', '-s', 'WASM_OBJECT_FILES=0'])
self.assertFalse(shared.Building.is_wasm('hello_bitcode.o'))
self.assertTrue(shared.Building.is_bitcode('hello_bitcode.o'))

print('use bitcode object (LTO)')
run_process([PYTHON, EMXX, 'hello_bitcode.o'] + args + ['-s', 'WASM_OBJECT_FILES=0'])
self.assertContained('hello, world!', run_js('a.out.js'))
print('use bitcode object (non-LTO)')
run_process([PYTHON, EMXX, 'hello_bitcode.o'] + args + ['-s', 'WASM_OBJECT_FILES=1'])
self.assertContained('hello, world!', run_js('a.out.js'))

print('use native object (LTO)')
run_process([PYTHON, EMXX, 'hello_obj.o'] + args + ['-s', 'WASM_OBJECT_FILES=0'])
self.assertContained('hello, world!', run_js('a.out.js'))
print('build with bitcode')
run_process([PYTHON, EMCC, path_from_root('tests', 'hello_libcxx.cpp')] + args + ['-s', 'WASM_OBJECT_FILES=0'])
print('use native object (non-LTO)')
run_process([PYTHON, EMXX, 'hello_obj.o'] + args + ['-s', 'WASM_OBJECT_FILES=1'])
self.assertContained('hello, world!', run_js('a.out.js'))

def test_wasm_nope(self):
Expand Down

0 comments on commit a9bd24f

Please sign in to comment.