Skip to content

Commit 14c22ff

Browse files
committed
[MERGE #2296 @obastemur] Fix PAL double initialize
Merge pull request #2296 from obastemur:pal_fix_double_init
2 parents 34a9c0b + ef987bb commit 14c22ff

33 files changed

+1026
-787
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,4 @@ deps/
9595

9696
.DS_Store
9797
android-toolchain-arm/
98+
cc-toolchain/

Build/android_toolchain.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ $1/build/tools/make-standalone-toolchain.sh \
2121
--install-dir=$TOOLCHAIN \
2222
--platform=$ANDROID_TARGET --force
2323

24+
# use system python
2425
rm $TOOLCHAIN/bin/python
26+
27+
# keep cmake from using system ranlib
28+
cp android-toolchain-arm/bin/arm-linux-androideabi-ranlib android-toolchain-arm/bin/ranlib

Build/compile_clang.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
#-------------------------------------------------------------------------------------------------------
3+
# Copyright (C) Microsoft. All rights reserved.
4+
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
5+
#-------------------------------------------------------------------------------------------------------
6+
7+
LLVM_VERSION="3.9.1"
8+
9+
CC_URL="git://sourceware.org/git/binutils-gdb.git\nhttp://llvm.org/releases/${LLVM_VERSION}/\n"
10+
echo -e "\n----------------------------------------------------------------"
11+
echo -e "\nThis script will download LLVM/CLANG and LLVM Gold Bintools from\n${CC_URL}\n"
12+
echo "These software are licensed to you by its publisher(s), not Microsoft."
13+
echo "Microsoft is not responsible for the software."
14+
echo "Your installation and use of the software is subject to the publisher’s terms available here:"
15+
echo -e "http://llvm.org/docs/DeveloperPolicy.html#license\nhttp://llvm.org/docs/GoldPlugin.html#licensing\n"
16+
echo -e "----------------------------------------------------------------\n"
17+
echo "If you don't agree, press Ctrl+C to terminate"
18+
read -t 10 -p "Hit ENTER to continue (or wait 10 seconds)"
19+
20+
echo -e "\nThis will take some time... [and free memory 2GB+]\n"
21+
22+
ROOT=${PWD}/cc-toolchain/
23+
GOLD_PLUGIN=""
24+
25+
if [ ! -d ./cc-toolchain/src/llvm/projects/compiler-rt ]; then
26+
rm -rf cc-toolchain
27+
mkdir cc-toolchain
28+
cd cc-toolchain
29+
mkdir src
30+
mkdir bin
31+
cd src
32+
33+
apt-get -v >/dev/null 2>&1
34+
if [ $? == 0 ]; then # debian
35+
sudo apt-get install -y apt-file texinfo texi2html csh gawk automake libtool libtool-bin bison flex libncurses5-dev
36+
if [ $? != 0 ]; then
37+
exit 1
38+
fi
39+
else
40+
yum -v >/dev/null 2>&1
41+
if [ $? == 0 ]; then # redhat
42+
yum install -y texinfo texi2html csh gawk automake libtool libtool-bin bison flex ncurses-devel
43+
else
44+
echo "This script requires (texinfo texi2html csh gawk automake libtool libtool-bin bison flex ncurses-devel)"
45+
echo "Automated installation of these requirements is supported with apt-get and yum only."
46+
echo ""
47+
echo "If you don't have these packages are installed, press Ctrl+C to terminate"
48+
read -t 10 -p "Hit ENTER to continue (or wait 10 seconds)"
49+
fi
50+
fi
51+
52+
mkdir lto_utils
53+
cd lto_utils
54+
echo "Downloading LLVM Gold Plugin"
55+
git clone --depth 1 git://sourceware.org/git/binutils-gdb.git binutils >/dev/null 2>&1
56+
mkdir binutils_compile; cd binutils_compile
57+
../binutils/configure --enable-gold --enable-plugins --disable-werror --prefix="${ROOT}/build"
58+
make -j2
59+
make install
60+
if [ $? != 0 ]; then
61+
exit 1
62+
fi
63+
64+
echo -e "\n\n\n\n"
65+
cd "${ROOT}/src/"
66+
67+
echo "Downloading LLVM ${LLVM_VERSION}"
68+
wget –quiet "http://llvm.org/releases/${LLVM_VERSION}/llvm-${LLVM_VERSION}.src.tar.xz" >/dev/null 2>&1
69+
tar -xf "llvm-${LLVM_VERSION}.src.tar.xz"
70+
if [ $? == 0 ]; then
71+
rm "llvm-${LLVM_VERSION}.src.tar.xz"
72+
mv "llvm-${LLVM_VERSION}.src" llvm
73+
else
74+
exit 1
75+
fi
76+
77+
cd llvm/tools/
78+
echo "Downloading Clang ${LLVM_VERSION}"
79+
wget –quiet "http://llvm.org/releases/${LLVM_VERSION}/cfe-${LLVM_VERSION}.src.tar.xz" >/dev/null 2>&1
80+
tar -xf "cfe-${LLVM_VERSION}.src.tar.xz"
81+
if [ $? == 0 ]; then
82+
mv "cfe-${LLVM_VERSION}.src" clang
83+
rm "cfe-${LLVM_VERSION}.src.tar.xz"
84+
else
85+
exit 1
86+
fi
87+
88+
mkdir -p ../projects/
89+
cd ../projects/
90+
echo "Downloading Compiler-RT ${LLVM_VERSION}"
91+
wget –quiet "http://llvm.org/releases/${LLVM_VERSION}/compiler-rt-${LLVM_VERSION}.src.tar.xz" >/dev/null 2>&1
92+
tar -xf "compiler-rt-${LLVM_VERSION}.src.tar.xz"
93+
if [ $? == 0 ]; then
94+
mv "compiler-rt-${LLVM_VERSION}.src" compiler-rt
95+
rm "compiler-rt-${LLVM_VERSION}.src.tar.xz"
96+
else
97+
exit 1
98+
fi
99+
fi
100+
101+
GOLD_PLUGIN=-DLLVM_BINUTILS_INCDIR="${ROOT}/src/lto_utils/binutils/include"
102+
103+
mkdir -p "${ROOT}/build"
104+
cd "${ROOT}/src/llvm"
105+
mkdir -p build_
106+
cd build_
107+
108+
cmake ../ -DCMAKE_INSTALL_PREFIX="${ROOT}/build" -DCMAKE_BUILD_TYPE=Release ${GOLD_PLUGIN}
109+
110+
if [ $? != 0 ]; then
111+
cd ..
112+
rm -rf build_
113+
mkdir build_
114+
exit 1
115+
fi
116+
117+
make -j4 install
118+
119+
if [ $? == 0 ]; then
120+
echo -e "Done!\n./build.sh args are given below;\n\n"
121+
echo "--cxx=${ROOT}/build/bin/clang++ --cc=${ROOT}/build/bin/clang"
122+
fi

CMakeLists.txt

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ if(STATIC_LIBRARY_SH)
1818
set(STATIC_LIBRARY 1)
1919
endif()
2020

21-
if(CC_TARGETS_AMD64_SH)
22-
set(CC_TARGETS_AMD64 1)
23-
endif()
24-
25-
if(CC_TARGETS_X86_SH)
26-
set(CC_TARGETS_X86 1)
27-
set(CMAKE_SYSTEM_PROCESSOR "i386")
28-
endif()
29-
30-
if(CC_TARGETS_ARM_SH)
21+
if (CC_TARGETS_ARM_SH OR CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
3122
set(CC_TARGETS_ARM 1)
3223
add_definitions(-D_ARM_=1)
3324
set(CMAKE_SYSTEM_PROCESSOR "armv7l")
25+
else()
26+
if(CC_TARGETS_AMD64_SH)
27+
set(CC_TARGETS_AMD64 1)
28+
endif()
29+
30+
if(CC_TARGETS_X86_SH)
31+
set(CC_TARGETS_X86 1)
32+
set(CMAKE_SYSTEM_PROCESSOR "i386")
33+
endif()
3434
endif()
3535

3636
unset(CC_TARGETS_ARM_SH CACHE)
@@ -62,6 +62,23 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
6262
set(CC_TARGET_OS_OSX 1)
6363
endif()
6464

65+
if (ENABLE_CC_XPLAT_TRACE_SH)
66+
unset(ENABLE_CC_XPLAT_TRACE_SH CACHE)
67+
set(ENABLE_CC_XPLAT_TRACE 1)
68+
if (CC_TARGET_OS_ANDROID)
69+
add_definitions(-DTRACE_OUTPUT_TO_LOGCAT=1)
70+
else()
71+
add_definitions(-DTRACE_OUTPUT_TARGET_FILE=1)
72+
endif()
73+
add_definitions(-DENABLE_CC_XPLAT_TRACE=1)
74+
add_compile_options(-finstrument-functions)
75+
add_compile_options(-g)
76+
add_compile_options(-ggdb)
77+
if(NOT STATIC_LIBRARY)
78+
message(FATAL_ERROR "Trace option is available only for --static builds")
79+
endif()
80+
endif()
81+
6582
if(CC_EMBED_ICU_SH)
6683
unset(CC_EMBED_ICU_SH CACHE)
6784
set(CC_EMBED_ICU 1)
@@ -289,12 +306,27 @@ if(CLR_CMAKE_PLATFORM_XPLAT)
289306
endif()
290307
endif(CLR_CMAKE_PLATFORM_XPLAT)
291308

292-
if(ENABLE_FULL_LTO_SH)
293-
unset(DENABLE_FULL_LTO_SH CACHE)
294-
add_compile_options(-flto)
295-
elseif(ENABLE_THIN_LTO_SH)
296-
unset(ENABLE_THIN_LTO_SH CACHE)
297-
add_compile_options(-flto=thin)
309+
if (ENABLE_FULL_LTO_SH OR ENABLE_THIN_LTO_SH)
310+
if (CC_TARGET_OS_LINUX)
311+
set(CC_LTO_ENABLED
312+
-fuse-ld=gold
313+
-Xlinker -plugin=${CHAKRACORE_BINARY_DIR}/../../cc-toolchain/build/lib/LLVMgold.so
314+
)
315+
endif()
316+
317+
if (ENABLE_FULL_LTO_SH)
318+
unset(DENABLE_FULL_LTO_SH CACHE)
319+
add_compile_options(-flto)
320+
if (CC_LTO_ENABLED)
321+
set(CC_LTO_ENABLED "${CC_LTO_ENABLED} -flto")
322+
endif()
323+
elseif (ENABLE_THIN_LTO_SH)
324+
unset(ENABLE_THIN_LTO_SH CACHE)
325+
add_compile_options(-flto=thin)
326+
if (CC_LTO_ENABLED)
327+
set(CC_LTO_ENABLED "${CC_LTO_ENABLED} -flto=thin")
328+
endif()
329+
endif()
298330
endif()
299331

300332
if(CMAKE_BUILD_TYPE STREQUAL Debug)
@@ -312,6 +344,8 @@ endif(CMAKE_BUILD_TYPE STREQUAL Debug)
312344

313345
if(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
314346
add_compile_options(-O3)
347+
else()
348+
add_compile_options(-O0)
315349
endif(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
316350

317351
if(IS_64BIT_BUILD)

bin/ChakraCore/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ set(lib_target "${lib_target}"
5353
if(CC_TARGET_OS_ANDROID OR CC_TARGET_OS_LINUX)
5454
set(lib_target "${lib_target}"
5555
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libChakraCoreLib.version
56+
# reduce link time memory usage
57+
-Xlinker --no-keep-memory
5658
)
5759
elseif(CC_TARGET_OS_OSX)
5860
if(CC_TARGETS_X86)
@@ -62,7 +64,10 @@ elseif(CC_TARGET_OS_OSX)
6264
endif()
6365
endif()
6466

65-
target_link_libraries (ChakraCore ${lib_target})
67+
target_link_libraries (ChakraCore
68+
${lib_target}
69+
${CC_LTO_ENABLED}
70+
)
6671

6772
if(NOT CC_XCODE_PROJECT)
6873
set(CC_LIB_EXT "so")

bin/GCStress/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ set(lib_target "${lib_target}"
3232
Chakra.Pal
3333
Chakra.Jsrt
3434
${LINKER_END_GROUP}
35+
${CC_LTO_ENABLED}
3536
)
3637

3738
target_link_libraries (GCStress ${lib_target})

bin/ch/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ endif()
8787
if(CC_TARGET_OS_ANDROID OR CC_TARGET_OS_LINUX)
8888
set(lib_target "${lib_target}"
8989
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/ch.version
90+
# reduce link time memory usage
91+
-Xlinker --no-keep-memory
9092
)
9193
elseif(CC_TARGET_OS_OSX)
9294
if(CC_TARGETS_X86)
@@ -97,7 +99,10 @@ elseif(CC_TARGET_OS_OSX)
9799
endif()
98100

99101

100-
target_link_libraries (ch ${lib_target})
102+
target_link_libraries (ch
103+
${lib_target}
104+
${CC_LTO_ENABLED}
105+
)
101106

102107
if(NOT CC_XCODE_PROJECT)
103108
# Add a post build event to the ch target

bin/ch/ChakraRtInterface.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,8 @@ bool ChakraRTInterface::LoadChakraDll(ArgInfo* argInfo, HINSTANCE *outLibrary)
4949
#ifndef CHAKRA_STATIC_LIBRARY
5050
HINSTANCE library = nullptr;
5151

52-
char filename[_MAX_PATH];
53-
char drive[_MAX_DRIVE];
54-
char dir[_MAX_DIR];
55-
56-
char modulename[_MAX_PATH];
57-
GetModuleFileNameA(NULL, modulename, _MAX_PATH);
58-
_splitpath_s(modulename, drive, _MAX_DRIVE, dir, _MAX_DIR, nullptr, 0, nullptr, 0);
59-
_makepath_s(filename, drive, dir, chakraDllName, nullptr);
60-
LPCSTR dllName = filename;
52+
char dllName[_MAX_PATH];
53+
GetBinaryPathWithFileNameA(dllName, _MAX_PATH, chakraDllName);
6154

6255
library = LoadChakraCore(dllName);
6356
*outLibrary = library;

0 commit comments

Comments
 (0)