LLVM系列第一章:编译LLVM源码

2023-11-09

系列文章目录

LLVM系列第一章:编译LLVM源码
LLVM系列第二章:模块Module
LLVM系列第三章:函数Function
LLVM系列第四章:逻辑代码块Block
LLVM系列第五章:全局变量Global Variable
LLVM系列第六章:函数返回值Return
LLVM系列第七章:函数参数Function Arguments
LLVM系列第八章:算术运算语句Arithmetic Statement
LLVM系列第九章:控制流语句if-else
LLVM系列第十章:控制流语句if-else-phi
LLVM系列第十一章:写一个Hello World
LLVM系列第十二章:写一个简单的词法分析器Lexer
LLVM系列第十三章:写一个简单的语法分析器Parser
LLVM系列第十四章:写一个简单的语义分析器Semantic Analyzer
LLVM系列第十五章:写一个简单的中间代码生成器IR Generator
LLVM系列第十六章:写一个简单的编译器
LLVM系列第十七章:for循环
LLVM系列第十八章:写一个简单的IR处理流程Pass
LLVM系列第十九章:写一个简单的Module Pass
LLVM系列第二十章:写一个简单的Function Pass
LLVM系列第二十一章:写一个简单的Loop Pass
LLVM系列第二十二章:写一个简单的编译时函数调用统计器(Pass)
LLVM系列第二十三章:写一个简单的运行时函数调用统计器(Pass)
LLVM系列第二十四章:用Xcode编译调试LLVM源码
LLVM系列第二十五章:简单统计一下LLVM源码行数
LLVM系列第二十六章:理解LLVMContext
LLVM系列第二十七章:理解IRBuilder
LLVM系列第二十八章:写一个JIT Hello World
LLVM系列第二十九章:写一个简单的常量加法“消除”工具(Pass)

flex&bison系列



前言

LLVM是一个著名的开源编译器项目、库、工具,在此记录下编译LLVM源码的过程,以备查阅。

一、操作系统

我用的操作系统是macOS 11.6.4:

System Version:        macOS 11.6.4 (20G417)
Kernel Version:        Darwin 20.6.0

Model Name:            MacBook Pro
Model Identifier:      MacBookPro15,1
Processor Name:        8-Core Intel Core i9
Processor Speed:       2.3 GHz
Number of Processors:  1
Total Number of Cores: 8
Memory:                16 GB

二、开发环境

用到的工具有Clang (Xcode)、Git、CMake以及Ninja。

关于安装Xcode, 可参考这个简易教程:

How to download Xcode DMG or XIP file? - Stack Overflow

安装后确认信息如下(示例):

% clang -v
                                                        
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

