一开始我非常疑惑——内核、buildroot、我的程序,这三个用同一个编译器编译的,怎么会出现非法指令呢?如果我的程序是非法指令,那内核和用户态的init程序应该也是跑不起来的。
在解决完后的上帝视角来看是很简单的问题,但如果要是在当时,应该怎么排查呢?现在想来思路是很清晰了,但是为什么我当时会被困住打转,这才是我想要研究的。
探索时
# ./pid-test
Illegal instruction
# file ./pid-test
./pid-test: ELF 64-bit LSB pie executable, LoongArch, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-loongarch-lp64d.so.1, for GNU/Linux 5.19.0, stripped
# readelf -h ./pid-test
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Position-Independent Executable file)
Machine: LoongArch
Version: 0x1
Entry point address: 0x9f20
Start of program headers: 64 (bytes into file)
Start of section headers: 197016 (bytes into file)
Flags: 0x43, DOUBLE-FLOAT, OBJ-v1
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 9
Size of section headers: 64 (bytes)
Number of section headers: 26
Section header string table index: 25
# cat /etc/os-release
NAME=Buildroot
VERSION=2026.05-rc3-49-g7811063db2
ID=buildroot VERSION_ID=2026.05-rc3
PRETTY_NAME="Buildroot 2026.05-rc3"
# cat /proc/cpuinfo
system type : generic-loongson-machine
processor : 0
package : 0
core : 0
global_id : 0
CPU Family : Loongson-64bit
Model Name : Loongson-2K0300
PRID : LA264 (0014a030)
CPU Revision : 0x30
FPU Revision : 0x00
CPU MHz : 1000.00
BogoMIPS : 2000.00
TLB Entries : 64
Address Sizes : 40 bits physical, 40 bits virtual
ISA : loongarch32r loongarch32s loongarch64
Features : cpucfg lam fpu crc32 lspw lbt_mips
Hardware Watchpoint : yes, iwatch count: 4, dwatch count: 2

