-
Notifications
You must be signed in to change notification settings - Fork 5
/
meson.build
313 lines (253 loc) · 9.03 KB
/
meson.build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#
# Project configuration, options, modules, scripts
#
project(
'gramine',
'c', 'cpp',
version: '1.7post~UNRELEASED',
license: 'LGPLv3+',
meson_version: '>=0.56',
default_options: [
'c_std=c11',
'cpp_std=c++14',
],
)
# If C23 (or experimetal C23 - C2x) is available, use it.
# TODO: Gramine supports older versions of gcc, so newer versions of compilers
# may not be available.
# We can change to c2x when we drop *EL8 and Ubuntu 20.04.
# We can't change to c23 for any supported versions yet (requires at
# least gcc 14).
if meson.get_compiler('c').has_argument('-std=c23')
add_project_arguments('-std=c23', language: 'c')
elif meson.get_compiler('c').has_argument('-std=c2x')
add_project_arguments('-std=c2x', language: 'c')
endif
# we need this subdir() early, because we need scripts defined there for setting up global vars
subdir('scripts')
pkglibdir = get_option('libdir') / meson.project_name()
pkgdatadir = get_option('datadir') / meson.project_name()
syslibdir = get_option('syslibdir')
if syslibdir == ''
syslibdir = '/' / get_option('libdir')
endif
direct = get_option('direct') == 'enabled'
sgx = get_option('sgx') == 'enabled'
vm = get_option('vm') == 'enabled'
tdx = get_option('tdx') == 'enabled'
skeleton = get_option('skeleton') == 'enabled'
dcap = get_option('dcap') == 'enabled'
ubsan = get_option('ubsan') == 'enabled'
asan = get_option('asan') == 'enabled'
vtune = get_option('vtune') == 'enabled'
enable_libgomp = get_option('libgomp') == 'enabled'
enable_tests = get_option('tests') == 'enabled'
cc = meson.get_compiler('c')
host_has_glibc = cc.get_define('__GLIBC__', prefix: '#include <features.h>') != ''
objcopy = find_program('objcopy')
pythonmod = import('python')
python3 = pythonmod.find_installation('python3')
# TODO: after meson 0.60 (already in Debian, Ubuntu from jammy, not yet in RHEL), use
# -Dpython.platlibdir
python3_platlib = run_command(
python3, get_python_platlib_prog, get_option('prefix')).stdout()
python3_pkgdir = python3_platlib / 'graminelibos'
pkgconfig = import('pkgconfig')
if host_machine.cpu_family() == 'x86_64'
nasm_gen = generator(
find_program('nasm'),
output: '@[email protected]',
depfile: '@[email protected]',
arguments: [
'-f', 'elf64',
'-p', '@SOURCE_DIR@/common/src/arch/x86_64/no_exec_stack.nasm',
'-I', '@0@/'.format(meson.current_build_dir()),
'-MQ', '@OUTPUT@', '-MF', '@DEPFILE@',
'@EXTRA_ARGS@',
'@INPUT@',
'-o', '@OUTPUT@'
]
)
endif
add_project_arguments(
'-Wa,--noexecstack',
'-Wall',
'-Wextra',
'-Wmissing-prototypes',
'-Wstrict-prototypes',
'-Wwrite-strings',
cc.get_supported_arguments(
'-Wtrampolines',
'-Wnull-dereference',
),
language: 'c')
debug = get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized'
if debug
add_project_arguments('-DDEBUG', language: 'c')
endif
if sgx
conf_sgx = configuration_data()
# SGX driver options
sgx_driver = get_option('sgx_driver')
sgx_driver_include_path = get_option('sgx_driver_include_path')
sgx_driver_device = get_option('sgx_driver_device')
if sgx_driver == 'upstream'
# upstream in-kernel driver (Linux 5.11+)
conf_sgx.set('CONFIG_SGX_DRIVER_UPSTREAM', true)
sgx_driver_header = 'asm/sgx.h'
sgx_driver_include_path_defaults = [
# standard /usr/include[/x86_64-linux-gnu] from linux-libc-dev
'',
# Ubuntu `linux-headers` package
'/usr/src/linux-headers-@0@/arch/x86/include/uapi'.format(
run_command('uname', '-r').stdout().strip()),
]
elif sgx_driver == 'oot'
# old non-DCAP driver (https://github.com/intel/linux-sgx-driver)
conf_sgx.set('CONFIG_SGX_DRIVER_OOT', true)
sgx_driver_header = 'sgx_user.h'
sgx_driver_include_path_defaults = ['/opt/intel/linux-sgx-driver']
else
error('Unknown sgx_driver value')
endif
if sgx_driver_device != ''
conf_sgx.set_quoted('CONFIG_SGX_DRIVER_DEVICE', sgx_driver_device)
endif
if sgx_driver_include_path == ''
foreach path : sgx_driver_include_path_defaults
if cc.has_header(path / sgx_driver_header)
sgx_driver_include_path = path
break
endif
endforeach
endif
sgx_driver_include = sgx_driver_include_path / sgx_driver_header
if not cc.has_header(sgx_driver_include)
error('Invalid SGX driver configuration (-Dsgx_driver and/or -Dsgx_driver_include_path); ' +
'expected "@0@" to exist under "@1@"'.format(
sgx_driver_header, sgx_driver_include_path))
endif
if vtune
add_project_arguments('-DSGX_VTUNE_PROFILE', language: 'c')
vtune_sdk_path = get_option('vtune_sdk_path')
endif
conf_sgx.set('CONFIG_SGX_DRIVER_INCLUDE', sgx_driver_include)
endif
if vm and host_machine.cpu_family() != 'x86_64'
error('VM PAL is currently available only for x86-64 arch')
endif
gen_symbol_map_cmd = [
find_program('nm'),
'--numeric-sort', '--defined-only', '--print-size', '--line-numbers',
'@INPUT@',
]
#
# Common checks and flags
#
# Not all compilers support mstack-protector-guard, so use stack protector only if supported.
# Gramine-custom stack protector uses the canary stored in the TCB (same for both in LibOS and PAL)
# at offset 0x8.
if host_machine.cpu_family() == 'x86_64'
cflags_custom_stack_protector = [
'-fstack-protector-strong',
'-mstack-protector-guard=tls',
'-mstack-protector-guard-reg=%gs',
'-mstack-protector-guard-offset=8',
]
else
cflags_custom_stack_protector = [
'-fstack-protector-strong',
]
endif
if not cc.has_multi_arguments(cflags_custom_stack_protector)
cflags_custom_stack_protector = '-fno-stack-protector'
endif
# Don't support b_sanitize: integration with sanitizers in Gramine is tricky and we want more
# control over the exact flags.
if get_option('b_sanitize') != 'none'
error('Please don\'t use the b_sanitize option; use -Dubsan=enabled instead.')
endif
cflags_sanitizers = []
if ubsan
cflags_sanitizers += [
'-fsanitize=undefined',
'-fno-sanitize-recover=undefined',
'-DUBSAN',
]
endif
if asan
if meson.get_compiler('c').get_id() != 'clang' or meson.get_compiler('cpp').get_id() != 'clang'
error('ASan is currently supported only for Clang (CC=clang CXX=clang++)')
endif
asan_shadow_start = '0x18000000000'
cflags_sanitizers += [
'-fsanitize=address',
'-fno-sanitize-link-runtime',
'-mllvm', '-asan-mapping-offset=' + asan_shadow_start,
'-DASAN',
]
if meson.get_compiler('c').version().version_compare('>=13')
cflags_sanitizers += ['-mllvm', '-asan-use-after-return=never']
else
cflags_sanitizers += ['-mllvm', '-asan-use-after-return=0']
endif
endif
#
# Dependencies
#
tomlc99_proj = subproject('tomlc99-208203af46bdbdb29ba199660ed78d09c220b6c5')
tomlc99_dep = tomlc99_proj.get_variable('tomlc99_dep')
tomlc99_src = tomlc99_proj.get_variable('tomlc99_src')
uthash_dep = subproject('uthash-2.1.0').get_variable('uthash_dep')
mbedtls_proj = subproject('mbedtls-3.6.0')
mbedtls_static_dep = mbedtls_proj.get_variable('mbedtls_static_dep')
mbedtls_pal_dep = mbedtls_proj.get_variable('mbedtls_pal_dep')
curl_proj = subproject('curl-8.8.0')
cjson_proj = subproject('cJSON-1.7.12')
if sgx
# XXX: do not call subproject() from under "if sgx" conditional, because it
# breaks `meson dist`: `-Dsgx` checks for presence of sgx.h header and we
# don't want to bother with finding the header just to create a tarball
# TODO: this ^ probably can be revised when all distros will have the header
# in <asm/sgx.h> so we won't have to mess with the paths anymore
protoc_c_prog = find_program('protoc-c')
if sgx_driver == 'oot'
protoc_prog = find_program('protoc')
endif
threads_dep = dependency('threads')
libcurl_dep = curl_proj.get_variable('curl_minimal_dep')
cjson_dep = cjson_proj.get_variable('cjson_dep')
protobuf_dep = dependency('libprotobuf-c')
if dcap
sgx_dcap_quoteverify_dep = cc.find_library('sgx_dcap_quoteverify')
endif
vtune_dep = []
dl_dep = []
if vtune
dl_dep = cc.find_library('dl', required: true)
vtune_dep = declare_dependency(
dependencies: [
cc.find_library('ittnotify', dirs: vtune_sdk_path / 'lib64', required: true),
dl_dep,
],
include_directories: include_directories(vtune_sdk_path / 'include'),
)
endif
endif
#
# The compilation
#
subdir('common')
subdir('pal')
subdir('libos')
subdir('python')
subdir('tools')
if get_option('libc') == 'glibc'
subproject('glibc-2.39-1')
elif get_option('libc') == 'musl'
subproject('musl-1.2.5')
endif
if enable_libgomp
subproject('gcc-10.2.0')
endif
run_target('clang-format', command: [meson_clang_format_prog])