对于其它工具,可借助brew (https://brew.sh) 进行安装(示例):

brew install git cmake ninja

安装后确认信息如下(示例):

% brew list --version git cmake ninja

cmake 3.22.1
git 2.32.0
ninja 1.10.2_1

三、下载源码

使用命令如下(示例):

git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout -b llvmorg-12.0.0

确认branch的信息如下(示例):

% git branch
                   
* llvmorg-12.0.0
  main

四、编译并安装LLVM

我们可使用工具CMake和Ninja来编译LLVM源代码。

1. 生成项目配置

使用命令如下(示例):

cd llvm-project
mkdir build
cd build

# Compile clang as well
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS=clang ../llvm

# Or, don't compile clang
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../llvm

输出log如下(示例):

-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features - done
-- No build type selected, default to Debug
-- clang project is enabled
-- clang-tools-extra project is disabled
-- compiler-rt project is disabled
-- debuginfo-tests project is disabled
-- libc project is disabled
-- libclc project is disabled
-- libcxx project is disabled
-- libcxxabi project is disabled
-- libunwind project is disabled
-- lld project is disabled
-- lldb project is disabled
-- mlir project is disabled
-- openmp project is disabled
-- parallel-libs project is disabled
-- polly project is disabled
-- pstl project is disabled
-- flang project is disabled
-- Found libtool - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool
-- Looking for dlfcn.h - found
-- Looking for errno.h - found
-- Looking for fcntl.h - found
-- Looking for link.h - not found
-- Looking for malloc/malloc.h - found
-- Looking for pthread.h - found
-- Looking for signal.h - found
-- Looking for sys/ioctl.h - found
-- Looking for sys/mman.h - found
-- Looking for sys/param.h - found
-- Looking for sys/resource.h - found
-- Looking for sys/stat.h - found
-- Looking for sys/time.h - found
-- Looking for sys/types.h - found
-- Looking for sysexits.h - found
-- Looking for termios.h - found
-- Looking for unistd.h - found
-- Looking for valgrind/valgrind.h - not found
-- Looking for fenv.h - found
-- Looking for FE_ALL_EXCEPT - found
-- Looking for FE_INEXACT - found
-- Looking for mach/mach.h - found
-- Looking for histedit.h - found
-- Looking for CrashReporterClient.h - not found
-- Performing Test HAVE_CRASHREPORTER_INFO - Success
-- Looking for pthread_create in pthread - found
-- Looking for pthread_getspecific in pthread - found
-- Looking for pthread_rwlock_init in pthread - found
-- Looking for pthread_mutex_lock in pthread - found
-- Looking for dlopen in dl - found
-- Looking for clock_gettime in rt - not found
-- Looking for pfm_initialize in pfm - not found
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Found ZLIB: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libz.tbd (found version "1.2.11") 
-- Looking for compress2 - found
-- Found LibXml2: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libxml2.tbd (found version "2.9.4") 
-- Looking for xmlReadMemory - found
-- Looking for el_init in edit - found
-- Looking for xar_open in xar - found
-- Looking for arc4random - found
-- Looking for backtrace - found
-- backtrace facility detected in default set of libraries
-- Found Backtrace: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include  
-- Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Success
-- Looking for __register_frame - found
-- Looking for __deregister_frame - found
-- Looking for _Unwind_Backtrace - found
-- Looking for getpagesize - found
-- Looking for sysconf - found
-- Looking for getrusage - found
-- Looking for setrlimit - found
-- Looking for isatty - found
-- Looking for futimens - found
-- Looking for futimes - found
-- Looking for posix_fallocate - not found
-- Looking for lseek64 - not found
-- Looking for mallctl - not found
-- Looking for mallinfo - not found
-- Looking for malloc_zone_statistics - found
-- Looking for getrlimit - found
-- Looking for posix_spawn - found
-- Looking for pread - found
-- Looking for sbrk - found
-- Looking for strerror - found
-- Looking for strerror_r - found
-- Looking for strerror_s - not found
-- Looking for setenv - found
-- Looking for dlopen - found
-- Looking for dladdr - found
-- Performing Test HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC - Success
-- Performing Test HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC - Failed
-- Looking for __GLIBC__ - not found
-- Looking for pthread_getname_np - found
-- Looking for pthread_setname_np - found
-- Performing Test HAVE_STD_IS_TRIVIALLY_COPYABLE - Success
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB - Success
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB - Success
-- Performing Test LLVM_HAS_ATOMICS - Success
-- Performing Test SUPPORTS_VARIADIC_MACROS_FLAG - Success
-- Performing Test SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG - Success
-- Native target architecture is X86
-- Threads enabled.
-- Doxygen disabled.
-- Go bindings enabled.
-- Ninja version: 1.10.2
-- Found ld64 - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) 
-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) 
-- OCaml bindings disabled.
-- Could NOT find Python module pygments
-- Could NOT find Python module pygments.lexers.c_cpp
-- Could NOT find Python module yaml
-- LLVM host triple: x86_64-apple-darwin20.6.0
-- LLVM default target triple: x86_64-apple-darwin20.6.0
-- Performing Test C_SUPPORTS_FPIC - Success
-- Performing Test CXX_SUPPORTS_FPIC - Success
-- Building with -fPIC
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success
-- Performing Test C_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Success
-- Performing Test CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG - Success
-- Performing Test C_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Success
-- Performing Test CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Success
-- Performing Test C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Success
-- Performing Test CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Success
-- Performing Test CXX_SUPPORTS_CLASS_MEMACCESS_FLAG - Failed
-- Performing Test CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG - Success
-- Performing Test CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR - Success
-- Performing Test C_SUPPORTS_DELETE_NON_VIRTUAL_DTOR_FLAG - Success
-- Performing Test CXX_SUPPORTS_DELETE_NON_VIRTUAL_DTOR_FLAG - Success
-- Performing Test CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG - Success
-- Performing Test CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL - Success
-- Performing Test C_WCOMMENT_ALLOWS_LINE_WRAP - Success
-- Performing Test C_SUPPORTS_STRING_CONVERSION_FLAG - Success
-- Performing Test CXX_SUPPORTS_STRING_CONVERSION_FLAG - Success
-- Performing Test LINKER_SUPPORTS_COLOR_DIAGNOSTICS - Failed
-- Looking for os_signpost_interval_begin - found
-- Performing Test macos_signposts_usable - Success
-- Found Python3: /usr/local/Frameworks/Python.framework/Versions/3.9/bin/python3.9 (found version "3.9.6") found components: Interpreter 
-- Linker detection: ld64
-- Found Git: /usr/local/bin/git (found version "2.32.0") 
-- Targeting AArch64
-- Targeting AMDGPU
-- Targeting ARM
-- Targeting AVR
-- Targeting BPF
-- Targeting Hexagon
-- Targeting Lanai
-- Targeting Mips
-- Targeting MSP430
-- Targeting NVPTX
-- Targeting PowerPC
-- Targeting RISCV
-- Targeting Sparc
-- Targeting SystemZ
-- Targeting WebAssembly
-- Targeting X86
-- Targeting XCore
-- Looking for sys/resource.h - found
-- Clang version: 12.0.1
-- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG - Success
-- Host linker version: 711
-- Looking for include file CoreServices/CoreServices.h - found
-- Registering Bye as a pass plugin (static build: OFF)
-- Failed to find LLVM FileCheck
-- Version: 0.0.0
-- Performing Test HAVE_CXX_FLAG_STD_CXX11 - Success
-- Performing Test HAVE_CXX_FLAG_WALL - Success
-- Performing Test HAVE_CXX_FLAG_WEXTRA - Success
-- Performing Test HAVE_CXX_FLAG_WSHADOW - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS - Success
-- Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32 - Success
-- Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL - Success
-- Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_FNO_EXCEPTIONS - Success
-- Performing Test HAVE_CXX_FLAG_WNO_SUGGEST_OVERRIDE - Success
-- Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_WD654 - Failed
-- Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY - Success
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES -- failed to compile
-- Performing Test HAVE_CXX_FLAG_COVERAGE - Success
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX -- success
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/wuzhanglin/Sources/OpenSource/compiler/llvm-project/build

