@@ -9,6 +9,8 @@ fn main() {
9
9
{
10
10
// Build the unwinding from libunwind C/C++ source code.
11
11
llvm_libunwind:: compile ( ) ;
12
+ } else if target. contains ( "x86_64-fortanix-unknown-sgx" ) {
13
+ llvm_libunwind:: compile ( ) ;
12
14
} else if target. contains ( "linux" ) {
13
15
if target. contains ( "musl" ) {
14
16
// linking for musl is handled in lib.rs
@@ -55,6 +57,7 @@ mod llvm_libunwind {
55
57
56
58
/// Compile the libunwind C/C++ source code.
57
59
pub fn compile ( ) {
60
+ let target = env:: var ( "TARGET" ) . expect ( "TARGET was not set" ) ;
58
61
let target_env = env:: var ( "CARGO_CFG_TARGET_ENV" ) . unwrap ( ) ;
59
62
let target_vendor = env:: var ( "CARGO_CFG_TARGET_VENDOR" ) . unwrap ( ) ;
60
63
let target_endian_little = env:: var ( "CARGO_CFG_TARGET_ENDIAN" ) . unwrap ( ) != "big" ;
@@ -75,6 +78,35 @@ mod llvm_libunwind {
75
78
cfg. flag ( "/EHsc" ) ;
76
79
cfg. define ( "_CRT_SECURE_NO_WARNINGS" , None ) ;
77
80
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 ) ;
78
110
} else {
79
111
cfg. flag ( "-std=c99" ) ;
80
112
cfg. flag ( "-std=c++11" ) ;
@@ -103,6 +135,10 @@ mod llvm_libunwind {
103
135
unwind_sources. push ( "Unwind_AppleExtras.cpp" ) ;
104
136
}
105
137
138
+ if target. contains ( "x86_64-fortanix-unknown-sgx" ) {
139
+ unwind_sources. push ( "UnwindRustSgx.c" ) ;
140
+ }
141
+
106
142
let root = Path :: new ( "../llvm-project/libunwind" ) ;
107
143
cfg. include ( root. join ( "include" ) ) ;
108
144
for src in unwind_sources {
0 commit comments