Linux/ARM: Use -O1 level to avoid segfault in release-build for Linux/ARM (#4904)
We cannot still run 'hello world' console application even though
the cross compilation of CoreCLR is successfully completed.
In release-build, the segmentation fault of 'hello world'
is made by the misalignment of thread local storage (TLS) section
because of the aggressive optimization level of clang compiler for
code optimization(e.g., file size and execution speed).
It means that Clang/LLVM has a bug in case of the usage of O2/O3 flag.
Below is the major difference among the optimization levels of Clang.
* -O2 is based on -O1:
.adding: -gvn -constmerge -globaldce -slp-vectorizer -mldst-motion -inline
.removing: -always-inline
* -O3 is based on -O2:
.adding: -argpromotion
ver2:
- Corerun is loading 'libcoreclr.so' using dlopen() library call. So, we can not
use initial-exec TLS model (ver1) because of the thread-safe issue of
the multi-threaded. (Reported by @janvorli)
- In the release-build, Let's replace -O3 with -O1 to avoid the segmentation
fault due to the aggressive optimization level of the Clang until fixing
the bug of the Clang/LLVM.
ver1:
- The default value of clang is "global-dynamic". However, the thread-local
storage (TLS) model of Clang/LLVM does not guarantee the normal execution
of TLS's symbol relocation due to the misaligned __tls_get_addr symbol in
case of the aggressive optimizations of Clang on Linux/ARM.
- Let's enable initial-exec TLS model instead of the dynamic TLS model.
Signed-off-by: Geunsik Lim <geunsik.lim@samsung.com>
CC: Jan Kotas <jkotas@microsoft.com>
CC: Jan Vorlicek <janvorli@microsoft.com>