59
59
C_ENDINGS = ('.c' , '.i' )
60
60
CXX_ENDINGS = ('.cpp' , '.cxx' , '.cc' , '.c++' , '.CPP' , '.CXX' , '.C' , '.CC' , '.C++' , '.ii' )
61
61
OBJC_ENDINGS = ('.m' , '.mi' )
62
+ PREPROCESSED_ENDINGS = ('.i' , '.ii' )
62
63
OBJCXX_ENDINGS = ('.mm' , '.mii' )
63
64
SPECIAL_ENDINGLESS_FILENAMES = (os .devnull ,)
64
65
@@ -822,10 +823,50 @@ def array_contains_any_of(hay, needles):
822
823
return cflags + ['-Xclang' , '-iwithsysroot' + os .path .join ('/include' , 'compat' )]
823
824
824
825
825
- def get_clang_flags ():
826
+ def get_target_flags ():
826
827
return ['-target' , shared .get_llvm_target ()]
827
828
828
829
830
+ def get_clang_flags (user_args ):
831
+ flags = get_target_flags ()
832
+
833
+ # if exception catching is disabled, we can prevent that code from being
834
+ # generated in the frontend
835
+ if settings .DISABLE_EXCEPTION_CATCHING and not settings .WASM_EXCEPTIONS :
836
+ flags .append ('-fignore-exceptions' )
837
+
838
+ if settings .INLINING_LIMIT :
839
+ flags .append ('-fno-inline-functions' )
840
+
841
+ if settings .RELOCATABLE and '-fPIC' not in user_args :
842
+ flags .append ('-fPIC' )
843
+
844
+ # We use default visiibilty=default in emscripten even though the upstream
845
+ # backend defaults visibility=hidden. This matched the expectations of C/C++
846
+ # code in the wild which expects undecorated symbols to be exported to other
847
+ # DSO's by default.
848
+ if not any (a .startswith ('-fvisibility' ) for a in user_args ):
849
+ flags .append ('-fvisibility=default' )
850
+
851
+ if settings .LTO :
852
+ if not any (a .startswith ('-flto' ) for a in user_args ):
853
+ flags .append ('-flto=' + settings .LTO )
854
+ # setjmp/longjmp handling using Wasm EH
855
+ # For non-LTO, '-mllvm -wasm-enable-eh' added in
856
+ # building.llvm_backend_args() sets this feature in clang. But in LTO, the
857
+ # argument is added to wasm-ld instead, so clang needs to know that EH is
858
+ # enabled so that it can be added to the attributes in LLVM IR.
859
+ if settings .SUPPORT_LONGJMP == 'wasm' :
860
+ flags .append ('-mexception-handling' )
861
+
862
+ else :
863
+ # In LTO mode these args get passed instead at link time when the backend runs.
864
+ for a in building .llvm_backend_args ():
865
+ flags += ['-mllvm' , a ]
866
+
867
+ return flags
868
+
869
+
829
870
cflags = None
830
871
831
872
@@ -836,7 +877,7 @@ def get_cflags(user_args):
836
877
837
878
# Flags we pass to the compiler when building C/C++ code
838
879
# We add these to the user's flags (newargs), but not when building .s or .S assembly files
839
- cflags = get_clang_flags ()
880
+ cflags = get_clang_flags (user_args )
840
881
841
882
if settings .EMSCRIPTEN_TRACING :
842
883
cflags .append ('-D__EMSCRIPTEN_TRACING__=1' )
@@ -858,40 +899,6 @@ def get_cflags(user_args):
858
899
'-D__EMSCRIPTEN_minor__=' + str (shared .EMSCRIPTEN_VERSION_MINOR ),
859
900
'-D__EMSCRIPTEN_tiny__=' + str (shared .EMSCRIPTEN_VERSION_TINY )]
860
901
861
- # if exception catching is disabled, we can prevent that code from being
862
- # generated in the frontend
863
- if settings .DISABLE_EXCEPTION_CATCHING and not settings .WASM_EXCEPTIONS :
864
- cflags .append ('-fignore-exceptions' )
865
-
866
- if settings .INLINING_LIMIT :
867
- cflags .append ('-fno-inline-functions' )
868
-
869
- if settings .RELOCATABLE and '-fPIC' not in user_args :
870
- cflags .append ('-fPIC' )
871
-
872
- # We use default visiibilty=default in emscripten even though the upstream
873
- # backend defaults visibility=hidden. This matched the expectations of C/C++
874
- # code in the wild which expects undecorated symbols to be exported to other
875
- # DSO's by default.
876
- if not any (a .startswith ('-fvisibility' ) for a in user_args ):
877
- cflags .append ('-fvisibility=default' )
878
-
879
- if settings .LTO :
880
- if not any (a .startswith ('-flto' ) for a in user_args ):
881
- cflags .append ('-flto=' + settings .LTO )
882
- # setjmp/longjmp handling using Wasm EH
883
- # For non-LTO, '-mllvm -wasm-enable-eh' added in
884
- # building.llvm_backend_args() sets this feature in clang. But in LTO, the
885
- # argument is added to wasm-ld instead, so clang needs to know that EH is
886
- # enabled so that it can be added to the attributes in LLVM IR.
887
- if settings .SUPPORT_LONGJMP == 'wasm' :
888
- cflags .append ('-mexception-handling' )
889
-
890
- else :
891
- # In LTO mode these args get passed instead at link time when the backend runs.
892
- for a in building .llvm_backend_args ():
893
- cflags += ['-mllvm' , a ]
894
-
895
902
# Changes to default clang behavior
896
903
897
904
# Implicit functions can cause horribly confusing function pointer type errors, see #2175
@@ -1045,7 +1052,7 @@ def run(args):
1045
1052
if len (args ) == 2 and args [1 ] == '-v' :
1046
1053
# autoconf likes to see 'GNU' in the output to enable shared object support
1047
1054
print (version_string (), file = sys .stderr )
1048
- return shared .check_call ([clang , '-v' ] + get_clang_flags (), check = False ).returncode
1055
+ return shared .check_call ([clang , '-v' ] + get_target_flags (), check = False ).returncode
1049
1056
1050
1057
# Additional compiler flags that we treat as if they were passed to us on the
1051
1058
# commandline
@@ -2709,8 +2716,11 @@ def get_compiler(src_file):
2709
2716
def get_clang_command (src_file ):
2710
2717
return get_compiler (src_file ) + get_cflags (state .orig_args ) + compile_args + [src_file ]
2711
2718
2719
+ def get_clang_command_preprocessed (src_file ):
2720
+ return get_compiler (src_file ) + get_clang_flags (state .orig_args ) + compile_args + [src_file ]
2721
+
2712
2722
def get_clang_command_asm (src_file ):
2713
- return get_compiler (src_file ) + get_clang_flags () + compile_args + [src_file ]
2723
+ return get_compiler (src_file ) + get_target_flags () + compile_args + [src_file ]
2714
2724
2715
2725
# preprocessor-only (-E) support
2716
2726
if state .mode == Mode .PREPROCESS_ONLY :
@@ -2765,6 +2775,8 @@ def compile_source_file(i, input_file):
2765
2775
linker_inputs .append ((i , output_file ))
2766
2776
if get_file_suffix (input_file ) in ASSEMBLY_ENDINGS :
2767
2777
cmd = get_clang_command_asm (input_file )
2778
+ elif get_file_suffix (input_file ) in PREPROCESSED_ENDINGS :
2779
+ cmd = get_clang_command_preprocessed (input_file )
2768
2780
else :
2769
2781
cmd = get_clang_command (input_file )
2770
2782
if not state .has_dash_c :
0 commit comments