summaryrefslogtreecommitdiff
path: root/packages/dev-libs/compiler-rt/files/8626a35a71f4398bc9b654b7375a2cdb17bd735d.patch
blob: 2b15b8ac1c8925baffc9883f3a2c5baab1bd885f (plain)
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
From 8626a35a71f4398bc9b654b7375a2cdb17bd735d Mon Sep 17 00:00:00 2001
From: Jian Cai <caij2003@gmail.com>
Date: Mon, 16 Sep 2019 21:47:47 +0000
Subject: [PATCH] [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

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@372038 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/crt/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/crt/CMakeLists.txt b/lib/crt/CMakeLists.txt
index 34c368f7ca..90e94b93db 100644
--- a/lib/crt/CMakeLists.txt
+++ b/lib/crt/CMakeLists.txt
@@ -70,7 +70,7 @@ function(check_cxx_section_exists section output)
 endfunction()
 
 check_cxx_section_exists(".init_array" COMPILER_RT_HAS_INITFINI_ARRAY
-  SOURCE "__attribute__((constructor)) void f() {}\nint main() { return 0; }\n")
+  SOURCE "volatile int x;\n__attribute__((constructor)) void f() {x = 0;}\nint main() { return 0; }\n")
 
 append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 CRT_CFLAGS)
 append_list_if(COMPILER_RT_HAS_INITFINI_ARRAY -DCRT_HAS_INITFINI_ARRAY CRT_CFLAGS)