2014年8月31日 星期日

build JSC with FTL on Linux

goal: the FTL only supported on Darwin, but we want it workable on linux for study FTL implementation


Platform: X86_64
LLVM version: c84ba8
WebKit version: 5d442a


LLVM:

LLVM should has stackmap implementation in ELF, grep .llvm_stackmaps in
$llvm/lib/MC/MCObjectFileInfo.cpp

patch for walkaround eh_frame relocation error
jsc: $llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp:308: void llvm::RuntimeDyldELF::resolveX86_64Relocation(const llvm::SectionEntry&, uint64_t, uint64_t, uint32_t, int64_t, uint64_t): Assertion `RealOffset <= (2147483647) && RealOffset >= (-2147483647-1)' failed.
Aborted

index a592c09..9231cbe 100644
--- a/lib/MC/MCDwarf.cpp
+++ b/lib/MC/MCDwarf.cpp
@@ -999,7 +999,7 @@ static void emitFDESymbol(MCObjectStreamer &streamer, const MCSym
   if (asmInfo->doDwarfFDESymbolsUseAbsDiff() && isEH)
     emitAbsValue(streamer, v, size);
   else
-    streamer.EmitValue(v, size);
+    streamer.EmitValue(v, isEH ? 8 : size);

 }

patch for webkit


1. 
--- a/Source/JavaScriptCore/CMakeLists.txt
+++ b/Source/JavaScriptCore/CMakeLists.txt
@@ -740,7 +740,7 @@ if (ENABLE_FTL_JIT)

     WEBKIT_WRAP_SOURCELIST(${llvmForJSC_SOURCES})
     add_library(llvmForJSC SHARED ${llvmForJSC_SOURCES} ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/WebKitLLVMLibraryToken.h)
-    target_link_libraries(llvmForJSC ${LLVM_STATIC_LIBRARIES} "pthread" "dl")

+    target_link_libraries(llvmForJSC ${LLVM_STATIC_LIBRARIES} "pthread" "dl" "z" "curses")

2.
--- a/Source/JavaScriptCore/ftl/FTLCompile.cpp
+++ b/Source/JavaScriptCore/ftl/FTLCompile.cpp
@@ -621,12 +624,21 @@ void compile(State& state, Safepoint::Result& safepointResult)
         if (isARM64())
             llvm->SetTarget(state.module, "arm64-apple-ios");
-
+
+#if OS(LINUX) && CPU(X86_64)
+        llvm->SetTarget(state.module, "x86_64-unknown-linux-gnu");
+#elif OS(LINUX) && CPU(X86)
+        llvm->SetTarget(state.module, "x86-unknown-linux-gnu");
+#endif


3.
--- a/Source/JavaScriptCore/disassembler/LLVMDisassembler.cpp
+++ b/Source/JavaScriptCore/disassembler/LLVMDisassembler.cpp
@@ -87,6 +87,8 @@ bool tryToDisassembleWithLLVM(
     triple = "x86_64-apple-darwin";
 #elif CPU(X86)
     triple = "x86-apple-darwin";
+#elif CPU(X86_64) && OS(LINUX)
+    triple = "x86_64-unknown-linux-gnu";
 #elif CPU(ARM64)
     triple = "arm64-apple-darwin";

4.
--- a/Source/JavaScriptCore/ftl/FTLCompile.cpp
+++ b/Source/JavaScriptCore/ftl/FTLCompile.cpp
@@ -87,7 +87,7 @@ static uint8_t* mmAllocateDataSection(

     RefPtr<DataSection> section = adoptRef(new DataSection(size, alignment));

-    if (!strcmp(sectionName, "__llvm_stackmaps"))
+    if (!strcmp(sectionName, ".llvm_stackmaps"))
         state.stackmapsSection = section;
     else {
         state.jitCode->addDataSection(section);

5.
--- a/Source/JavaScriptCore/ftl/FTLUnwindInfo.cpp
+++ b/Source/JavaScriptCore/ftl/FTLUnwindInfo.cpp
@@ -28,7 +28,7 @@

 #if ENABLE(FTL_JIT)

-#include <mach-o/compact_unwind_encoding.h>
+#include "compact_unwind_encoding.h"

6. 
download compact_unwind_encoding.h and put it to $webkit/Source/JavaScriptCore/ftl

build command


$export PATH=$PATH:$llvm/install/bin
$./Tools/Scripts/build-jsc --gtk  --debug --ftl-jit   --cmakeargs="-DENABLE_PLUGIN_PROCESS_GTK2=OFF -DLIBCXXABI_INCLUDE_DIRS=/usr/include/c++/4.8/ -DENABLE_VIDEO=OFF -DENABLE_VIDEO_TRACK=OFF -DENABLE_VIEW_MODE_CSS_MEDIA=OFF  -DENABLE_WEB_AUDIO=OFF" --makeargs="VERBOSE=1"


Running and Testing

export JSC_enableConcurrentJIT=false
./Tools/Scripts/run-jsc-stress-tests -root=$WebKit/ WebKitBuild/Debug/bin/

Results for JSC stress tests:
     12 failures found.

2014年8月17日 星期日

千萬不要自己寫build script去試open source

我做了非常愚蠢的事情
大型open source有buildscript的話
能的話要先從buildscript當做進入點
千萬不要想我傻傻的自己寫build script去試
腦殘

2014年8月7日 星期四

clang's atomic operation trick

clang will generate libCall or LLVM atomic IR with built-in atomic operaion.

1. when data size of atomic operation is less than getTarget().getMaxAtomicInlineWidth()
&& alignent, it will generate LLVM atomic IR, otherwise generate libCall

2. in ARM target, give fail triple name also generates libCall

3. MaxAtomicInlineWidth is defined in lib/Basic/Targets.cpp