gcc 如何在elf文件中设置EXEC_P标志

ymdaylpp  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(118)

我使用riscv 64-unknown-elf-objcopy从一个intel-hex文件生成了一个elf文件。
确切命令:

riscv64-unknown-elf-objcopy -O elf32-littleriscv --set-start 0x10000000 --rename-section .sec1=.text image32.ihex image32.elf

结果如下所示:

$ riscv64-unknown-elf-readelf image32.elf -h
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           RISC-V
  Version:                           0x1
  Entry point address:               0x10000000
  Start of program headers:          0 (bytes into file)
  Start of section headers:          136148 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         8
  Section header string table index: 7

我的目的是使用“Spike”执行它。
斯派克不接受我的精灵文件:

spike --isa=RV32IM --priv=MU -m0x10000000:0x00200000 --real-time-clint image32.elf
spike: ../fesvr/elfloader.cc:36: std::map<std::__cxx11::basic_string<char>, long unsigned int> load_elf(const char*, memif_t*, reg_t*): Assertion `IS_ELF_EXEC(*eh64)' failed.

它接受具有以下标题的elf文件:

$ riscv64-unknown-elf-readelf ok.elf -h
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           RISC-V
  Version:                           0x1
  Entry point address:               0x10000000
  Start of program headers:          52 (bytes into file)
  Start of section headers:          54672 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         3
  Size of section headers:           40 (bytes)
  Number of section headers:         23
  Section header string table index: 22

我想我需要将“Type”字段从“REL”更改为“EXEC”,但我在objcopy中没有看到任何选项。

lvjbypge

lvjbypge1#

This post表示以下序列可能会执行您想要的操作:

riscv64-unknown-elf-objcopy  -I ihex   -O binary image32.ihex image32.bin
riscv64-unknown-elf-objcopy  -I binary -O riscv64-unknown-elf image32.bin image32.elf

但我只是猜测:-(

相关问题