使用llvm 编译最新的linux 内核(LoongArch)

1. 准备交叉工具链

llvm 使用了最新的llvm-17, 编译方法见:编译LoongArch的llvm交叉工具链

gcc 从linux 官方下载:http://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/13.2.0/x86_64-gcc-13.2.0-nolibc-loongarch64-linux.tar.xz

发布llvm和gcc 相应的环境变量

$ llc --version
LLVM (http://llvm.org/):
  LLVM version 17.0.0rc
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: haswell

  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
    loongarch32 - 32-bit LoongArch
    loongarch64 - 64-bit LoongArch
    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)
    ve          - VE
    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

2. 下载内核源码

从https://www.kernel.org/ 下载最新的版本(linux-next) ,本次用的是linux 6.6rc1

3. 编译内核

$ cd linux-next
$ export ARCH=loongarch

$ make O=./build_llvm LLVM=1 loongson3_defconfig
$ make O=./build_llvm LLVM=1 -j4
make[1]: 进入目录“/home/loongson/work/oh/kernel/linux-next-next-20230906/build_llvm”
  GEN     Makefile
  CALL    ../scripts/checksyscalls.sh
  AS      arch/loongarch/kernel/genex.o
:11:9: error: Cannot represent a difference across sections
 .dword 768b-766b
        ^
:11:9: error: Cannot represent a difference across sections                                                              
 .dword 768b-766b
        ^
:11:9: error: Cannot represent a difference across sections                                                              
 .dword 768b-766b
        ^
:11:9: error: Cannot represent a difference across sections 

出现上面的错误是因为不relocalable 特性,修改内核配置 关掉CONFIG_RELOCATABLE

CONFIG_CRASH_DUMP=n
CONFIG_RELOCATABLE=n   
$ make O=./build_llvm LLVM=1 -j4

../arch/loongarch/include/asm/percpu.h:20:4: error: compiler support for the model attribute is necessary when a recent assembler is used
   20 | #  error compiler support for the model attribute is necessary when a recent assembler is used
      |    ^

出现上面的错误是因为不module 也还不支持,修改内核配置 关掉CONFIG_MODULES

 CONFIG_MODULES=n

你可能感兴趣的:(loongarch,linux,服务器)