2. 编译LLVM

使用命令如下(示例):

ninja

整个编译过程大约需要30至60分钟。输出log如下(示例):

...
[164/3972] Building CXX object lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/BranchFolding.cpp.o
...
[3808/3808] Linking CXX executable bin/llvm-lto2

编译完成后,我们可以测试一下,确保一切正常(示例):

ninja check-all

整个测试过程大约需要一个小时。输出log如下(示例):

[390/704] cd .../llvm-project/clang/...al/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -m unittest discover
..............................................................................................................................
----------------------------------------------------------------------
Ran 126 tests in 21.427s

OK
[703/704] Running all regression tests
llvm-lit: .../llvm-project/llvm/utils/lit/lit/llvm/config.py:385: note: using clang: .../llvm-project/build/bin/clang
llvm-lit: .../llvm-project/llvm/utils/lit/lit/util.py:399: note: using SDKROOT: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk'
llvm-lit: .../llvm-project/build/utils/lit/tests/lit.cfg:79: warning: Setting a timeout per test not supported. Requires the Python psutil module but it could not be found. Try installing it via pip or via your operating system's package manager. Some tests will be skipped and the --timeout command line argument will not work.
FAIL: LLVM :: Bindings/Go/go.test (34351 of 69399)
******************** TEST 'LLVM :: Bindings/Go/go.test' FAILED ********************
Script:
--
: 'RUN: at line 1';   .../llvm-project/build/bin/llvm-go go=/usr/local/go/bin/go test llvm.org/llvm/bindings/go/llvm
--
Exit Code: 1

