可可西

2025年1月20日 #

在Win10上编译LLVM

代码仓库:https://github.com/llvm/llvm-project

 

LLVM_TARGETS_TO_BUILD

-DLLVM_TARGETS_TO_BUILD="X86;PowerPC". The full list, as of March 2023, is: AArch64;AMDGPU;ARM;AVR;BPF;Hexagon;Lanai;LoongArch;Mips;MSP430;NVPTX;PowerPC;RISCV;Sparc;SystemZ;VE;WebAssembly;X86;XCore

-DLLVM_TARGETS_TO_BUILD=host   // 将编译当前机器的架构的二进制 on an x86_64 machine will include the X86 target.

To enable all of them, use: -DLLVM_TARGETS_TO_BUILD=all

 

LLVM_ENABLE_PROJECTS

full list:bolt;clang;clang-tools-extra;compiler-rt;cross-project-tests;libc;libclc;lld;lldb;mlir;openmp;polly;pstl

To enable all of them, use: LLVM_ENABLE_RUNTIMES=all

 

LLVM_ENABLE_RUNTIMES

full list:libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;offload

To enable all of them, use: LLVM_ENABLE_RUNTIMES=all

 

CMAKE_BUILD_TYPE

This configures the optimization level for make or ninja builds.

Possible values:

Build Type

Optimizations

Debug Info

Assertions

Best suited for

Release

For Speed

No

No

Users of LLVM and Clang

Debug

None

Yes

Yes

Developers of LLVM

RelWithDebInfo

For Speed

Yes

No

Users that also need Debug

MinSizeRel

For Size

No

No

When disk space matters

更多详见:https://llvm.org/docs/CMake.html 

 

在windows上编译llvm

 

build.windows.clang.bat内容如下:

setlocal enableextensions
set "ROOT_DIR=%~dp0"
set "PROJECT_DIR=%ROOT_DIR%\llvm"
set "path=%~dp0tools\bin;C:\Python36-32;%path%"
set "CLANG_BUILD_DIR=%ROOT_DIR%\build\windows"
set "CLANG_INSTALL_DIR=%ROOT_DIR%\install\windows"
mkdir %CLANG_BUILD_DIR%
set "LLVM_ENABLE_PROJECTS=clang;lld"
set "LLVM_TARGETS_TO_BUILD=X86;WebAssembly"
set "CMAKE_BUILD_TYPE=RelWithDebInfo"
set "LIBFFI_DIR=%ROOT_DIR%\..\cppvm\source\cppvm-libffi\install\windows\x86_64"
set "CMAKE_PARAM=-DLLVM_ENABLE_PROJECTS="%LLVM_ENABLE_PROJECTS%" -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_DOCS=OFF -DLLVM_ENABLE_LLD=On -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=On -DLLVM_TARGETS_TO_BUILD="%LLVM_TARGETS_TO_BUILD%" -DLLVM_ENABLE_FFI=ON -DFFI_INCLUDE_DIR=%LIBFFI_DIR%\include -DLLVM_ENABLE_DUMP=On -DFFI_LIBRARY_DIR=%LIBFFI_DIR%\lib -DLLVM_OPTIMIZED_TABLEGEN=ON -DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% -DCMAKE_INSTALL_PREFIX=%CLANG_INSTALL_DIR% %PROJECT_DIR%"
cmake.exe -S %PROJECT_DIR% -B %CLANG_BUILD_DIR% -G "Visual Studio 16 2019"  -A x64 -Thost=x64 -DLLVM_COMPILER_JOBS=14 -DCMAKE_C_FLAGS="/bigobj" -DCMAKE_CXX_FLAGS="/bigobj" %CMAKE_PARAM% 
cmake --build %CLANG_BUILD_DIR% --config "%CMAKE_BUILD_TYPE%" --target INSTALL -- /m
pause

 

一些报错:

LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_prep_cif referenced in function "bool __cdecl ffiInvoke(void (__cdecl*)(void),class llvm::Function *,class llvm::ArrayRef
<struct llvm::GenericValue>,class llvm::DataLayout const &,struct llvm::GenericValue &)" (?ffiInvoke@@YA_NP6AXXZPEAVFunction@llvm@@V?$ArrayRef@UGenericValue@llvm@@@2@AEBVDataLayout@2@AEAUGenericValue@2@@Z) [G:\svn\llvm
-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_call referenced in function "bool __cdecl ffiInvoke(void (__cdecl*)(void),class llvm::Function *,class llvm::ArrayRef<str
uct llvm::GenericValue>,class llvm::DataLayout const &,struct llvm::GenericValue &)" (?ffiInvoke@@YA_NP6AXXZPEAVFunction@llvm@@V?$ArrayRef@UGenericValue@llvm@@@2@AEBVDataLayout@2@AEAUGenericValue@2@@Z) [G:\svn\llvm-pro
ject\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_void referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_typ 
e@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint8 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_ty 
pe@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint16 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint32 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint64 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_float referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_ty 
pe@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_double referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_pointer referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_ 
type@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
G:\svn\llvm-project\build\windows\RelWithDebInfo\bin\lli.exe : fatal error LNK1120: 10 unresolved externals [G:\svn\llvm-project\build\windows\tools\lli\lli.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_prep_cif referenced in function "bool __cdecl ffiInvoke(void (__cdecl*)(void),class llvm::Function *,class llvm::ArrayRef
<struct llvm::GenericValue>,class llvm::DataLayout const &,struct llvm::GenericValue &)" (?ffiInvoke@@YA_NP6AXXZPEAVFunction@llvm@@V?$ArrayRef@UGenericValue@llvm@@@2@AEBVDataLayout@2@AEAUGenericValue@2@@Z) [G:\svn\llvm 
-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_call referenced in function "bool __cdecl ffiInvoke(void (__cdecl*)(void),class llvm::Function *,class llvm::ArrayRef<str
uct llvm::GenericValue>,class llvm::DataLayout const &,struct llvm::GenericValue &)" (?ffiInvoke@@YA_NP6AXXZPEAVFunction@llvm@@V?$ArrayRef@UGenericValue@llvm@@@2@AEBVDataLayout@2@AEAUGenericValue@2@@Z) [G:\svn\llvm-pro
ject\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_void referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_typ 
e@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint8 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_ty 
pe@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint16 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint32 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_sint64 referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_float referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_ty 
pe@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_double referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_t 
ype@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
LLVMInterpreter.lib(ExternalFunctions.obj) : error LNK2019: unresolved external symbol __imp_ffi_type_pointer referenced in function "struct _ffi_type * __cdecl ffiTypeFor(class llvm::Type *)" (?ffiTypeFor@@YAPEAU_ffi_ 
type@@PEAVType@llvm@@@Z) [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]
G:\svn\llvm-project\build\windows\RelWithDebInfo\bin\LLVM-C.dll : fatal error LNK1120: 10 unresolved externals [G:\svn\llvm-project\build\windows\tools\llvm-shlib\LLVM-C.vcxproj]

 

原因是:使用了静态库版的ffi.lib,而在G:\svn\llvm-project\llvm\lib\ExecutionEngine\Interpreter\ExternalFunctions.cpp中引用ffi.h会将FFI_API定义为__declspec(dllimport),导致名字修饰都会带上__imp_前缀,从而找不到这些符号

/* Need minimal decorations for DLLs to work on Windows.  GCC has
   autoimport and autoexport.  Always mark externally visible symbols
   as dllimport for MSVC clients, even if it means an extra indirection
   when using the static version of the library.
   Besides, as a workaround, they can define FFI_BUILDING if they
   *know* they are going to link with the static library.  */
#if defined _MSC_VER
# if defined FFI_BUILDING_DLL /* Building libffi.DLL with msvcc.sh */
#  define FFI_API __declspec(dllexport)
# elif !defined FFI_BUILDING  /* Importing libffi.DLL */
#  define FFI_API __declspec(dllimport)
# else                        /* Building/linking static library */
#  define FFI_API
# endif
#else
# define FFI_API
#endif

 

解决办法:预定义FFI_BUILDING

add_definitions("-DFFI_BUILDING")

 

posted @ 2025-01-20 16:57 可可西 阅读(53) 评论(0) 推荐(0) 编辑

2025年1月6日 #

使用LEB128格式对整数进行编码

