Skip to content

Commit 59094cf

Browse files
authored
Build crt1.o as a wasm object file (emscripten-core#9883)
The underlying issue is that if crt1.o is built with WASM_OBJECT_FILES=0 then it's a bitcode file. That appears to be linked together with the user's main before the linker would create the __original_main function. As a result, the trick with making that weak doesn't work. The proposed solution here is to build crt1.o as a wasm object file in all cases. Then it's linked in at the very end, and the optimization works.
1 parent c8dc6ee commit 59094cf

6 files changed

+19
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_start
2+
main
3+
memory
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$__original_main
2+
$_start
3+
$dlmalloc
4+
$main
5+
$sbrk
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
proc_exit
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
proc_exit

tests/test_other.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8250,6 +8250,10 @@ def test_metadce_hello_fastcomp(self, *args):
82508250
# Growth support code is in the wasm
82518251
'O3_grow_standalone': ('mem.c', ['-O3', '-s', 'ALLOW_MEMORY_GROWTH', '-s', 'STANDALONE_WASM'],
82528252
4, [], [], 6449, 4, 3, 6), # noqa
8253+
# without argc/argv, no support code for them is emitted, even with lto
8254+
'O3_standalone_narg_flto':
8255+
('mem_no_argv.c', ['-O3', '-s', 'STANDALONE_WASM', '-flto'],
8256+
1, [], [], 6309, 1, 3, 5), # noqa
82538257
})
82548258
@no_fastcomp()
82558259
def test_metadce_mem(self, filename, *args):

tools/system_libs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,12 +766,17 @@ class crt1(MuslInternalLibrary):
766766
src_dir = ['system', 'lib', 'libc']
767767
src_files = ['crt1.c']
768768

769+
force_object_files = True
770+
769771
def get_ext(self):
770772
return '.o'
771773

772774
def can_use(self):
773775
return shared.Settings.STANDALONE_WASM
774776

777+
def can_build(self):
778+
return shared.Settings.WASM_BACKEND
779+
775780

776781
class libc_extras(MuslInternalLibrary):
777782
"""This library is separate from libc itself for fastcomp only so that the

0 commit comments

Comments
 (0)