Mercurial > vanilla
comparison lib/compiler-rt/D28791.diff @ 350:819d906b465d
vanilla: create pure LLVM toolchain
- dev/lld is imported
- dev/llvm is built with libc++
- lib/compiler-rt is imported and used
- lib/libc++ is built with libunwind/libc++abi
- lib/libunwind is imported
- lib/openmp is imported
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 28 Mar 2019 20:58:49 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
349:7b000befead5 | 350:819d906b465d |
---|---|
1 Index: compiler-rt/CMakeLists.txt | |
2 =================================================================== | |
3 --- compiler-rt/CMakeLists.txt | |
4 +++ compiler-rt/CMakeLists.txt | |
5 @@ -29,6 +29,8 @@ | |
6 | |
7 option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON) | |
8 mark_as_advanced(COMPILER_RT_BUILD_BUILTINS) | |
9 +option(COMPILER_RT_BUILD_CRT "Build crtbegin.o/crtend.o" ON) | |
10 +mark_as_advanced(COMPILER_RT_BUILD_CRT) | |
11 option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON) | |
12 mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS) | |
13 option(COMPILER_RT_BUILD_XRAY "Build xray" ON) | |
14 Index: compiler-rt/cmake/Modules/AddCompilerRT.cmake | |
15 =================================================================== | |
16 --- compiler-rt/cmake/Modules/AddCompilerRT.cmake | |
17 +++ compiler-rt/cmake/Modules/AddCompilerRT.cmake | |
18 @@ -132,7 +132,7 @@ | |
19 # Adds static or shared runtime for a list of architectures and operating | |
20 # systems and puts it in the proper directory in the build and install trees. | |
21 # add_compiler_rt_runtime(<name> | |
22 -# {STATIC|SHARED} | |
23 +# {OBJECT|STATIC|SHARED} | |
24 # ARCHS <architectures> | |
25 # OS <os list> | |
26 # SOURCES <source files> | |
27 @@ -144,8 +144,8 @@ | |
28 # PARENT_TARGET <convenience parent target> | |
29 # ADDITIONAL_HEADERS <header files>) | |
30 function(add_compiler_rt_runtime name type) | |
31 - if(NOT type MATCHES "^(STATIC|SHARED)$") | |
32 - message(FATAL_ERROR "type argument must be STATIC or SHARED") | |
33 + if(NOT type MATCHES "^(OBJECT|STATIC|SHARED)$") | |
34 + message(FATAL_ERROR "type argument must be OBJECT, STATIC or SHARED") | |
35 return() | |
36 endif() | |
37 cmake_parse_arguments(LIB | |
38 @@ -204,7 +204,10 @@ | |
39 message(FATAL_ERROR "Architecture ${arch} can't be targeted") | |
40 return() | |
41 endif() | |
42 - if(type STREQUAL "STATIC") | |
43 + if(type STREQUAL "OBJECT") | |
44 + set(libname "${name}-${arch}") | |
45 + set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX}) | |
46 + elseif(type STREQUAL "STATIC") | |
47 set(libname "${name}-${arch}") | |
48 set_output_name(output_name_${libname} ${name} ${arch}) | |
49 else() | |
50 @@ -270,12 +273,34 @@ | |
51 set(COMPONENT_OPTION COMPONENT ${libname}) | |
52 endif() | |
53 | |
54 - add_library(${libname} ${type} ${sources_${libname}}) | |
55 - set_target_compile_flags(${libname} ${extra_cflags_${libname}}) | |
56 - set_target_link_flags(${libname} ${extra_link_flags_${libname}}) | |
57 - set_property(TARGET ${libname} APPEND PROPERTY | |
58 - COMPILE_DEFINITIONS ${LIB_DEFS}) | |
59 - set_target_output_directories(${libname} ${output_dir_${libname}}) | |
60 + if(type STREQUAL "OBJECT") | |
61 + string(TOUPPER ${CMAKE_BUILD_TYPE} config) | |
62 + get_property(cflags SOURCE ${sources_${libname}} PROPERTY COMPILE_FLAGS) | |
63 + separate_arguments(cflags) | |
64 + add_custom_command( | |
65 + OUTPUT ${output_dir_${libname}}/${libname}.o | |
66 + COMMAND ${CMAKE_C_COMPILER} ${sources_${libname}} ${cflags} ${extra_cflags_${libname}} -c -o ${output_dir_${libname}}/${libname}.o | |
67 + DEPENDS ${sources_${libname}} | |
68 + COMMENT "Building C object ${libname}.o") | |
69 + add_custom_target(${libname} DEPENDS ${output_dir_${libname}}/${libname}.o) | |
70 + install(FILES ${output_dir_${libname}}/${libname}.o | |
71 + DESTINATION ${install_dir_${libname}} | |
72 + ${COMPONENT_OPTION}) | |
73 + else() | |
74 + add_library(${libname} ${type} ${sources_${libname}}) | |
75 + set_target_compile_flags(${libname} ${extra_cflags_${libname}}) | |
76 + set_target_link_flags(${libname} ${extra_link_flags_${libname}}) | |
77 + set_property(TARGET ${libname} APPEND PROPERTY | |
78 + COMPILE_DEFINITIONS ${LIB_DEFS}) | |
79 + set_target_output_directories(${libname} ${output_dir_${libname}}) | |
80 + install(TARGETS ${libname} | |
81 + ARCHIVE DESTINATION ${install_dir_${libname}} | |
82 + ${COMPONENT_OPTION} | |
83 + LIBRARY DESTINATION ${install_dir_${libname}} | |
84 + ${COMPONENT_OPTION} | |
85 + RUNTIME DESTINATION ${install_dir_${libname}} | |
86 + ${COMPONENT_OPTION}) | |
87 + endif() | |
88 set_target_properties(${libname} PROPERTIES | |
89 OUTPUT_NAME ${output_name_${libname}}) | |
90 set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Runtime") | |
91 @@ -299,13 +324,6 @@ | |
92 ) | |
93 endif() | |
94 endif() | |
95 - install(TARGETS ${libname} | |
96 - ARCHIVE DESTINATION ${install_dir_${libname}} | |
97 - ${COMPONENT_OPTION} | |
98 - LIBRARY DESTINATION ${install_dir_${libname}} | |
99 - ${COMPONENT_OPTION} | |
100 - RUNTIME DESTINATION ${install_dir_${libname}} | |
101 - ${COMPONENT_OPTION}) | |
102 | |
103 # We only want to generate per-library install targets if you aren't using | |
104 # an IDE because the extra targets get cluttered in IDEs. | |
105 Index: compiler-rt/cmake/config-ix.cmake | |
106 =================================================================== | |
107 --- compiler-rt/cmake/config-ix.cmake | |
108 +++ compiler-rt/cmake/config-ix.cmake | |
109 @@ -227,6 +227,7 @@ | |
110 ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X}) | |
111 set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} | |
112 ${MIPS32} ${MIPS64} ${PPC64} ${S390X}) | |
113 +set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}) | |
114 set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) | |
115 set(ALL_FUZZER_SUPPORTED_ARCH ${X86_64} ${ARM64}) | |
116 | |
117 @@ -474,6 +475,7 @@ | |
118 SANITIZER_COMMON_SUPPORTED_ARCH) | |
119 | |
120 else() | |
121 + filter_available_targets(CRT_SUPPORTED_ARCH ${ALL_CRT_SUPPORTED_ARCH}) | |
122 # Architectures supported by compiler-rt libraries. | |
123 filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH | |
124 ${ALL_SANITIZER_COMMON_SUPPORTED_ARCH}) | |
125 @@ -563,6 +565,12 @@ | |
126 | |
127 # TODO: Add builtins support. | |
128 | |
129 +if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux") | |
130 + set(COMPILER_RT_HAS_CRT TRUE) | |
131 +else() | |
132 + set(COMPILER_RT_HAS_CRT FALSE) | |
133 +endif() | |
134 + | |
135 if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND | |
136 OS_NAME MATCHES "Linux") | |
137 set(COMPILER_RT_HAS_DFSAN TRUE) | |
138 Index: compiler-rt/lib/CMakeLists.txt | |
139 =================================================================== | |
140 --- compiler-rt/lib/CMakeLists.txt | |
141 +++ compiler-rt/lib/CMakeLists.txt | |
142 @@ -17,6 +17,10 @@ | |
143 add_subdirectory(builtins) | |
144 endif() | |
145 | |
146 +if(COMPILER_RT_BUILD_CRT) | |
147 + add_subdirectory(crt) | |
148 +endif() | |
149 + | |
150 function(compiler_rt_build_runtime runtime) | |
151 string(TOUPPER ${runtime} runtime_uppercase) | |
152 if(COMPILER_RT_HAS_${runtime_uppercase}) | |
153 Index: compiler-rt/lib/crt/CMakeLists.txt | |
154 =================================================================== | |
155 --- /dev/null | |
156 +++ compiler-rt/lib/crt/CMakeLists.txt | |
157 @@ -0,0 +1,102 @@ | |
158 +add_compiler_rt_component(crt) | |
159 + | |
160 +function(check_cxx_section_exists section output) | |
161 + cmake_parse_arguments(ARG "" "" "SOURCE;FLAGS" ${ARGN}) | |
162 + if(NOT ARG_SOURCE) | |
163 + set(ARG_SOURCE "int main() { return 0; }\n") | |
164 + endif() | |
165 + | |
166 + string(RANDOM TARGET_NAME) | |
167 + set(TARGET_NAME "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cmTC_${TARGET_NAME}.dir") | |
168 + file(MAKE_DIRECTORY ${TARGET_NAME}) | |
169 + | |
170 + file(WRITE "${TARGET_NAME}/CheckSectionExists.c" "${ARG_SOURCE}\n") | |
171 + | |
172 + string(REGEX MATCHALL "<[A-Za-z0-9_]*>" substitutions | |
173 + ${CMAKE_C_COMPILE_OBJECT}) | |
174 + | |
175 + set(try_compile_flags "${ARG_FLAGS}") | |
176 + if(CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_TARGET) | |
177 + list(APPEND try_compile_flags "-target ${CMAKE_C_COMPILER_TARGET}") | |
178 + endif() | |
179 + | |
180 + string(REPLACE ";" " " extra_flags "${try_compile_flags}") | |
181 + | |
182 + set(test_compile_command "${CMAKE_C_COMPILE_OBJECT}") | |
183 + foreach(substitution ${substitutions}) | |
184 + if(substitution STREQUAL "<CMAKE_C_COMPILER>") | |
185 + string(REPLACE "<CMAKE_C_COMPILER>" | |
186 + "${CMAKE_C_COMPILER}" test_compile_command ${test_compile_command}) | |
187 + elseif(substitution STREQUAL "<OBJECT>") | |
188 + string(REPLACE "<OBJECT>" "${TARGET_NAME}/CheckSectionExists.o" | |
189 + test_compile_command ${test_compile_command}) | |
190 + elseif(substitution STREQUAL "<SOURCE>") | |
191 + string(REPLACE "<SOURCE>" "${TARGET_NAME}/CheckSectionExists.c" | |
192 + test_compile_command ${test_compile_command}) | |
193 + elseif(substitution STREQUAL "<FLAGS>") | |
194 + string(REPLACE "<FLAGS>" "${CMAKE_C_FLAGS} ${extra_flags}" | |
195 + test_compile_command ${test_compile_command}) | |
196 + else() | |
197 + string(REPLACE "${substitution}" "" test_compile_command | |
198 + ${test_compile_command}) | |
199 + endif() | |
200 + endforeach() | |
201 + | |
202 + string(REPLACE " " ";" test_compile_command "${test_compile_command}") | |
203 + | |
204 + execute_process( | |
205 + COMMAND ${test_compile_command} | |
206 + RESULT_VARIABLE TEST_RESULT | |
207 + OUTPUT_VARIABLE TEST_OUTPUT | |
208 + ERROR_VARIABLE TEST_ERROR | |
209 + ) | |
210 + | |
211 + execute_process( | |
212 + COMMAND ${CMAKE_OBJDUMP} -h "${TARGET_NAME}/CheckSectionExists.o" | |
213 + RESULT_VARIABLE CHECK_RESULT | |
214 + OUTPUT_VARIABLE CHECK_OUTPUT | |
215 + ERROR_VARIABLE CHECK_ERROR | |
216 + ) | |
217 + string(FIND "${CHECK_OUTPUT}" "${section}" SECTION_FOUND) | |
218 + | |
219 + if(NOT SECTION_FOUND EQUAL -1) | |
220 + set(${output} TRUE PARENT_SCOPE) | |
221 + else() | |
222 + set(${output} FALSE PARENT_SCOPE) | |
223 + endif() | |
224 + | |
225 + file(REMOVE_RECURSE ${TARGET_NAME}) | |
226 +endfunction() | |
227 + | |
228 +check_cxx_section_exists(".init_array" COMPILER_RT_HAS_INITFINI_ARRAY | |
229 + SOURCE "__attribute__((constructor)) void f() {}\nint main() { return 0; }\n") | |
230 + | |
231 +append_list_if(COMPILER_RT_HAS_INITFINI_ARRAY -DCRT_HAS_INITFINI_ARRAY CRT_CFLAGS) | |
232 +append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC CRT_CFLAGS) | |
233 + | |
234 +foreach(arch ${CRT_SUPPORTED_ARCH}) | |
235 + add_compiler_rt_runtime(clang_rt.crtbegin | |
236 + OBJECT | |
237 + ARCHS ${arch} | |
238 + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtbegin.c | |
239 + CFLAGS ${CRT_CFLAGS} | |
240 + PARENT_TARGET crt) | |
241 + add_compiler_rt_runtime(clang_rt.crtbegin_shared | |
242 + OBJECT | |
243 + ARCHS ${arch} | |
244 + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtbegin.c | |
245 + CFLAGS ${CRT_CFLAGS} -DCRT_SHARED | |
246 + PARENT_TARGET crt) | |
247 + add_compiler_rt_runtime(clang_rt.crtend | |
248 + OBJECT | |
249 + ARCHS ${arch} | |
250 + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtend.c | |
251 + CFLAGS ${CRT_CFLAGS} | |
252 + PARENT_TARGET crt) | |
253 + add_compiler_rt_runtime(clang_rt.crtend_shared | |
254 + OBJECT | |
255 + ARCHS ${arch} | |
256 + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtend.c | |
257 + CFLAGS ${CRT_CFLAGS} -DCRT_SHARED | |
258 + PARENT_TARGET crt) | |
259 +endforeach() | |
260 Index: compiler-rt/lib/crt/crtbegin.c | |
261 =================================================================== | |
262 --- /dev/null | |
263 +++ compiler-rt/lib/crt/crtbegin.c | |
264 @@ -0,0 +1,108 @@ | |
265 +/* ===-- crtbegin.c - Start of constructors and destructors ----------------=== | |
266 + * | |
267 + * The LLVM Compiler Infrastructure | |
268 + * | |
269 + * This file is dual licensed under the MIT and the University of Illinois Open | |
270 + * Source Licenses. See LICENSE.TXT for details. | |
271 + * | |
272 + * ===----------------------------------------------------------------------=== | |
273 + */ | |
274 + | |
275 +#include <stddef.h> | |
276 + | |
277 +__attribute__((visibility("hidden"))) | |
278 +#ifdef CRT_SHARED | |
279 +void *__dso_handle = &__dso_handle; | |
280 +#else | |
281 +void *__dso_handle = (void *)0; | |
282 +#endif | |
283 + | |
284 +static long __EH_FRAME_LIST__[] | |
285 + __attribute__((section(".eh_frame"), aligned(sizeof(void *)))) = {}; | |
286 + | |
287 +extern void __register_frame_info(const void *, void *) __attribute__((weak)); | |
288 +extern void *__deregister_frame_info(const void *) __attribute__((weak)); | |
289 + | |
290 +#ifndef CRT_HAS_INITFINI_ARRAY | |
291 +typedef void (*fp)(void); | |
292 + | |
293 +static fp __CTOR_LIST__[] | |
294 + __attribute__((section(".ctors"), aligned(sizeof(fp)), used)) = {(fp)-1}; | |
295 +extern fp __CTOR_LIST_END__[]; | |
296 +#endif | |
297 + | |
298 +#ifdef CRT_SHARED | |
299 +extern void __cxa_finalize(void *) __attribute__((weak)); | |
300 +#endif | |
301 + | |
302 +static void __attribute__((used)) __do_init() { | |
303 + static _Bool __initialized; | |
304 + if (__builtin_expect(__initialized, 0)) | |
305 + return; | |
306 + __initialized = 1; | |
307 + | |
308 + static struct { void *p[8]; } __object; | |
309 + if (__register_frame_info) | |
310 + __register_frame_info(__EH_FRAME_LIST__, &__object); | |
311 + | |
312 +#ifndef CRT_HAS_INITFINI_ARRAY | |
313 + const size_t n = __CTOR_LIST_END__ - __CTOR_LIST__ - 1; | |
314 + for (size_t i = n; i >= 1; i--) __CTOR_LIST__[i](); | |
315 +#endif | |
316 +} | |
317 + | |
318 +#ifdef CRT_HAS_INITFINI_ARRAY | |
319 +__attribute__((section(".init_array"), | |
320 + used)) static void (*__init)(void) = __do_init; | |
321 +#else // CRT_HAS_INITFINI_ARRAY | |
322 +#if defined(__i386__) || defined(__x86_64__) | |
323 +asm(".pushsection .init,\"ax\",@progbits\n\t" | |
324 + "call " __USER_LABEL_PREFIX__ "__do_init\n\t" | |
325 + ".popsection"); | |
326 +#elif defined(__arm__) | |
327 +asm(".pushsection .init,\"ax\",%progbits\n\t" | |
328 + "bl " __USER_LABEL_PREFIX__ "__do_init\n\t" | |
329 + ".popsection"); | |
330 +#endif // CRT_HAS_INITFINI_ARRAY | |
331 +#endif | |
332 + | |
333 +#ifndef CRT_HAS_INITFINI_ARRAY | |
334 +static fp __DTOR_LIST__[] | |
335 + __attribute__((section(".dtors"), aligned(sizeof(fp)), used)) = {(fp)-1}; | |
336 +extern fp __DTOR_LIST_END__[]; | |
337 +#endif | |
338 + | |
339 +static void __attribute__((used)) __do_fini() { | |
340 + static _Bool __finalized; | |
341 + if (__builtin_expect(__finalized, 0)) | |
342 + return; | |
343 + __finalized = 1; | |
344 + | |
345 +#ifdef CRT_SHARED | |
346 + if (__cxa_finalize) | |
347 + __cxa_finalize(__dso_handle); | |
348 +#endif | |
349 + | |
350 +#ifndef CRT_HAS_INITFINI_ARRAY | |
351 + if (__deregister_frame_info) | |
352 + __deregister_frame_info(__EH_FRAME_LIST__); | |
353 + | |
354 + const size_t n = __DTOR_LIST_END__ - __DTOR_LIST__ - 1; | |
355 + for (size_t i = 1; i < n; i++) __DTOR_LIST__[i](); | |
356 +#endif | |
357 +} | |
358 + | |
359 +#ifdef CRT_HAS_INITFINI_ARRAY | |
360 +__attribute__((section(".fini_array"), | |
361 + used)) static void (*__fini)(void) = __do_fini; | |
362 +#else // CRT_HAS_INITFINI_ARRAY | |
363 +#if defined(__i386__) || defined(__x86_64__) | |
364 +asm(".pushsection .fini,\"ax\",@progbits\n\t" | |
365 + "call " __USER_LABEL_PREFIX__ "__do_fini\n\t" | |
366 + ".popsection"); | |
367 +#elif defined(__arm__) | |
368 +asm(".pushsection .fini,\"ax\",%progbits\n\t" | |
369 + "bl " __USER_LABEL_PREFIX__ "__do_fini\n\t" | |
370 + ".popsection"); | |
371 +#endif | |
372 +#endif // CRT_HAS_INIT_FINI_ARRAY | |
373 Index: compiler-rt/lib/crt/crtend.c | |
374 =================================================================== | |
375 --- /dev/null | |
376 +++ compiler-rt/lib/crt/crtend.c | |
377 @@ -0,0 +1,24 @@ | |
378 +/* ===-- crtend.c - End of constructors and destructors --------------------=== | |
379 + * | |
380 + * The LLVM Compiler Infrastructure | |
381 + * | |
382 + * This file is dual licensed under the MIT and the University of Illinois Open | |
383 + * Source Licenses. See LICENSE.TXT for details. | |
384 + * | |
385 + * ===----------------------------------------------------------------------=== | |
386 + */ | |
387 + | |
388 +#include <stdint.h> | |
389 + | |
390 +// Put 4-byte zero which is the length field in FDE at the end as a terminator. | |
391 +const int32_t __EH_FRAME_LIST_END__[] | |
392 + __attribute__((section(".eh_frame"), aligned(sizeof(int32_t)), | |
393 + visibility("hidden"), used)) = {0}; | |
394 + | |
395 +#ifndef CRT_HAS_INITFINI_ARRAY | |
396 +typedef void (*fp)(void); | |
397 +fp __CTOR_LIST_END__[] | |
398 + __attribute__((section(".ctors"), visibility("hidden"), used)) = {0}; | |
399 +fp __DTOR_LIST_END__[] | |
400 + __attribute__((section(".dtors"), visibility("hidden"), used)) = {0}; | |
401 +#endif | |
402 Index: compiler-rt/test/CMakeLists.txt | |
403 =================================================================== | |
404 --- compiler-rt/test/CMakeLists.txt | |
405 +++ compiler-rt/test/CMakeLists.txt | |
406 @@ -73,6 +73,9 @@ | |
407 if(COMPILER_RT_BUILD_XRAY) | |
408 compiler_rt_test_runtime(xray) | |
409 endif() | |
410 + if(COMPILER_RT_HAS_CRT) | |
411 + add_subdirectory(crt) | |
412 + endif() | |
413 # ShadowCallStack does not yet provide a runtime with compiler-rt, the tests | |
414 # include their own minimal runtime | |
415 add_subdirectory(shadowcallstack) | |
416 Index: compiler-rt/test/crt/CMakeLists.txt | |
417 =================================================================== | |
418 --- /dev/null | |
419 +++ compiler-rt/test/crt/CMakeLists.txt | |
420 @@ -0,0 +1,31 @@ | |
421 +set(CRT_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | |
422 + | |
423 +set(CRT_TESTSUITES) | |
424 + | |
425 +set(CRT_TEST_DEPS "") | |
426 + | |
427 +if(NOT COMPILER_RT_STANDALONE_BUILD AND COMPILER_RT_BUILD_CRT AND | |
428 + COMPILER_RT_HAS_CRT) | |
429 + list(APPEND CRT_TEST_DEPS crt) | |
430 +endif() | |
431 + | |
432 +set(CRT_TEST_ARCH ${CRT_SUPPORTED_ARCH}) | |
433 +if (COMPILER_RT_BUILD_CRT AND COMPILER_RT_HAS_CRT) | |
434 + foreach(arch ${CRT_TEST_ARCH}) | |
435 + set(CRT_TEST_TARGET_ARCH ${arch}) | |
436 + string(TOLOWER "-${arch}-${OS_NAME}" CRT_TEST_CONFIG_SUFFIX) | |
437 + get_test_cc_for_arch(${arch} CRT_TEST_TARGET_CC CRT_TEST_TARGET_CFLAGS) | |
438 + string(TOUPPER ${arch} ARCH_UPPER_CASE) | |
439 + set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config) | |
440 + | |
441 + configure_lit_site_cfg( | |
442 + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in | |
443 + ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg) | |
444 + list(APPEND CRT_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) | |
445 + endforeach() | |
446 +endif() | |
447 + | |
448 +add_lit_testsuite(check-crt "Running the CRT tests" | |
449 + ${CRT_TESTSUITES} | |
450 + DEPENDS ${CRT_TEST_DEPS}) | |
451 +set_target_properties(check-crt PROPERTIES FOLDER "Compiler-RT Misc") | |
452 Index: compiler-rt/test/crt/dso_handle.cpp | |
453 =================================================================== | |
454 --- /dev/null | |
455 +++ compiler-rt/test/crt/dso_handle.cpp | |
456 @@ -0,0 +1,33 @@ | |
457 +// RUN: %clangxx -g -DCRT_SHARED -c %s -fPIC -o %tshared.o | |
458 +// RUN: %clangxx -g -c %s -fPIC -o %t.o | |
459 +// RUN: %clangxx -g -shared -o %t.so -nostdlib %crti %shared_crtbegin %tshared.o %libstdcxx -lc -lm -lgcc_s %shared_crtend %crtn | |
460 +// RUN: %clangxx -g -o %t -nostdlib %crt1 %crti %crtbegin %t.o %libstdcxx -lc -lm %libgcc %t.so %crtend %crtn | |
461 +// RUN: %run %t 2>&1 | FileCheck %s | |
462 + | |
463 +#include <stdio.h> | |
464 + | |
465 +// CHECK: 1 | |
466 +// CHECK-NEXT: ~A() | |
467 + | |
468 +#ifdef CRT_SHARED | |
469 +bool G; | |
470 +void C() { | |
471 + printf("%d\n", G); | |
472 +} | |
473 + | |
474 +struct A { | |
475 + A() { G = true; } | |
476 + ~A() { | |
477 + printf("~A()\n"); | |
478 + } | |
479 +}; | |
480 + | |
481 +A a; | |
482 +#else | |
483 +void C(); | |
484 + | |
485 +int main() { | |
486 + C(); | |
487 + return 0; | |
488 +} | |
489 +#endif | |
490 Index: compiler-rt/test/crt/lit.cfg | |
491 =================================================================== | |
492 --- /dev/null | |
493 +++ compiler-rt/test/crt/lit.cfg | |
494 @@ -0,0 +1,80 @@ | |
495 +# -*- Python -*- | |
496 + | |
497 +import os | |
498 +import subprocess | |
499 + | |
500 +# Setup config name. | |
501 +config.name = 'CRT' + config.name_suffix | |
502 + | |
503 +# Setup source root. | |
504 +config.test_source_root = os.path.dirname(__file__) | |
505 + | |
506 + | |
507 +def get_library_path(file): | |
508 + cmd = subprocess.Popen([config.clang.strip(), | |
509 + config.target_cflags.strip(), | |
510 + '-print-file-name=%s' % file], | |
511 + stdout=subprocess.PIPE, | |
512 + env=config.environment) | |
513 + if not cmd.stdout: | |
514 + lit_config.fatal("Couldn't find the library path for '%s'" % file) | |
515 + dir = cmd.stdout.read().strip() | |
516 + if sys.platform in ['win32'] and execute_external: | |
517 + # Don't pass dosish path separator to msys bash.exe. | |
518 + dir = dir.replace('\\', '/') | |
519 + # Ensure the result is an ascii string, across Python2.5+ - Python3. | |
520 + return str(dir.decode('ascii')) | |
521 + | |
522 + | |
523 +def get_libgcc_file_name(): | |
524 + cmd = subprocess.Popen([config.clang.strip(), | |
525 + config.target_cflags.strip(), | |
526 + '-print-libgcc-file-name'], | |
527 + stdout=subprocess.PIPE, | |
528 + env=config.environment) | |
529 + if not cmd.stdout: | |
530 + lit_config.fatal("Couldn't find the library path for '%s'" % file) | |
531 + dir = cmd.stdout.read().strip() | |
532 + if sys.platform in ['win32'] and execute_external: | |
533 + # Don't pass dosish path separator to msys bash.exe. | |
534 + dir = dir.replace('\\', '/') | |
535 + # Ensure the result is an ascii string, across Python2.5+ - Python3. | |
536 + return str(dir.decode('ascii')) | |
537 + | |
538 + | |
539 +def build_invocation(compile_flags): | |
540 + return ' ' + ' '.join([config.clang] + compile_flags) + ' ' | |
541 + | |
542 + | |
543 +# Setup substitutions. | |
544 +config.substitutions.append( | |
545 + ('%clang ', build_invocation([config.target_cflags]))) | |
546 +config.substitutions.append( | |
547 + ('%clangxx ', | |
548 + build_invocation(config.cxx_mode_flags + [config.target_cflags]))) | |
549 + | |
550 +base_lib = os.path.join( | |
551 + config.compiler_rt_libdir, "clang_rt.%%s-%s.o" % config.target_arch) | |
552 +config.substitutions.append(('%crtbegin', base_lib % "crtbegin")) | |
553 +config.substitutions.append(('%shared_crtbegin', base_lib % "crtbegin_shared")) | |
554 +config.substitutions.append(('%crtend', base_lib % "crtend")) | |
555 +config.substitutions.append(('%shared_crtend', base_lib % "crtend_shared")) | |
556 + | |
557 +config.substitutions.append( | |
558 + ('%crt1', get_library_path('crt1.o'))) | |
559 +config.substitutions.append( | |
560 + ('%crti', get_library_path('crti.o'))) | |
561 +config.substitutions.append( | |
562 + ('%crtn', get_library_path('crtn.o'))) | |
563 + | |
564 +config.substitutions.append( | |
565 + ('%libgcc', get_libgcc_file_name())) | |
566 + | |
567 +config.substitutions.append( | |
568 + ('%libstdcxx', '-l' + config.sanitizer_cxx_lib.lstrip('lib'))) | |
569 + | |
570 +# Default test suffixes. | |
571 +config.suffixes = ['.c', '.cc', '.cpp'] | |
572 + | |
573 +if config.host_os not in ['Linux']: | |
574 + config.unsupported = True | |
575 Index: compiler-rt/test/crt/lit.site.cfg.in | |
576 =================================================================== | |
577 --- /dev/null | |
578 +++ compiler-rt/test/crt/lit.site.cfg.in | |
579 @@ -0,0 +1,14 @@ | |
580 +@LIT_SITE_CFG_IN_HEADER@ | |
581 + | |
582 +# Tool-specific config options. | |
583 +config.name_suffix = "@CRT_TEST_CONFIG_SUFFIX@" | |
584 +config.crt_lit_source_dir = "@CRT_LIT_SOURCE_DIR@" | |
585 +config.target_cflags = "@CRT_TEST_TARGET_CFLAGS@" | |
586 +config.target_arch = "@CRT_TEST_TARGET_ARCH@" | |
587 +config.sanitizer_cxx_lib = "@SANITIZER_TEST_CXX_LIBNAME@" | |
588 + | |
589 +# Load common config for all compiler-rt lit tests | |
590 +lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") | |
591 + | |
592 +# Load tool-specific config that would do the real work. | |
593 +lit_config.load_config(config, "@CRT_LIT_SOURCE_DIR@/lit.cfg") |