Command Output (stdout):
--
FAIL	llvm.org/llvm/bindings/go/llvm [build failed]
FAIL
--
Command Output (stderr):
--
# runtime/cgo
_cgo_export.c:3:10: fatal error: 'stdlib.h' file not found
--
********************
FAIL: LLVM :: tools/lto/no-bitcode.s (69143 of 69399)
******************** TEST 'LLVM :: tools/lto/no-bitcode.s' FAILED ********************
Script:
--
: 'RUN: at line 3';   .../llvm-project/build/bin/llvm-mc -triple=arm64-apple-ios7.0.0 -filetype=obj -o .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.o
: 'RUN: at line 4';   .../llvm-project/build/bin/llvm-ar r .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.a .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.o
: 'RUN: at line 5';   /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -lto_library .../llvm-project/build/test/../lib/libLTO.dylib -arch x86_64 -dylib -mllvm -O0 -o .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.dylib .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.a
--
Exit Code: 1
Command Output (stderr):
--
.../llvm-project/build/bin/llvm-ar: warning: creating .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.a
ld: warning: platform not specified
ld: warning: No platform min-version specified on command line
ld: warning: ignoring file .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.a, building for -x86_64 but attempting to link with file built for iOS-arm64
ld: dynamic main executables must link with libSystem.dylib for architecture x86_64
--
********************
FAIL: LLVM :: tools/lto/opt-level.ll (69226 of 69399)
******************** TEST 'LLVM :: tools/lto/opt-level.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   .../llvm-project/build/bin/llvm-as .../llvm-project/llvm/test/tools/lto/opt-level.ll -o .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.o
: 'RUN: at line 2';   /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -lto_library .../llvm-project/build/test/../lib/libLTO.dylib -arch x86_64 -dylib -mllvm -O0 -o .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.dylib .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.o
: 'RUN: at line 3';   .../llvm-project/build/bin/llvm-nm --no-llvm-bc .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.dylib | .../llvm-project/build/bin/FileCheck --allow-unused-prefixes=false --check-prefix=CHECK-O0 .../llvm-project/llvm/test/tools/lto/opt-level.ll
: 'RUN: at line 4';   /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -lto_library .../llvm-project/build/test/../lib/libLTO.dylib -arch x86_64 -dylib -mllvm -O2 -o .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.dylib .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.o
: 'RUN: at line 5';   .../llvm-project/build/bin/llvm-nm --no-llvm-bc .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.dylib | .../llvm-project/build/bin/FileCheck --allow-unused-prefixes=false --check-prefix=CHECK-O2 .../llvm-project/llvm/test/tools/lto/opt-level.ll
--
Exit Code: 1
Command Output (stderr):
--
ld: warning: platform not specified
ld: warning: No platform min-version specified on command line
ld: dynamic main executables must link with libSystem.dylib for architecture x86_64
--
********************
FAIL: LLVM :: tools/lto/print-stats.ll (69227 of 69399)
******************** TEST 'LLVM :: tools/lto/print-stats.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   .../llvm-project/build/bin/llvm-as .../llvm-project/llvm/test/tools/lto/print-stats.ll -o .../llvm-project/build/test/tools/lto/Output/print-stats.ll.tmp.o
: 'RUN: at line 2';   /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -lto_library .../llvm-project/build/test/../lib/libLTO.dylib -arch x86_64 -dylib -mllvm -stats -o .../llvm-project/build/test/tools/lto/Output/print-stats.ll.tmp.dylib .../llvm-project/build/test/tools/lto/Output/print-stats.ll.tmp.o 2>&1 | .../llvm-project/build/bin/FileCheck --allow-unused-prefixes=false --check-prefix=STATS .../llvm-project/llvm/test/tools/lto/print-stats.ll
: 'RUN: at line 3';   /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -lto_library .../llvm-project/build/test/../lib/libLTO.dylib -arch x86_64 -dylib -o .../llvm-project/build/test/tools/lto/Output/print-stats.ll.tmp.dylib .../llvm-project/build/test/tools/lto/Output/print-stats.ll.tmp.o 2>&1 | .../llvm-project/build/bin/FileCheck --allow-unused-prefixes=false --check-prefix=NO_STATS .../llvm-project/llvm/test/tools/lto/print-stats.ll
--
Exit Code: 1
********************
FAIL: LLVM :: tools/lto/hide-linkonce-odr.ll (69229 of 69399)
******************** TEST 'LLVM :: tools/lto/hide-linkonce-odr.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   .../llvm-project/build/bin/llvm-as .../llvm-project/llvm/test/tools/lto/hide-linkonce-odr.ll -o .../llvm-project/build/test/tools/lto/Output/hide-linkonce-odr.ll.tmp.o
: 'RUN: at line 2';   /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -lto_library .../llvm-project/build/test/../lib/libLTO.dylib -dylib -arch x86_64 -macosx_version_min 10.10.0 -o .../llvm-project/build/test/tools/lto/Output/hide-linkonce-odr.ll.tmp.dylib .../llvm-project/build/test/tools/lto/Output/hide-linkonce-odr.ll.tmp.o -save-temps  -undefined dynamic_lookup -exported_symbol _c -exported_symbol _b  -exported_symbol _GlobLinkonce
: 'RUN: at line 4';   .../llvm-project/build/bin/llvm-dis .../llvm-project/build/test/tools/lto/Output/hide-linkonce-odr.ll.tmp.dylib.lto.opt.bc -o - | .../llvm-project/build/bin/FileCheck --allow-unused-prefixes=false --check-prefix=IR .../llvm-project/llvm/test/tools/lto/hide-linkonce-odr.ll
: 'RUN: at line 10';   .../llvm-project/build/bin/llvm-nm .../llvm-project/build/test/tools/lto/Output/hide-linkonce-odr.ll.tmp.dylib | .../llvm-project/build/bin/FileCheck --allow-unused-prefixes=false --check-prefix=NM .../llvm-project/llvm/test/tools/lto/hide-linkonce-odr.ll
--
Exit Code: 1
Command Output (stderr):
--
ld: dynamic main executables must link with libSystem.dylib for architecture x86_64
--
********************
********************
Failed Tests (5):
  LLVM :: Bindings/Go/go.test
  LLVM :: tools/lto/hide-linkonce-odr.ll
  LLVM :: tools/lto/no-bitcode.s
  LLVM :: tools/lto/opt-level.ll
  LLVM :: tools/lto/print-stats.ll

