> compile NEMU

ysyx_22040000 李心杨
Linux calcite 6.6.19 #1-NixOS SMP PREEMPT_DYNAMIC Fri Mar  1 12:35:11 UTC 2024 x86_64 GNU/Linux
 00:39:11  up  10:14,  2 users,  load average: 0.97, 0.70, 0.60
This commit is contained in:
tracer-ysyx 2024-03-17 00:39:11 +08:00 committed by xinyangli
parent 6a279a4429
commit 39f0f75bf4

View file

@ -1,3 +1,4 @@
#include <assert.h>
#include <common.h>
#include <elf.h>
@ -16,6 +17,8 @@ void init_elf(const char *path) {
FAILED_GOTO(failed_nosym, fseek(elf_file, header.e_shoff, SEEK_SET) != 0);
FAILED_GOTO(failed_nosym, fread(section_header, header.e_shentsize, header.e_shnum, elf_file) <= 0);
char *shstrtab = calloc(1, section_header[header.e_shstrndx].sh_size);
Elf32_Shdr *symtab = NULL, *strtab = NULL;
for(int i = 0; i < header.e_shnum; i++) {
psh = section_header + i;
@ -26,12 +29,16 @@ void init_elf(const char *path) {
strtab = psh;
printf("strtab: %u %u\n", strtab->sh_size, strtab->sh_offset);
}
FAILED_GOTO(failed_shstrtab, fseek(elf_file, section_header[header.e_shstrndx].sh_offset, SEEK_SET) != 0);
FAILED_GOTO(failed_shstrtab, fread(shstrtab, sizeof(Elf32_Sym), section_header[header.e_shstrndx].sh_size, elf_file) <= 0);
printf("%s", shstrtab);
// if(symtab && strtab) break;
}
int sym_length = symtab->sh_size / sizeof(Elf32_Sym);
Elf32_Sym *sym = calloc(sym_length, sizeof(Elf32_Sym));
FAILED_GOTO(failed_nosym, sym == NULL);
FAILED_GOTO(failed, fseek(elf_file, symtab->sh_offset, SEEK_SET) != 0);
FAILED_GOTO(failed, fread(sym, sizeof(Elf32_Sym), sym_length, elf_file) <= 0);
for(int j = 0; j < sym_length; j++) {
@ -46,6 +53,8 @@ void init_elf(const char *path) {
return;
failed:
free(sym);
failed_shstrtab:
free(shstrtab);
failed_nosym:
Error("Failed reading elf file");
}