Skip to content

Commit c88b34d

Browse files
committed
Remove fastcomp-only ALIASING_FUNCTION_POINTERS setting, plus some emscripten.py fastcomp code around it. See #11860
1 parent c6212ef commit c88b34d

File tree

8 files changed

+4
-234
lines changed

8 files changed

+4
-234
lines changed

emcc.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,9 +1447,6 @@ def check(input_file):
14471447
not shared.Settings.USE_PTHREADS:
14481448
shared.Settings.EXPORT_READY_PROMISE = 0
14491449

1450-
if shared.Settings.EMULATE_FUNCTION_POINTER_CASTS:
1451-
shared.Settings.ALIASING_FUNCTION_POINTERS = 0
1452-
14531450
if shared.Settings.LEGACY_VM_SUPPORT:
14541451
if not shared.Settings.WASM or shared.Settings.WASM2JS:
14551452
shared.Settings.POLYFILL_OLD_MATH_FUNCTIONS = 1

emscripten.py

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -53,70 +53,6 @@ def access_quote(prop):
5353
return '.' + prop
5454

5555

56-
def emscript_fastcomp(infile, outfile, memfile, temp_files, DEBUG):
57-
"""Runs the emscripten LLVM-to-JS compiler.
58-
59-
Args:
60-
infile: The path to the input LLVM assembly file.
61-
outfile: An open file object where the output is written.
62-
"""
63-
64-
assert shared.Settings.ASM_JS, 'fastcomp is asm.js-only (mode 1 or 2)'
65-
66-
success = False
67-
68-
try:
69-
70-
# Overview:
71-
# * Run LLVM backend to emit JS. JS includes function bodies, memory initializer,
72-
# and various metadata
73-
# * Run compiler.js on the metadata to emit the shell js code, pre/post-ambles,
74-
# JS library dependencies, etc.
75-
76-
# metadata is modified by reference in some of the below
77-
# these functions are split up to force variables to go out of scope and allow
78-
# memory to be reclaimed
79-
80-
with ToolchainProfiler.profile_block('get_and_parse_backend'):
81-
backend_output = compile_js(infile, temp_files, DEBUG)
82-
funcs, metadata, mem_init = parse_fastcomp_output(backend_output, DEBUG)
83-
fixup_metadata_tables(metadata)
84-
funcs = fixup_functions(funcs, metadata)
85-
with ToolchainProfiler.profile_block('compiler_glue'):
86-
glue, forwarded_data = compiler_glue(metadata, temp_files, DEBUG)
87-
88-
with ToolchainProfiler.profile_block('function_tables_and_exports'):
89-
(post, function_table_data, bundled_args) = (
90-
function_tables_and_exports(funcs, metadata, mem_init, glue, forwarded_data, outfile, DEBUG))
91-
with ToolchainProfiler.profile_block('write_output_file'):
92-
finalize_output(outfile, post, function_table_data, bundled_args, metadata, DEBUG)
93-
success = True
94-
95-
finally:
96-
outfile.close()
97-
if not success:
98-
shared.try_delete(outfile.name) # remove partial output
99-
100-
101-
def compile_js(infile, temp_files, DEBUG):
102-
"""Compile infile with asm.js backend, return the contents of the compiled js"""
103-
with temp_files.get_file('.4.js') as temp_js:
104-
backend_cmd = create_backend_cmd(infile, temp_js)
105-
106-
if DEBUG:
107-
logger.debug('emscript: llvm backend: ' + ' '.join(backend_cmd))
108-
t = time.time()
109-
shared.print_compiler_stage(backend_cmd)
110-
with ToolchainProfiler.profile_block('emscript_llvm_backend'):
111-
shared.check_call(backend_cmd)
112-
if DEBUG:
113-
logger.debug(' emscript: llvm backend took %s seconds' % (time.time() - t))
114-
115-
# Split up output
116-
backend_output = open(temp_js).read()
117-
return backend_output
118-
119-
12056
def parse_fastcomp_output(backend_output, DEBUG):
12157
start_funcs_marker = '// EMSCRIPTEN_START_FUNCTIONS'
12258
end_funcs_marker = '// EMSCRIPTEN_END_FUNCTIONS'
@@ -543,49 +479,6 @@ def write_output_file(outfile, post, module):
543479
outfile.write(post)
544480

545481