Testing Time: 4120.19s
  Unsupported      :   718
  Passed           : 68490
  Expectedly Failed:   186
  Failed           :     5

1 warning(s) in tests
FAILED: CMakeFiles/check-all .../llvm-project/build/CMakeFiles/check-all 
cd .../llvm-project/build && /usr/local/Frameworks/Python.framework/Versions/3.9/bin/python3.9 .../llvm-project/build/./bin/llvm-lit -sv --param USE_Z3_SOLVER=0 .../llvm-project/build/tools/clang/test .../llvm-project/build/utils/lit .../llvm-project/build/test
ninja: build stopped: subcommand failed.

有少量测试错误,但目前对我们使用LLVM没有影响。

3. 快速试用llc工具

我们可以简单试用一下LLVM的llc工具,进一步确保一切正常。使用命令如下(示例):

./bin/llc --version

输出log如下(示例):

LLVM (http://llvm.org/):
  LLVM version 12.0.1
  DEBUG build with assertions.
  Default target: x86_64-apple-darwin20.6.0
  Host CPU: skylake

  Registered Targets:
    aarch64    - AArch64 (little endian)
    aarch64_32 - AArch64 (little endian ILP32)
    aarch64_be - AArch64 (big endian)
    amdgcn     - AMD GCN GPUs
    arm        - ARM
    arm64      - ARM64 (little endian)
    arm64_32   - ARM64 (little endian ILP32)
    armeb      - ARM (big endian)
    avr        - Atmel AVR Microcontroller
    bpf        - BPF (host endian)
    bpfeb      - BPF (big endian)
    bpfel      - BPF (little endian)
    hexagon    - Hexagon
    lanai      - Lanai
    mips       - MIPS (32-bit big endian)
    mips64     - MIPS (64-bit big endian)
    mips64el   - MIPS (64-bit little endian)
    mipsel     - MIPS (32-bit little endian)
    msp430     - MSP430 [experimental]
    nvptx      - NVIDIA PTX 32-bit
    nvptx64    - NVIDIA PTX 64-bit
    ppc32      - PowerPC 32
    ppc32le    - PowerPC 32 LE
    ppc64      - PowerPC 64
    ppc64le    - PowerPC 64 LE
    r600       - AMD GPUs HD2XXX-HD6XXX
    riscv32    - 32-bit RISC-V
    riscv64    - 64-bit RISC-V
    sparc      - Sparc
    sparcel    - Sparc LE
    sparcv9    - Sparc V9
    systemz    - SystemZ
    thumb      - Thumb
    thumbeb    - Thumb (big endian)
    wasm32     - WebAssembly 32-bit
    wasm64     - WebAssembly 64-bit
    x86        - 32-bit X86: Pentium-Pro and above
    x86-64     - 64-bit X86: EM64T and AMD64
    xcore      - XCore

4. 安装LLVM

使用命令如下(示例):

sudo ninja install

(注意如果不用sudo的话,可能会因为文件访问权限问题,而导致安装失败。)

这样就把LLVM安装到了/usr/local目录下,输出log如下(示例):

[0/1] Install the project...
-- Install configuration: "Debug"
-- Installing: /usr/local/include/llvm
...
...
...
-- Installing: /usr/local/lib/cmake/llvm/./CheckLinkerFlag.cmake

我们快速地测试一下,确保安装成功。使用命令如下(示例):

which llc; llc --version

输出log如下(示例):

/usr/local/bin/llc
LLVM (http://llvm.org/):
  LLVM version 12.0.1
  DEBUG build with assertions.
  Default target: x86_64-apple-darwin20.6.0
  Host CPU: skylake

  Registered Targets:
    aarch64    - AArch64 (little endian)
    ...
    ...
    x86-64     - 64-bit X86: EM64T and AMD64
    xcore      - XCore

跟上一步的log是一样的。

总结

我们利用Git下载了LLVM的源代码,用CMake和Ninja工具编译并安装了LLVM,最后还简单地试用了一下LLVM工具库中的llc工具。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

LLVM系列第一章:编译LLVM源码 的相关文章

随机推荐

  • 使用Python的方式理解Golang的结构体struct

    Go源码 package GoTools import fmt 定义结构体存储密码 type Config struct password string func InitConfig password string Config c ne
  • Vue用户进行页面切换(路由跳转)时,动态改变路由的动画(transition效果)

    当我们在使用Vue Router时 为了用户有更好的视觉效果及体验 我们通常需要实现基于路由的动态过渡效果 github https github com Rise Devin FullStack Product Transport Use
  • retinaface代码讲解_「干货」RetinaFace最强开源人脸识别算法

    看来最早商业化的人脸检测为目标检测算法 依然是各大CV方向AI公司的必争之地 那我们今天主角就是RetinaFace RetinaFace 是今年5月份出现的人脸检测算法 当时取得了state of the art 作者也开源了代码 过去了
  • 集合的知识

    集合 collection集合的常用方法 collection的特点 Collection代表单列集合 每个元素 数据 只包含一个值 Map代表双列集合 每个元素包含两个值 键值对 Collection集合特点 由于collection是一
  • gRpc指南

    本文翻译自官网 原文 https grpc io docs languages java quickstart 快速开始 下面通过一个简单的样例 让你快速上手基于java的gRpc的使用 前置条件 JDK7以上版本 获取示例代码 示例代码是
  • 斯坦福密码学课程-笔记-01-Introduction绪论

    斯坦福密码学课程笔记 01 绪论 Introduction Course Overview Cryptography is everywhere Secure communication Secure Sockets Layer TLS P
  • 使用thop库对yolo等深度学习模型的FLOPS进行计算

    据说yolov5原来的FLOPS计算脚本有bug 因此这个大神推荐使用thop库进行计算 代码如下 input torch randn 1 3 416 416 flops params thop profile model inputs i
  • 【华为OD机试真题 C++】寻找链表的中间结点

    前言 本专栏将持续更新华为OD机试题目 并进行详细的分析与解答 包含完整的代码实现 希望可以帮助到正在努力的你 关于OD机试流程 面经 面试指导等 如有任何疑问 欢迎联系我 wechat steven moda email nansun09
  • SuperMemo 【POJ - 3580】【Splay+懒标记递推想法】

    题目链接 可以说这道题很好的给我们讲述了在Splay树上的lazy标记的递推 跟线段树上类似 在这棵二叉搜索树上 我们一样的去递推懒标记 接下来说说在哪几处需要专门注意懒标记的使用 这里有几处需要注意的地方 就是一开始给你的元素不是已经排好
  • 四种常见的代码覆盖率测试

    您听说过 代码覆盖率 吗 在这篇文章中 我们将探讨什么是测试中的代码覆盖率 以及四种衡量它的常用方法 什么是代码覆盖率 代码覆盖率是衡量测试代码测试了源代码百分比多少的指标 它可以帮助您识别可能缺乏适当测试的代码区域 通常 覆盖率指标会这样
  • 大头小头 字节序

    http blog csdn net zjf82031913 article details 7245183 字节序的问题涉及硬件架构 目前主要是Motorola的PowerPC系列CPU和Intel的x86系列CPU PowerPC系列采
  • Kibana导入CVS数据

    导入CVS数据 下载数据源CVS文件2018 7 12月份地震数据 https www elastic co assets bltb0648a200c490f5e quakes data csv 导入Machine Learning gt
  • 压缩zip文件和解压zip文件(设置压缩密码)

    欢迎访问个人博客 德鲁大叔撸代码 说明 注意引入的依赖 否则一直报错 很不容易找到的错误 import net lingala zip4j core ZipFile import net lingala zip4j exception Zi
  • 搭建并部署Vue3+TypeScript+Vite+ElementPlus项目

    目录 前言 一 搭建Vue3项目 1 安装yarn命令 2 创建VUE项目 3 安装VUE依赖 4 启动VUE项目 5 访问VUE项目 6 打包VUE项目 带项目名 7 部署VUE项目 二 使用Visual Studio Code管理vue
  • CVPR2023 语义分割论文合集

    国际计算机视觉与模式识别会议 CVPR 是计算机科学领域中的顶级会议之一 也是图像处理 机器学习 人工智能等多个领域的交叉学科会议 每年的CVPR会议都会有大量的论文投稿和学术交流活动 其中涵盖了包括图像处理 计算机视觉 模式识别 机器学习
  • STM32 USBH CDC开发及应用

    USB 是英文 Universal Serial BUS 通用串行总线 的缩写 其是一个外部总线标准 用于规范USB主机与外部设备的连接和通讯 由于项目需要 需要开发基于STM32 USB主机 HOST 的CDC的开发 用于编队表演系统中底
  • 【软件测试7】web自动化测试——12306购票实战

    web自动化测试 12306购票实战 一 自动化购票流程 登录 进入购票 填写信息 选择车次 预定 选择购票人 二 自动化环境配置 软件环境 Python selenium Python安装 Python Pycharm安装 seleniu
  • ECS云服务器2核4g够用吗?

    够不够用要看具体的需求 一般来说这个算是入门或者是入门以上的配置吧 满足我们一般个人用户大部分的建站需求 够不够用需要结合建站需求来考虑的 一般来说这个配置的阿里云服务器基本可以满足我们大部分个人和小微企业的建站需求了 我们除非是大型网站建
  • [生产力]VSCode必备插件-C/C++开发

    文章目录 1 C C for Visual Studio Code 2 C Intellisense 3 Git Graph 4 compareit 5 TODO Highlight 6 Bookmarks 7 Markdown All i
  • LLVM系列第一章:编译LLVM源码

    系列文章目录 LLVM系列第一章 编译LLVM源码 LLVM系列第二章 模块Module LLVM系列第三章 函数Function LLVM系列第四章 逻辑代码块Block LLVM系列第五章 全局变量Global Variable LLV