Linker ELFIO正在创建所有零ELF部分,而不考虑设置数据。如何将数据放入.text部分?

Linker ELFIO正在创建所有零ELF部分,而不考虑设置数据。如何将数据放入.text部分?,linker,elf,readelf,Linker,Elf,Readelf,我正在尝试使用ELFIO创建一个ELF对象 解决方案:行节文本->设置标志(SHT\U程序位)应为区段文本->设置类型(SHT\U程序位) 结果对象错误(如下所述),因此: 如何创建包含实际数据的elf节? 计划如下: #包括 #包括 #包括“elfio/elfio.hpp” int main(){ std::共享的\u ptrelf\u对象; elf_object=std::shared_ptr(新的ELFIO::ELFIO); elf_对象->创建(ELFCLASS32,ELFDATA2LS

我正在尝试使用ELFIO创建一个ELF对象

解决方案:
节文本->设置标志(SHT\U程序位)应为
区段文本->设置类型(SHT\U程序位)

结果对象错误(如下所述),因此:
如何创建包含实际数据的elf节?

计划如下:

#包括
#包括
#包括“elfio/elfio.hpp”
int main(){
std::共享的\u ptrelf\u对象;
elf_object=std::shared_ptr(新的ELFIO::ELFIO);
elf_对象->创建(ELFCLASS32,ELFDATA2LSB);
elf_object->set_os_abi(ELFOSABI_NONE);
elf_对象->设置_类型(ET_REL);
elf_对象->设置_机器(EM_无);
ELFIO::section*section_text;
section_text=elf_object->sections.add(“.text”);//设置标志(SHT_PROGBITS);
区段文本->设置标志(SHF\U ALLOC | SHF\U EXECINSTR);
区段文本->设置地址对齐(0x10);
章节文本->设置数据(“0123456789ABCDEF”,16);
elf_对象->保存(“sample.elf”);
返回0;
}
当我使用
readelf
转储节时,.text节的大小和标志(AX,16字节)是正确的,但数据都是零

readelf-x.text-aW sample.elf
输出:


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:                           None
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          80 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         3
  Section header string table index: 1

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .shstrtab         STRTAB          00000000 000034 000011 00      0   0  1
  [ 2] .text             NULL            00000000 000050 000010 00  AX  0   0 16
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  p (processor specific)

There are no section groups in this file.

There are no program headers in this file.

There is no dynamic section in this file.

There are no relocations in this file.

The decoding of unwind sections for machine type None is not currently supported.

No version information found in this file.

Hex dump of section '.text':
  0x00000000 00000000 00000000 00000000 00000000 ................
hextump是:

Hex dump of section '.text':
  0x00000000 00000000 00000000 00000000 00000000 ................
预计时间为:

Hex dump of section '.text':
  0x00000000 30313233 34353637 38394142 43444546 0123456789ABCDEF

你打错了。反而

section_text->set_flags(SHT_PROGBITS);


我已经注意到并相应地编辑了原始帖子。但换行使其不太可见。
section_text->set_type(SHT_PROGBITS);