Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
chakracore: Updated chakracore to release/2.0
Browse files Browse the repository at this point in the history
Updated chakracore to chakra-core/ChakraCore@f7e94b3

PR-URL: #185
Reviewed-By: Hitesh Kanwathirtha <[email protected]>
  • Loading branch information
kunalspathak committed Mar 10, 2017
1 parent bdf6c12 commit 9eb3d7c
Show file tree
Hide file tree
Showing 37 changed files with 442 additions and 214 deletions.
16 changes: 11 additions & 5 deletions deps/chakrashim/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ project (CHAKRACORE)
# Keep CMake from caching static/shared library
# option. Otherwise, CMake fails to update cached
# references

# todo: create a sub cmake file to take care of _SH uncaching...
if(SHARED_LIBRARY_SH)
unset(SHARED_LIBRARY_SH CACHE)
unset(STATIC_LIBRARY_SH CACHE)
Expand All @@ -18,6 +20,11 @@ if(STATIC_LIBRARY_SH)
set(STATIC_LIBRARY 1)
endif()

if(LIBS_ONLY_BUILD_SH)
unset(LIBS_ONLY_BUILD_SH CACHE)
set(CC_LIBS_ONLY_BUILD 1)
endif()

if(CC_USES_SYSTEM_ARCH_SH)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(CC_TARGETS_AMD64_SH 1)
Expand Down Expand Up @@ -305,15 +312,14 @@ endif(CLR_CMAKE_PLATFORM_XPLAT)

if (ENABLE_FULL_LTO_SH OR ENABLE_THIN_LTO_SH)
if (CC_TARGET_OS_LINUX)
set(CC_LTO_ENABLED
-fuse-ld=gold
-Xlinker -plugin=${CHAKRACORE_BINARY_DIR}/../../cc-toolchain/build/lib/LLVMgold.so
)
set(CC_LTO_ENABLED -use-gold-plugin)
set(CC_LTO_ENABLED_C -c)
endif()

if (ENABLE_FULL_LTO_SH)
unset(DENABLE_FULL_LTO_SH CACHE)
add_compile_options(-flto)
add_compile_options(-flto ${CC_LTO_ENABLED_C})

if (CC_LTO_ENABLED)
set(CC_LTO_ENABLED "${CC_LTO_ENABLED} -flto")
endif()
Expand Down
10 changes: 6 additions & 4 deletions deps/chakrashim/core/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
if(NOT CC_TARGET_OS_ANDROID)
add_subdirectory (GCStress)
endif()
if(NOT CC_LIBS_ONLY_BUILD)
if(NOT CC_TARGET_OS_ANDROID)
add_subdirectory (GCStress)
endif()

add_subdirectory (ch)
add_subdirectory (ch)
endif()

if (NOT STATIC_LIBRARY)
add_subdirectory (ChakraCore)
Expand Down
11 changes: 6 additions & 5 deletions deps/chakrashim/core/bin/ChakraCore/TestHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ void __stdcall NotifyUnhandledException(PEXCEPTION_POINTERS exceptionInfo)
#undef FLAG_NumberPairSet
#undef FLAG_NumberRange

HRESULT OnChakraCoreLoaded()
HRESULT OnChakraCoreLoaded(OnChakraCoreLoadedPtr pfChakraCoreLoaded)
{
typedef HRESULT(__stdcall *OnChakraCoreLoadedPtr)(TestHooks &testHooks);
OnChakraCoreLoadedPtr pfChakraCoreLoaded = (OnChakraCoreLoadedPtr)GetProcAddress(GetModuleHandle(NULL), "OnChakraCoreLoadedEntry");
if (pfChakraCoreLoaded == nullptr)
{
return S_OK;
pfChakraCoreLoaded = (OnChakraCoreLoadedPtr)GetProcAddress(GetModuleHandle(NULL), "OnChakraCoreLoadedEntry");
if (pfChakraCoreLoaded == nullptr)
{
return S_OK;
}
}

TestHooks testHooks =
Expand Down Expand Up @@ -167,7 +169,6 @@ HRESULT OnChakraCoreLoaded()
#endif
NotifyUnhandledException
};

