Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix initial value of sbrk(0) #9553

Merged
merged 4 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3001,6 +3001,8 @@ def do_binaryen(target, asm_target, options, memfile, wasm_binary_target,
# (we can't add this value when we placed post-emscripten in the proper position in the list of
# passes because that was before the value was computed)
options.binaryen_passes += ['--pass-arg=emscripten-sbrk-ptr@%d' % shared.Settings.DYNAMICTOP_PTR]
if shared.Settings.STANDALONE_WASM:
options.binaryen_passes += ['--pass-arg=emscripten-sbrk-val@%d' % shared.Settings.DYNAMIC_BASE]
if DEBUG:
shared.safe_copy(wasm_binary_target, os.path.join(shared.get_emscripten_temp_dir(), os.path.basename(wasm_binary_target) + '.pre-byn'))
cmd = [os.path.join(binaryen_bin, 'wasm-opt'), wasm_binary_target, '-o', wasm_binary_target] + options.binaryen_passes
Expand Down
2 changes: 2 additions & 0 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,8 @@ def apply_memory(js):

logger.debug('global_base: %d stack_base: %d, stack_max: %d, dynamic_base: %d, static bump: %d', memory.global_base, memory.stack_base, memory.stack_max, memory.dynamic_base, memory.static_bump)

shared.Settings.DYNAMIC_BASE = memory.dynamic_base

return js


Expand Down
2 changes: 2 additions & 0 deletions src/runtime_init_memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ updateGlobalBufferAndViews(buffer);
#if USE_PTHREADS
if (!ENVIRONMENT_IS_PTHREAD) { // Pthreads have already initialized these variables in src/worker.js, where they were passed to the thread worker at startup time
#endif
#if !STANDALONE_WASM // in standalone mode the value is in the wasm
HEAP32[DYNAMICTOP_PTR>>2] = DYNAMIC_BASE;
#endif // !STANDALONE_WASM
#if USE_PTHREADS
}
#endif
4 changes: 4 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,10 @@ var MAIN_READS_PARAMS = 1;
// The computed location of the pointer to the sbrk position.
var DYNAMICTOP_PTR = -1;

// The computed initial value of the program break (the sbrk position), which
// is called DYNAMIC_BASE as it is the start of dynamically-allocated memory.
var DYNAMIC_BASE = -1;

// Legacy settings that have been removed or renamed.
// For renamed settings the format is:
// [OLD_NAME, NEW_NAME]
Expand Down
1 change: 1 addition & 0 deletions tests/other/metadce/hello_world_Oz.exports
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
c
d
1 change: 1 addition & 0 deletions tests/other/metadce/hello_world_Oz.funcs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $__fwritex
$__overflow
$__stdio_write
$__towrite
$__wasm_call_ctors
$fwrite
$main
$memcpy
Expand Down
1 change: 1 addition & 0 deletions tests/other/metadce/minimal_Oz.exports
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
a
b
1 change: 1 addition & 0 deletions tests/other/metadce/minimal_Oz.funcs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
$__wasm_call_ctors
$add
5 changes: 3 additions & 2 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -7348,6 +7348,7 @@ def test(p1, p2, p3, last, expected):
print(first, second, third)
assert first < second and second < third, [first, second, third]

@no_wasm_backend('ctor evaller disabled, see https://github.com/emscripten-core/emscripten/issues/9527')
@uses_canonical_tmp
@with_env_modify({'EMCC_DEBUG': '1'})
def test_eval_ctors_debug_output(self):
Expand Down Expand Up @@ -8089,7 +8090,7 @@ def strip_numeric_suffixes(funcname):
# in -O3, -Os and -Oz we metadce, and they shrink it down to the minimal output we want
'O3': (['-O3'], 2, [], [], 85, 0, 2, 2), # noqa
'Os': (['-Os'], 2, [], [], 85, 0, 2, 2), # noqa
'Oz': (['-Oz'], 2, [], [], 54, 0, 1, 1), # noqa
'Oz': (['-Oz'], 2, [], [], 85, 0, 2, 2), # noqa
})
@no_fastcomp()
def test_binaryen_metadce_minimal(self, *args):
Expand Down Expand Up @@ -8130,7 +8131,7 @@ def test_binaryen_metadce_cxx_fastcomp(self, *args):
'O2': (['-O2'], 7, [], ['waka'], 10183, 6, 14, 24), # noqa
'O3': (['-O3'], 4, [], [], 1957, 4, 2, 12), # noqa; in -O3, -Os and -Oz we metadce
'Os': (['-Os'], 4, [], [], 1963, 4, 2, 12), # noqa
'Oz': (['-Oz'], 4, [], [], 1929, 4, 1, 11), # noqa
'Oz': (['-Oz'], 4, [], [], 1929, 4, 2, 12), # noqa
# finally, check what happens when we export nothing. wasm should be almost empty
'export_nothing':
(['-Os', '-s', 'EXPORTED_FUNCTIONS=[]'],
Expand Down
5 changes: 4 additions & 1 deletion tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,10 @@ def apply_opt_level(cls, opt_level, shrink_level=0, noisy=False):
cls.attrs['ASSERTIONS'] = 0
cls.attrs['ALIASING_FUNCTION_POINTERS'] = 1
if shrink_level >= 2:
cls.attrs['EVAL_CTORS'] = 1
# Ctor evalling in the wasm backend is disabled due to
# https://github.com/emscripten-core/emscripten/issues/9527
if not Settings.WASM_BACKEND:
cls.attrs['EVAL_CTORS'] = 1

def keys(self):
return self.attrs.keys()
Expand Down