LLVM IR Setup (clang 21.1.0)
対象実装: このドキュメントは現行 Bootstrap 実装の LLVM target 開発環境メモを記述する。
NEPLg2.1 の正の仕様や target 設計はdoc/2.1spec/platform.mdを参照。
This document describes the minimum setup to use LLVM IR with clang 21.1.0 on Linux/WSL.
Requirements
clang21.1.0llvm-as21.1.0llc21.1.0lli21.1.0
Version check:
clang --version
llvm-as --version
llc --version
lli --version
Environment variables for llvm-sys/inkwell
When using LLVM 21 in Rust (llvm-sys/inkwell), set the prefix to LLVM 21.1.0:
export LLVM_SYS_211_PREFIX=/opt/llvm-21.1.0Optional:
export PATH=/opt/llvm-21.1.0/bin:$PATH
LLVM IR workflow (quick check)
Create C source:
mkdir -p tmp/llvm_ir
cat > tmp/llvm_ir/hello.c << 'EOF'
#include <stdio.h>
int add(int a, int b) { return a + b; }
int main(void) { printf("sum=%d\n", add(20, 22)); return 0; }
EOFGenerate LLVM IR:
clang -S -emit-llvm -O0 tmp/llvm_ir/hello.c -o tmp/llvm_ir/hello.llRun IR directly:
lli tmp/llvm_ir/hello.llExpected output:
sum=42Compile IR to object and link:
llc -relocation-model=pic -filetype=obj tmp/llvm_ir/hello.ll -o tmp/llvm_ir/hello.o
clang tmp/llvm_ir/hello.o -o tmp/llvm_ir/hello
tmp/llvm_ir/helloExpected output:
sum=42
Notes
-relocation-model=picavoids linker warnings related to PIE/text relocations on Linux.- This is the current baseline (
clang 21.1.0 + linux native) for upcoming LLVM IR target work innepl-cli.