@@ -2015,12 +2015,29 @@ def compile_to_debug_executable(compile_args):
2015
2015
self .assertLess (line_size , full_size )
2016
2016
2017
2017
def compile_to_release_executable (compile_args ):
2018
- return compile_to_executable (compile_args , [])
2018
+ return compile_to_executable (compile_args , ['-O1' ])
2019
2019
2020
2020
no_size , line_size , full_size = test (compile_to_release_executable )
2021
2021
self .assertEqual (no_size , line_size )
2022
2022
self .assertEqual (line_size , full_size )
2023
2023
2024
+ # "-O0 executable" means compiling without optimizations but *also* without
2025
+ # -g (so, not a true debug build). the results here may change over time,
2026
+ # since we are telling emcc both to try to do as little as possible during
2027
+ # link (-O0), but also that debug info is not needed (no -g). if we end up
2028
+ # doing post-link changes then we will strip the debug info, but if not then
2029
+ # we don't.
2030
+ def compile_to_O0_executable (compile_args ):
2031
+ return compile_to_executable (compile_args , [])
2032
+
2033
+ no_size , line_size , full_size = test (compile_to_O0_executable )
2034
+ # the difference between these two is due to the producer's section which
2035
+ # LLVM emits, and which we do not strip as this is not a release build.
2036
+ # the specific difference is that LLVM emits language info (C_plus_plus_14)
2037
+ # when emitting debug info, but not otherwise.
2038
+ self .assertLess (no_size , line_size )
2039
+ self .assertEqual (line_size , full_size )
2040
+
2024
2041
def test_dwarf (self ):
2025
2042
def compile_with_dwarf (args , output ):
2026
2043
# Test that -g enables dwarf info in object files and linked wasm
@@ -7862,13 +7879,23 @@ def test_separate_dwarf_with_filename_and_path(self):
7862
7879
with open ('a.out.wasm' , 'rb' ) as f :
7863
7880
self .assertIn (b'somewhere.com/hosted.wasm' , f .read ())
7864
7881
7865
- def test_wasm_producers_section (self ):
7866
- # no producers section by default
7867
- self .run_process ([EMCC , path_from_root ('tests' , 'hello_world.c' )])
7882
+ @parameterized ({
7883
+ 'O0' : (True , ['-O0' ]), # unoptimized builds try not to modify the LLVM wasm.
7884
+ 'O1' : (False , ['-O1' ]), # optimized builds strip the producer's section
7885
+ 'O2' : (False , ['-O2' ]), # by default.
7886
+ })
7887
+ def test_wasm_producers_section (self , expect_producers_by_default , args ):
7888
+ self .run_process ([EMCC , path_from_root ('tests' , 'hello_world.c' )] + args )
7868
7889
with open ('a.out.wasm' , 'rb' ) as f :
7869
- self .assertNotIn ('clang' , str (f .read ()))
7890
+ data = f .read ()
7891
+ if expect_producers_by_default :
7892
+ self .assertIn ('clang' , str (data ))
7893
+ return
7894
+ # if there is no producers section expected by default, verify that, and
7895
+ # see that the flag works to add it.
7896
+ self .assertNotIn ('clang' , str (data ))
7870
7897
size = os .path .getsize ('a.out.wasm' )
7871
- self .run_process ([EMCC , path_from_root ('tests' , 'hello_world.c' ), '-s' , 'EMIT_PRODUCERS_SECTION=1' ])
7898
+ self .run_process ([EMCC , path_from_root ('tests' , 'hello_world.c' ), '-s' , 'EMIT_PRODUCERS_SECTION=1' ] + args )
7872
7899
with open ('a.out.wasm' , 'rb' ) as f :
7873
7900
self .assertIn ('clang' , str (f .read ()))
7874
7901
size_with_section = os .path .getsize ('a.out.wasm' )
0 commit comments