546-
def create_backend_cmd(infile, temp_js):
547-
"""Create asm.js backend command from settings dict"""
548-
args = [
549-
shared.LLVM_COMPILER, infile, '-march=js', '-filetype=asm', '-o', temp_js,
550-
'-emscripten-stack-size=%d' % shared.Settings.TOTAL_STACK,
551-
'-O%s' % shared.Settings.OPT_LEVEL,
552-
]
553-
if shared.Settings.USE_PTHREADS:
554-
args += ['-emscripten-enable-pthreads']
555-
if shared.Settings.WARN_UNALIGNED:
556-
args += ['-emscripten-warn-unaligned']
557-
if shared.Settings.RESERVED_FUNCTION_POINTERS > 0:
558-
args += ['-emscripten-reserved-function-pointers=%d' % shared.Settings.RESERVED_FUNCTION_POINTERS]
559-
if shared.Settings.ASSERTIONS > 0:
560-
args += ['-emscripten-assertions=%d' % shared.Settings.ASSERTIONS]
561-
if shared.Settings.ALIASING_FUNCTION_POINTERS == 0:
562-
args += ['-emscripten-no-aliasing-function-pointers']
563-
if shared.Settings.EMULATE_FUNCTION_POINTER_CASTS:
564-
args += ['-emscripten-emulate-function-pointer-casts']
565-
if shared.Settings.RELOCATABLE:
566-
args += ['-emscripten-relocatable']
567-
args += ['-emscripten-global-base=0']
568-
elif shared.Settings.GLOBAL_BASE >= 0:
569-
args += ['-emscripten-global-base=%d' % shared.Settings.GLOBAL_BASE]
570-
if shared.Settings.SIDE_MODULE:
571-
args += ['-emscripten-side-module']
572-
if shared.Settings.LEGALIZE_JS_FFI != 1:
573-
args += ['-emscripten-legalize-javascript-ffi=0']
574-
if shared.Settings.DISABLE_EXCEPTION_CATCHING != 1:
575-
args += ['-enable-emscripten-cpp-exceptions']
576-
if shared.Settings.DISABLE_EXCEPTION_CATCHING == 2:
577-
args += ['-emscripten-cpp-exceptions-whitelist=' + ','.join(shared.Settings.EXCEPTION_CATCHING_ALLOWED or ['fake'])]
578-
if not shared.Settings.EXIT_RUNTIME:
579-
args += ['-emscripten-no-exit-runtime']
580-
if shared.Settings.WORKAROUND_IOS_9_RIGHT_SHIFT_BUG:
581-
args += ['-emscripten-asmjs-work-around-ios-9-right-shift-bug']
582-
if shared.Settings.WASM:
583-
args += ['-emscripten-wasm']
584-
if building.is_wasm_only():
585-
args += ['-emscripten-only-wasm']
586-
return args
587-
588-
589482
def optimize_syscalls(declares, DEBUG):
590483
"""Disables filesystem if only a limited subset of syscalls is used.
591484
@@ -2444,7 +2337,7 @@ def run(infile, outfile, memfile):
24442337

24452338
outfile_obj = open(outfile, 'w')
24462339

2447-
emscripter = emscript_wasm_backend if shared.Settings.WASM_BACKEND else emscript_fastcomp
2340+
emscripter = emscript_wasm_backend
24482341
return temp_files.run_and_clean(lambda: emscripter(
24492342
infile, outfile_obj, memfile, temp_files, shared.DEBUG)
24502343
)

site/source/docs/porting/Debugging.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,11 @@ In order to debug these sorts of issues:
251251
- Compile with ``-Werror``. This turns warnings into errors, which can be useful as some cases of undefined behavior would otherwise show warnings.
252252
- Use ``-s ASSERTIONS=2`` to get some useful information about the function pointer being called, and its type.
253253
- Look at the browser stack trace to see where the error occurs and which function should have been called.
254-
- Build with :ref:`SAFE_HEAP=1 <debugging-SAFE-HEAP>` and function pointer aliasing disabled (``ALIASING_FUNCTION_POINTERS=0``). This should make it impossible for a function pointer to be called with the wrong type without raising an error: ``-s SAFE_HEAP=1 -s ALIASING_FUNCTION_POINTERS=0``
255-
254+
- Build with :ref:`SAFE_HEAP=1 <debugging-SAFE-HEAP>`.
255+
- :ref:`Sanitizers` can help here, in particular UBSan.
256256

257257
Another function pointer issue is when the wrong function is called. :ref:`SAFE_HEAP=1 <debugging-SAFE-HEAP>` can help with this as it detects some possible errors with function table accesses.
258258

259-
``ALIASING_FUNCTION_POINTERS=0`` is also useful because it ensures that calls to function pointer addresses in the wrong table result in clear errors. Without this setting such calls just execute whatever function is at the address, which can be much harder to debug.
260-
261-
262259

263260
Infinite loops
264261
--------------

src/settings.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,6 @@ var SAFE_HEAP_LOG = 0;
290290
// [fastcomp-only]
291291
var RESERVED_FUNCTION_POINTERS = 0;
292292

293-
// Whether to allow function pointers to alias if they have a different type.
294-
// This can greatly decrease table sizes in asm.js, but can break code that
295-
// compares function pointers across different types.
296-
// [fastcomp-only]
297-
var ALIASING_FUNCTION_POINTERS = 0;
298-
299293
// Allows function pointers to be cast, wraps each call of an incorrect type
300294
// with a runtime correction. This adds overhead and should not be used
301295
// normally. It also forces ALIASING_FUNCTION_POINTERS to 0. Aside from making
@@ -1757,4 +1751,5 @@ var LEGACY_SETTINGS = [
17571751
['FAST_UNROLLED_MEMCPY_AND_MEMSET', [0, 1], 'The wasm backend implements memcpy/memset in C'],
17581752
['DOUBLE_MODE', [0, 1], 'The wasm backend always implements doubles normally'],
17591753
['PRECISE_F32', [0, 1, 2], 'The wasm backend always implements floats normally'],
1754+
['ALIASING_FUNCTION_POINTERS', [0, 1], 'The wasm backend always uses a single index space for function pointers, in a single Table'],
17601755
];

tests/test_core.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6093,10 +6093,6 @@ def test_lua(self):
60936093
@needs_make('configure script')
60946094
@is_slow_test
60956095
def test_freetype(self):
6096-
if self.run_name == 'asm2g':
6097-
# flip for some more coverage here
6098-
self.set_setting('ALIASING_FUNCTION_POINTERS', 1 - self.get_setting('ALIASING_FUNCTION_POINTERS'))
6099-
61006096
self.add_pre_run("FS.createDataFile('/', 'font.ttf', %s, true, false, false);" % str(
61016097
list(bytearray(open(path_from_root('tests', 'freetype', 'LiberationSansBold.ttf'), 'rb').read()))
61026098
))
@@ -6908,11 +6904,6 @@ def test_add_function(self):
69086904
self.emcc_args = old
69096905
print(old)
69106906

6911-
print('with ALIASING_FUNCTION_POINTERS')
6912-
self.set_setting('ALIASING_FUNCTION_POINTERS', 1)
6913-
self.do_run_in_out_file_test('tests', 'interop', 'test_add_function')
6914-
self.clear_setting('ALIASING_FUNCTION_POINTERS')
6915-
69166907
print('with RESERVED_FUNCTION_POINTERS=0')
69176908
self.set_setting('RESERVED_FUNCTION_POINTERS', 0)
69186909

tests/test_other.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3932,56 +3932,6 @@ def test_bad_function_pointer_cast(self):
39323932
# non-informative error
39333933
self.assertContained(('abort(', 'exception'), output)
39343934

3935-
@no_wasm_backend('asm.js function table feature')
3936-
def test_aliased_func_pointers(self):
3937-
create_test_file('src.cpp', r'''
3938-
#include <stdio.h>
3939-
3940-
int impl1(int foo) { return foo; }
3941-
float impla(float foo) { return foo; }
3942-
int impl2(int foo) { return foo+1; }
3943-
float implb(float foo) { return foo+1; }
3944-
int impl3(int foo) { return foo+2; }
3945-
float implc(float foo) { return foo+2; }
3946-
3947-
int main(int argc, char **argv) {
3948-
volatile void *f = (void*)impl1;
3949-
if (argc == 50) f = (void*)impla;
3950-
if (argc == 51) f = (void*)impl2;
3951-
if (argc == 52) f = (void*)implb;
3952-
if (argc == 53) f = (void*)impl3;
3953-
if (argc == 54) f = (void*)implc;
3954-
return (int)f;
3955-
}
3956-
''')
3957-
3958-
print('aliasing')
3959-
3960-
sizes_ii = {}
3961-
sizes_dd = {}
3962-
3963-
for alias in [None, 0, 1]:
3964-
cmd = [EMCC, 'src.cpp', '-O1', '-s', 'WASM=0']
3965-
if alias is not None:
3966-
cmd += ['-s', 'ALIASING_FUNCTION_POINTERS=' + str(alias)]
3967-
else:
3968-
alias = -1
3969-
print(cmd)
3970-
self.run_process(cmd)
3971-
src = open('a.out.js').read().split('\n')
3972-
for line in src:
3973-
if line.strip().startswith('var FUNCTION_TABLE_ii = '):
3974-
sizes_ii[alias] = line.count(',')
3975-
if line.strip().startswith('var FUNCTION_TABLE_dd = '):
3976-
sizes_dd[alias] = line.count(',')
3977-
3978-
print('ii', sizes_ii)
3979-
print('dd', sizes_dd)
3980-
3981-
for sizes in [sizes_ii, sizes_dd]:
3982-
self.assertEqual(sizes[-1], sizes[1]) # default is to alias
3983-
self.assertLess(sizes[1], sizes[0]) # without aliasing, we have more unique values and fat tables
3984-
39853935
def test_bad_export(self):
39863936
for m in ['', ' ']:
39873937
self.clear()

tools/minified_js_name_generator.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

tools/shared.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,6 @@ def apply_opt_level(cls, opt_level, shrink_level=0, noisy=False):
10011001
if opt_level >= 1:
10021002
cls.attrs['ASM_JS'] = 1
10031003
cls.attrs['ASSERTIONS'] = 0
1004-
cls.attrs['ALIASING_FUNCTION_POINTERS'] = 1
10051004
if shrink_level >= 2:
10061005
cls.attrs['EVAL_CTORS'] = 1
10071006

0 commit comments

Comments
 (0)