• 使用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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50

    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 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

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

    CONFIG_CRASH_DUMP=n
    CONFIG_RELOCATABLE=n   
    
    • 1
    • 2
    $ 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
          |    ^
    
    • 1
    • 2
    • 3
    • 4
    • 5

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

     CONFIG_MODULES=n
    
    • 1
  • 相关阅读:
    (C++进阶)正则表达式
    比较Visual Studio Code中的文件
    智慧城市标准化白皮书(2022版)发布
    Linux 系统IO函数之stat、lstat函数
    112二二位
    java面试题背不下来怎么办?java面试题总结
    Rust 中的 Pin UnPin Async Await 实现机制
    springboot项目讲解
    Pytorch手撸Attention
    关于Android 日历事件的实现
  • 原文地址:https://blog.csdn.net/mxcai2005/article/details/132722693