return pfChakraCoreLoaded(testHooks);
}

Expand Down
4 changes: 3 additions & 1 deletion deps/chakrashim/core/bin/ChakraCore/TestHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#ifdef ENABLE_TEST_HOOKS

HRESULT OnChakraCoreLoaded();
interface ICustomConfigFlags;

#if defined(_WIN32) || defined(_MSC_VER)
Expand Down Expand Up @@ -66,4 +65,7 @@ struct TestHooks
NotifyUnhandledExceptionPtr pfnNotifyUnhandledException;
};

typedef HRESULT(__stdcall *OnChakraCoreLoadedPtr)(TestHooks &testHooks);
HRESULT OnChakraCoreLoaded(OnChakraCoreLoadedPtr pfChakraCoreLoaded = NULL);

#endif
2 changes: 1 addition & 1 deletion deps/chakrashim/core/bin/ch/ch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ int _cdecl wmain(int argc, __in_ecount(argc) LPWSTR argv[])

#if defined(CHAKRA_STATIC_LIBRARY) && !defined(NDEBUG)
// handle command line flags
OnChakraCoreLoaded();
OnChakraCoreLoaded(OnChakraCoreLoadedEntry);
#endif

if (argInfo.filename == nullptr)
Expand Down
1 change: 1 addition & 0 deletions deps/chakrashim/core/bin/ch/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,4 @@ inline JsErrorCode CreatePropertyIdFromString(const char* str, JsPropertyIdRef *

void GetBinaryLocation(char *path, const unsigned size);
void GetBinaryPathWithFileNameA(char *path, const size_t buffer_size, const char* filename);
extern "C" HRESULT __stdcall OnChakraCoreLoadedEntry(TestHooks& testHooks);
12 changes: 10 additions & 2 deletions deps/chakrashim/core/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ PRINT_USAGE() {
echo " -n, --ninja Build with ninja instead of make."
echo " --no-icu Compile without unicode/icu support."
echo " --no-jit Disable JIT"
echo " --libs-only Do not build CH and GCStress"
echo " --lto Enables LLVM Full LTO"
echo " --lto-thin Enables LLVM Thin LTO - xcode 8+ or clang 3.9+"
echo " --static Build as static library. Default: shared library"
Expand Down Expand Up @@ -93,6 +94,9 @@ WB_CHECK=
WB_ANALYZE=
WB_ARGS=
TARGET_PATH=0
# -DCMAKE_EXPORT_COMPILE_COMMANDS=ON useful for clang-query tool
CMAKE_EXPORT_COMPILE_COMMANDS="-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
LIBS_ONLY_BUILD=

if [ -f "/proc/version" ]; then
OS_LINUX=1
Expand Down Expand Up @@ -207,6 +211,10 @@ while [[ $# -gt 0 ]]; do
ICU_PATH="-DICU_INCLUDE_PATH_SH=${ICU_PATH:6}"
;;

--libs-only)
LIBS_ONLY_BUILD="-DLIBS_ONLY_BUILD_SH=1"
;;

--lto)
LTO="-DENABLE_FULL_LTO_SH=1"
HAS_LTO=1
Expand All @@ -232,6 +240,7 @@ while [[ $# -gt 0 ]]; do

--xcode)
CMAKE_GEN="-G Xcode -DCC_XCODE_PROJECT=1"
CMAKE_EXPORT_COMPILE_COMMANDS=""
MAKE=0
;;

Expand Down Expand Up @@ -484,9 +493,8 @@ fi
echo Generating $BUILD_TYPE makefiles
cmake $CMAKE_GEN $CC_PREFIX $ICU_PATH $LTO $STATIC_LIBRARY $ARCH $TARGET_OS \
$ENABLE_CC_XPLAT_TRACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT \
$WITHOUT_FEATURES $WB_FLAG $WB_ARGS -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
$WITHOUT_FEATURES $WB_FLAG $WB_ARGS $CMAKE_EXPORT_COMPILE_COMMANDS $LIBS_ONLY_BUILD\
../..
# -DCMAKE_EXPORT_COMPILE_COMMANDS=ON useful for clang-query tool

_RET=$?
if [[ $? == 0 ]]; then
Expand Down
21 changes: 10 additions & 11 deletions deps/chakrashim/core/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,22 @@ else()
endif()

target_link_libraries(ChakraCoreStatic
${CC_LTO_ENABLED}
${PTHREAD}
"dl"
)
endif()

target_include_directories (
ChakraCoreStatic PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CHAKRACORE_SOURCE_DIR}/lib/Backend
${CHAKRACORE_SOURCE_DIR}/lib/Common
${CHAKRACORE_SOURCE_DIR}/lib/Runtime
${CHAKRACORE_SOURCE_DIR}/lib/Runtime/ByteCode
${CHAKRACORE_SOURCE_DIR}/lib/Parser
${CHAKRACORE_SOURCE_DIR}/lib/Jsrt
${wasm_includes}
)
ChakraCoreStatic PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CHAKRACORE_SOURCE_DIR}/lib/Backend
${CHAKRACORE_SOURCE_DIR}/lib/Common
${CHAKRACORE_SOURCE_DIR}/lib/Runtime
${CHAKRACORE_SOURCE_DIR}/lib/Runtime/ByteCode
${CHAKRACORE_SOURCE_DIR}/lib/Parser
${CHAKRACORE_SOURCE_DIR}/lib/Jsrt
${wasm_includes}
)

