ELF File Format

I am trying to manually load the hexdump of an elf file that I compiled with g ++ into the processor simulation I developed. There are 30 sections of the standard elf file, and I load all 30 segments given their proper memory location offset. Then I start my program counter at the beginning of the section .text(00400130), but it seems that the program is not working correctly. I checked my processor design relatively thoroughly using SPIM as the gold standard. It is strange that if I load the assembly into SPIM, and then take the disassembled sections .textand .datawhich are generated by the software, load them into the processor memory, the programs work. This is different from what I want to do because I want:

  • write a C ++ program
  • compile it with mipseb-linux-g ++ (cross-compiler)
  • hex dump all partitions into your own file
  • read files and load contents into processor memory
  • run the program

Where in the ELF file should I first set my program counter? I have this in the beginning .textright now. Also, do I need to enable .textand .datafor my program to work correctly? What am I doing wrong here?

+3
source share
3 answers

ELF , .text. objdump -f, , - " ".

- program headers, section headers ELF ( , 30 ), e_entry ELF.

+5

e_entry ELF, , .

+1

Elf32_Ehdr.e_entry ( Elf64_Ehdr.e_entry, 64- ). , , .bss, , " " ELF .

.

Edit:

objdump -h /usr/bin/vim :

Sections:
Idx Name         Size      VMA               LMA               File off  Algn
...
22 .bss          00009628  00000000006df760  00000000006df760  001df760  2**5
                 ALLOC
23 .comment      00000bc8  0000000000000000  0000000000000000  001df760  2**0
                 CONTENTS, READONLY

Note that it is the File offsame for .bssand .comment, which means that it is .bssempty in the disk file, but there must be a 0x9628byte in memory.

+1
source

Source: https://habr.com/ru/post/1751400/


All Articles