Skip to content

Commit 155a43e

Browse files
committed
[compiler-rt][crt] make test case nontrivial in check_cxx_section_exists
Summary: .init_array gets optimized away when building with -O2 and as a result, check_cxx_section_exists failed to pass -DCOMPILER_RT_HAS_INITFINI_ARRAY when building crtbegin.o and crtend.o, which causes binaries linked with them encounter segmentation fault. See https://crbug.com/855759 for details. This change prevents .init_array section to be optimized away even with -O2 or higher optimization level. Subscribers: dberris, mgorny, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D67628 llvm-svn: 372038
1 parent 9d2066a commit 155a43e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

compiler-rt/lib/crt/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function(check_cxx_section_exists section output)
7070
endfunction()
7171

7272
check_cxx_section_exists(".init_array" COMPILER_RT_HAS_INITFINI_ARRAY
73-
SOURCE "__attribute__((constructor)) void f() {}\nint main() { return 0; }\n")
73+
SOURCE "volatile int x;\n__attribute__((constructor)) void f() {x = 0;}\nint main() { return 0; }\n")
7474

7575
append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 CRT_CFLAGS)
7676
append_list_if(COMPILER_RT_HAS_INITFINI_ARRAY -DCRT_HAS_INITFINI_ARRAY CRT_CFLAGS)

0 commit comments

Comments
 (0)