Linux/ARM: Use -O1 level to avoid segfault in release-build for Linux/ARM (#4904)
authorGeunsik Lim <leemgs@users.noreply.github.com>
Wed, 11 May 2016 08:44:36 +0000 (17:44 +0900)
committerJan Vorlicek <janvorli@microsoft.com>
Wed, 11 May 2016 08:44:36 +0000 (10:44 +0200)
commitee28eca285fc71acad093eb5e34101d2ab9e2018
tree47f889826403ee90a3debd46cc0311994dbd135b
parent5c3d1efea4a8673086df4ba36267d7f580ba9c8c
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>
src/pal/tools/clang-compiler-override.txt