首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >内核无法执行二进制文件(错误-8)

内核无法执行二进制文件(错误-8)
EN

Unix & Linux用户
提问于 2020-09-18 16:54:40
回答 1查看 1.4K关注 0票数 3

我的平台:

代码语言:javascript
运行
复制
SOC = STM32H743 (ARMv7E-M | Cortex-M7)
Board = Waveshare CoreH7XXI 
Linux Kernel = 5.8.10 (stable 2020-09-17)
initial defconfig file = stm32_defconfig
rootfs = built using busybox | busybox compiled using  arm-linux-gnueabihf-gcc

我通过遵循本指南创建了rootfs。

我的内核不能执行任何文件,甚至不能执行init文件>>>、/linuxrc/sbin/init

为了确保问题不是来自busybox文件,我编写了一个带有-mcpu=cortex-m7标志的C helloworld程序,并使用arm-linux-gnueabi-gcc编译了它,但是内核再次修改并抛出了-8错误(Exec格式错误)。

我的busybox文件都链接到busybox二进制文件,并且为32位arm正确编译了二进制文件:

代码语言:javascript
运行
复制
$ readelf -A bin/busybox
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "Cortex-M7"
  Tag_CPU_arch: v7E-M
  Tag_CPU_arch_profile: Microcontroller
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_rounding: Needed
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_CPU_unaligned_access: v6

内核错误:

代码语言:javascript
运行
复制
[    0.925859] Run /linuxrc as init process
[    0.943257] Kernel panic - not syncing: Requested init /linuxrc failed (error -8).
[    0.950654] ---[ end Kernel panic - not syncing: Requested init /linuxrc failed (error -8). ]---

我的helloworld程序:

代码语言:javascript
运行
复制
$ readelf -A hello
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "7E-M"
  Tag_CPU_arch: v7E-M
  Tag_CPU_arch_profile: Microcontroller
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_rounding: Needed
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_CPU_unaligned_access: v6

内核错误:

代码语言:javascript
运行
复制
[    1.189550] Run /hello as init process
[    1.198670] Kernel panic - not syncing: Requested init /hello failed (error -8).
[    1.205977] ---[ end Kernel panic - not syncing: Requested init /hello failed (error -8). ]---

Why内核不能执行二进制文件?

EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2020-10-13 12:59:05

问题是,您正在编译它的一个正常的静态精灵格式。您应该将其编译为FDPIC-ELF可执行文件(因为缺乏MMU,需要一个独立于位置的可执行文件(FDPIC) )。

FDPIC不是ET_EXEC型。它是ET_DYN (它意味着它是共享的)类型,并由Linux动态加载程序加载。

只需向其添加一个-mfdpic标志,并在busybox的kconfig菜单中关闭构建的静态二进制文件。

注意,默认情况下,在arm-uclinux-fdpicabi工具链中,-mfdpic标志是打开的。

票数 3
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/610094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档