摘要: 大小端 比如说4个字节长度的一个十六进制的无符号整数:0x12 34 56 78,使用大端和小端两种表示方法的内存布局如下: LEB128编码说明 LEB128(Little-Endian Base 128)使用小端表示法,因为计算机处理小端表示法比较方便。 其每个字节只有7位为有效位,如果第一个字 阅读全文

posted @ 2025-01-06 23:31 可可西 阅读(22) 评论(0) 推荐(0) 编辑

2024年12月29日 #

使用Emscripten进行WebAssembly web开发

摘要: 测试源代码 math.c内容如下: #include <stdio.h> int add(int a, int b) { return a+b; } int mul(int a, int b) { return a*b; } void Test(int a, int b) { int r1 = ad 阅读全文

posted @ 2024-12-29 23:55 可可西 阅读(34) 评论(0) 推荐(0) 编辑

2024年12月26日 #

WebAssembly基础

摘要: 随着JavaScript语言的诞生,浏览器从单纯的内容展示工具升级为应用运行平台,开启了全新的Web时代。 然而,新的问题开始显露出来:JavaScript的运行速度太慢了。2008年,Google公司推出了Chrome浏览器,并在其内部搭载了全新设计的JavaScript引擎V8。 通过使用JIT 阅读全文

posted @ 2024-12-26 20:57 可可西 阅读(315) 评论(0) 推荐(0) 编辑

python3启动一个本地http服务器

摘要: 在windows中,使用python版本为Python 3.6.3 编写index.html网页 在当前目录F:\httpTest下,新建index.html,内容如下: <!DOCTYPE html> <head> <meta charset="utf-8"> <title>Http Test</ 阅读全文

posted @ 2024-12-26 19:37 可可西 阅读(99) 评论(0) 推荐(0) 编辑

2024年12月25日 #

生成LLVM IR及其CFG图

摘要: math.c代码 int add(int a, int b) { return a+b; } int mul(int a, int b) { return a*b; } void Test() { int r1 = add(1,2); int r2 = mul(3,4); } 编译生成IR中间代码m 阅读全文

posted @ 2024-12-25 22:58 可可西 阅读(55) 评论(0) 推荐(0) 编辑

2024年12月22日 #

vscode操作技巧

摘要: 代码着色 glsl、hlsl、fx、ush、usf着色器 安装Shader languages support for VS Code插件 对于ue4的ush、usf文件,需要配置其使用hlsl的着色规则 着色成功后的效果 打开文件时,缺省添加成Pin类型的Tab标签(非斜体) 改变当前文件时,左边 阅读全文

posted @ 2024-12-22 11:50 可可西 阅读(28) 评论(0) 推荐(0) 编辑

2024年12月4日 #

Win10下安装WSL(Windows Subsystem for Linux)

摘要: 启用WSL(Windows Subsystem for Linux) 管理员权限运行powershell并运行下面的命令 C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Enable-WindowsOptionalFeature - 阅读全文

posted @ 2024-12-04 23:12 可可西 阅读(464) 评论(0) 推荐(0) 编辑

2024年11月20日 #

渲染指令提交到GPU与等待执行完

摘要: CPU执行渲染指令,是不会立即发送给GPU硬件的。它们首先被送到驱动的指令缓冲区,当缓冲区满或执行某个函数,然后才被发送到GPU硬件上去执行。 注:PC上缓冲区满会被发送到GPU,而Mobile下即使缓冲区满也不会发送,除非pass结束或执行执行某个函数 发送到GPU后会立即返回,不会等待GPU执行 阅读全文

posted @ 2024-11-20 00:50 可可西 阅读(79) 评论(0) 推荐(0) 编辑

2024年10月22日 #

windows纤程(Fiber)机制

摘要: Windows 10(17763)系统上执行tjInitCompress函数时,加载dll失败,从而导致崩溃 KERNELBASE.dll pc 0x69 RaiseException (:0)[amd64:Windows NT:7BF8014B3D39BE6ADDC83DA4991008EB1] 阅读全文

posted @ 2024-10-22 00:28 可可西 阅读(103) 评论(0) 推荐(0) 编辑

导航

统计信息

点击右上角即可分享
微信分享提示