if(BuildJIT)
add_subdirectory (Backend)
Expand Down
1 change: 0 additions & 1 deletion deps/chakrashim/core/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,5 @@ if (NOT STATIC_LIBRARY)
target_link_libraries(Chakra.Pal.Singular
${PTHREAD}
dl
${CC_LTO_ENABLED}
)
endif()
42 changes: 25 additions & 17 deletions deps/chakrashim/core/pal/src/misc/random.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

#include <stdlib.h>
Expand All @@ -26,7 +26,7 @@ class Lock{
static bool Init()
{
return pthread_mutex_init(&random_generator_mutex, NULL) == 0;
}
}

__attribute__((noinline))
Lock() {
Expand All @@ -41,7 +41,10 @@ class Lock{

pthread_mutex_t Lock::random_generator_mutex;

static bool GetRandom(unsigned int *result) noexcept
// not needed to be a THREAD_LOCAL. GetRandom acquires a mutex lock
unsigned int WEAK_RANDOM_SEED = 12345;

static void GetRandom(unsigned int *result) noexcept
{
static bool mutex_initialized = Lock::Init();
// Do not put the `if check` into `Init` or replace it with Assert
Expand All @@ -53,40 +56,45 @@ static bool GetRandom(unsigned int *result) noexcept

if (cache_index < RANDOM_CACHE_SIZE) {
*result = random_cache.result[cache_index++];
return true;
return;
}

const int rdev = open("/dev/urandom", O_RDONLY);
unsigned len = 0;
bool failed = false;

do
{
int added = read(rdev, random_cache.rstack + len, rand_byte_len - len);
if (added < 0) {
close(rdev);
return false;
// io starvation ?
failed = true;
goto LEAVE;
}
len += added;
} while (len < rand_byte_len);

close(rdev);
*result = random_cache.result[0];
cache_index = 1;
return len == rand_byte_len;
failed = len != rand_byte_len;
LEAVE:
if (failed) // fallback to weak rnd
{
WEAK_RANDOM_SEED += rand();
*result = rand_r(&WEAK_RANDOM_SEED);
}
else
{
cache_index = 1; // enable cache only when len == rand_byte_len
}
}

extern "C"
errno_t __cdecl rand_s(unsigned int* randomValue) noexcept
{
if (randomValue == nullptr) return 1;

if (GetRandom(randomValue))
{
return 0;
}
else
{
*randomValue = 0;
return 1;
}

GetRandom(randomValue);
return 0;
}
Loading

0 comments on commit 9eb3d7c

Please sign in to comment.