Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,17 @@ endif(WITHOUT_FEATURES_SH)

enable_language(ASM)

if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(DYN_LIB_EXT "dylib")
else()
set(DYN_LIB_EXT "so")
endif()

################# Write-barrier check/analyze ##################
if (WB_CHECK_SH OR WB_ANALYZE_SH)
add_definitions(
-Xclang -load
-Xclang ${CMAKE_CURRENT_SOURCE_DIR}/tools/RecyclerChecker/Build/libclangRecyclerChecker.so
-Xclang ${CMAKE_CURRENT_SOURCE_DIR}/tools/RecyclerChecker/Build/libclangRecyclerChecker.${DYN_LIB_EXT}
)
endif()
if (WB_CHECK_SH)
Expand All @@ -331,6 +337,15 @@ if (WB_ANALYZE_SH)
-Xclang -analyzer-checker=chakra.RecyclerChecker
)
endif()
if (WB_ARGS_SH)
foreach(wb_arg IN LISTS WB_ARGS_SH)
add_definitions(
-Xclang -plugin-arg-check-recycler
-Xclang ${wb_arg}
)
endforeach(wb_arg)
unset(WB_ARGS_SH CACHE) # don't cache
endif()

include_directories(
.
Expand Down
7 changes: 1 addition & 6 deletions bin/ChakraCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,11 @@ endif()
target_link_libraries (ChakraCore ${lib_target})

if(NOT CC_XCODE_PROJECT)
set(CC_LIB_EXT "so")
# Post build step to copy the built shared library
# to BuildLinux (or whatever the CMakeBuildDir is)
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(CC_LIB_EXT "dylib")
endif()

add_custom_command(TARGET ChakraCore POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CHAKRACORE_BINARY_DIR}/bin/ChakraCore/libChakraCore.${CC_LIB_EXT}"
"${CHAKRACORE_BINARY_DIR}/bin/ChakraCore/libChakraCore.${DYN_LIB_EXT}"
${CHAKRACORE_BINARY_DIR}/
)
endif()
17 changes: 15 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ PRINT_USAGE() {
echo " Write-barrier check given CPPFILE (git path)"
echo " --wb-analyze CPPFILE"
echo " Write-barrier analyze given CPPFILE (git path)"
echo " --wb-args=PLUGIN_ARGS"
echo " Write-barrier clang plugin args"
echo ""
echo "example:"
echo " ./build.sh --cxx=/path/to/clang++ --cc=/path/to/clang -j"
Expand Down Expand Up @@ -81,6 +83,7 @@ OS_APT_GET=0
OS_UNIX=0
WB_CHECK=
WB_ANALYZE=
WB_ARGS=

if [ -f "/proc/version" ]; then
OS_LINUX=1
Expand Down Expand Up @@ -258,6 +261,12 @@ while [[ $# -gt 0 ]]; do
fi
;;

--wb-args=*)
WB_ARGS=$1
WB_ARGS=${WB_ARGS:10}
WB_ARGS=${WB_ARGS// /;} # replace space with ; to generate a cmake list
;;

*)
echo "Unknown option $1"
PRINT_USAGE
Expand Down Expand Up @@ -349,6 +358,10 @@ if [[ $WB_CHECK || $WB_ANALYZE ]]; then
WB_FILE=$WB_ANALYZE
fi

if [[ $WB_ARGS ]]; then
WB_ARGS="-DWB_ARGS_SH=$WB_ARGS"
fi

if [[ -f $CHAKRACORE_DIR/$WB_FILE ]]; then
touch $CHAKRACORE_DIR/$WB_FILE
else
Expand All @@ -360,7 +373,7 @@ if [[ $WB_CHECK || $WB_ANALYZE ]]; then

WB_FILE_CMAKELISTS="$CHAKRACORE_DIR/$WB_FILE_DIR/CMakeLists.txt"
if [[ -f $WB_FILE_CMAKELISTS ]]; then
SUBDIR=$(grep -i add_library $WB_FILE_CMAKELISTS | sed -r "s/.*\((\S+) .*/\1/")
SUBDIR=$(grep -i add_library $WB_FILE_CMAKELISTS | sed "s/.*(\(.*\) .*/\1/")
else
echo "$WB_FILE_CMAKELISTS not found." && exit 1
fi
Expand All @@ -384,7 +397,7 @@ fi
echo Generating $BUILD_TYPE makefiles
cmake $CMAKE_GEN $CC_PREFIX $ICU_PATH $STATIC_LIBRARY $ARCH \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT $WITHOUT_FEATURES \
$WB_FLAG \
$WB_FLAG $WB_ARGS \
../..

_RET=$?
Expand Down
29 changes: 23 additions & 6 deletions tools/RecyclerChecker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,33 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
project(clangRecyclerChecker CXX)

Find_Package(LLVM REQUIRED)
link_directories( ${LLVM_LIB_DIR} )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_COMPILE_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LLVM_LDFLAGS}")

Find_Package(Clang REQUIRED)
include_directories( ${CLANG_INCLUDE_DIRS} )

add_definitions("-fno-rtti -std=c++11")
add_definitions("-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS ")
add_definitions("-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS")

# target_link_libraries(clangRecyclerChecker ${CLANG_LIBS} ${LLVM_LIBS_CORE} )
add_library(clangRecyclerChecker SHARED RecyclerChecker.cpp RecyclerAnalyzer.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Wno-strict-aliasing \
"
)

# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --unresolved-symbols=report-all")
target_link_libraries(clangRecyclerChecker ${CLANG_LIBS})
add_library(clangRecyclerChecker SHARED
Helpers.cpp
RecyclerChecker.cpp
RecyclerAnalyzer.cpp
)

# OSX requires following libs.
# Ubuntu complains/fails if these libs specified.
#
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
target_link_libraries(clangRecyclerChecker
${CLANG_LIBS}
${LLVM_LIBS_CORE}
${LLVM_LIBS_SYS}
)
endif()
8 changes: 8 additions & 0 deletions tools/RecyclerChecker/Helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "Helpers.h"

// Default log level: Error
Log::LogLevel Log::s_logLevel = Log::LogLevel::Error;
49 changes: 49 additions & 0 deletions tools/RecyclerChecker/Helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once

#include "llvm/Support/raw_ostream.h"
using std::string;
using llvm::raw_ostream;

class Log
{
public:
enum class LogLevel { Error, Info, Verbose };

private:
static LogLevel s_logLevel;

public:
static void SetLevel(LogLevel level) { s_logLevel = level; }

static raw_ostream& errs()
{
return llvm::outs(); // use same outs stream for better output order
}

static raw_ostream& outs()
{
return s_logLevel >= LogLevel::Info ? llvm::outs() : llvm::nulls();
}

static raw_ostream& verbose()
{
return s_logLevel >= LogLevel::Verbose ? llvm::outs() : llvm::nulls();
}
};

template <size_t N>
bool StartsWith(const string& s, const char (&prefix)[N])
{
return s.length() >= N - 1
&& s.compare(0, string::npos, prefix, N - 1) == 0;
}

template <class Set, class Item>
bool Contains(const Set& s, const Item& item)
{
return s.find(item) != s.end();
}
22 changes: 1 addition & 21 deletions tools/RecyclerChecker/RecyclerAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,6 @@ class RecyclerChecker
void checkPostStmt(const CXXNewExpr *newExpr, CheckerContext& ctx) const;
};

/*
llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const PHPNativeType &type) {
os << type.getName() << " ";
for (int i = 0; i < type.getPointerLevel(); ++i) {
os << "*";
}
return os;
}
*/

static raw_ostream &debug_stream() {
// #ifdef DEBUG_RECYCLER_CHECKER
return llvm::outs();
/*
#else
return llvm::nulls();
#endif
*/
}

static BugType* createRecyclerCheckerError(StringRef name) {
return new BugType(
new CheckerBase(),
Expand Down Expand Up @@ -150,7 +130,7 @@ void RecyclerChecker::checkPostStmt(const CXXNewExpr* newExpr, CheckerContext& c
}

static void initRecyclerChecker(CheckerManager &mgr) {
RecyclerChecker *checker = mgr.registerChecker<RecyclerChecker>();
mgr.registerChecker<RecyclerChecker>();
}


Expand Down
Loading