@@ -9,6 +9,8 @@ fn main() {
99 {
1010 // Build the unwinding from libunwind C/C++ source code.
1111 llvm_libunwind:: compile ( ) ;
12+ } else if target. contains ( "x86_64-fortanix-unknown-sgx" ) {
13+ llvm_libunwind:: compile ( ) ;
1214 } else if target. contains ( "linux" ) {
1315 if target. contains ( "musl" ) {
1416 // linking for musl is handled in lib.rs
@@ -55,6 +57,7 @@ mod llvm_libunwind {
5557
5658 /// Compile the libunwind C/C++ source code.
5759 pub fn compile ( ) {
60+ let target = env:: var ( "TARGET" ) . expect ( "TARGET was not set" ) ;
5861 let target_env = env:: var ( "CARGO_CFG_TARGET_ENV" ) . unwrap ( ) ;
5962 let target_vendor = env:: var ( "CARGO_CFG_TARGET_VENDOR" ) . unwrap ( ) ;
6063 let target_endian_little = env:: var ( "CARGO_CFG_TARGET_ENDIAN" ) . unwrap ( ) != "big" ;
@@ -75,6 +78,35 @@ mod llvm_libunwind {
7578 cfg. flag ( "/EHsc" ) ;
7679 cfg. define ( "_CRT_SECURE_NO_WARNINGS" , None ) ;
7780 cfg. define ( "_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS" , None ) ;
81+ } else if target. contains ( "x86_64-fortanix-unknown-sgx" ) {
82+ cfg. cpp ( false ) ;
83+
84+ cfg. static_flag ( true ) ;
85+ cfg. opt_level ( 3 ) ;
86+
87+ cfg. flag ( "-nostdinc++" ) ;
88+ cfg. flag ( "-fno-exceptions" ) ;
89+ cfg. flag ( "-fno-rtti" ) ;
90+ cfg. flag ( "-fstrict-aliasing" ) ;
91+ cfg. flag ( "-funwind-tables" ) ;
92+ cfg. flag ( "-fvisibility=hidden" ) ;
93+ cfg. flag ( "-fno-stack-protector" ) ;
94+ cfg. flag ( "-ffreestanding" ) ;
95+ cfg. flag ( "-fexceptions" ) ;
96+
97+ // easiest way to undefine since no API available in cc::Build to undefine
98+ cfg. flag ( "-U_FORTIFY_SOURCE" ) ;
99+ cfg. define ( "_FORTIFY_SOURCE" , "0" ) ;
100+
101+ cfg. flag_if_supported ( "-fvisibility-global-new-delete-hidden" ) ;
102+
103+ cfg. define ( "_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS" , None ) ;
104+ cfg. define ( "RUST_SGX" , "1" ) ;
105+ cfg. define ( "__NO_STRING_INLINES" , None ) ;
106+ cfg. define ( "__NO_MATH_INLINES" , None ) ;
107+ cfg. define ( "_LIBUNWIND_IS_BAREMETAL" , None ) ;
108+ cfg. define ( "__LIBUNWIND_IS_NATIVE_ONLY" , None ) ;
109+ cfg. define ( "NDEBUG" , None ) ;
78110 } else {
79111 cfg. flag ( "-std=c99" ) ;
80112 cfg. flag ( "-std=c++11" ) ;
@@ -103,6 +135,10 @@ mod llvm_libunwind {
103135 unwind_sources. push ( "Unwind_AppleExtras.cpp" ) ;
104136 }
105137
138+ if target. contains ( "x86_64-fortanix-unknown-sgx" ) {
139+ unwind_sources. push ( "UnwindRustSgx.c" ) ;
140+ }
141+
106142 let root = Path :: new ( "../llvm-project/libunwind" ) ;
107143 cfg. include ( root. join ( "include" ) ) ;
108144 for src in unwind_sources {
0 commit comments