From c9d88aa08941d41d3d89d91b2c1c5e6eaa6f2894 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Wed, 14 Jan 2004 04:18:20 -0500 Subject: Minor fixes to loader and an additional header file in alpha_access.h when we are compiling the console. base/loader/elf_object.cc: added code to verify that the .bss section is 0; added code to only load function and label types dev/alpha_access.h: include inittypes if we are compiling the console code --HG-- extra : convert_revision : b88fb36500b1c1003d44ed95cefdd2a30b7466b8 --- base/loader/elf_object.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'base/loader/elf_object.cc') diff --git a/base/loader/elf_object.cc b/base/loader/elf_object.cc index d43e2fe7c..2cdce4259 100644 --- a/base/loader/elf_object.cc +++ b/base/loader/elf_object.cc @@ -115,10 +115,14 @@ ElfObject::loadSections(FunctionalMemory *mem, bool loadPhys) Elf_Scn *section; GElf_Shdr shdr; GElf_Ehdr ehdr; + uint8_t *zeromem; + uint8_t *sectionData; Addr address; char *secname; + + /* check that header matches library version */ assert(elf_version(EV_CURRENT) != EV_NONE); @@ -152,6 +156,9 @@ ElfObject::loadSections(FunctionalMemory *mem, bool loadPhys) elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name), shdr.sh_addr, shdr.sh_size, shdr.sh_offset, shdr.sh_flags, shdr.sh_flags & SHF_ALLOC ? "ALLOC" : ""); secname = elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name); + + sectionData = fileData + shdr.sh_offset; + if(secname) { if (strcmp(secname, ".text")==0) @@ -168,6 +175,13 @@ ElfObject::loadSections(FunctionalMemory *mem, bool loadPhys) { bss.baseAddr = shdr.sh_addr; bss.size = shdr.sh_size; + + /* If this is the .bss section it must be 0, so just + to be extra causious, lets allocate some memory + bzero it, and write that */ + zeromem = (uint8_t*)malloc(shdr.sh_size); + memset(zeromem, 0, shdr.sh_size); + sectionData = zeromem; } } if(shdr.sh_size != 0) @@ -175,11 +189,11 @@ ElfObject::loadSections(FunctionalMemory *mem, bool loadPhys) if (loadPhys) { address = shdr.sh_addr &= (ULL(1) << 40) - 1; - mem->prot_write(address, fileData + shdr.sh_offset, shdr.sh_size); + mem->prot_write(address, sectionData, shdr.sh_size); } else { - mem->prot_write(shdr.sh_addr, fileData + shdr.sh_offset, shdr.sh_size); + mem->prot_write(shdr.sh_addr, sectionData, shdr.sh_size); } } @@ -188,6 +202,7 @@ ElfObject::loadSections(FunctionalMemory *mem, bool loadPhys) ++secidx; section = elf_getscn(elf, secidx); } + free(zeromem); elf_end(elf); @@ -239,7 +254,8 @@ ElfObject::loadGlobalSymbols(SymbolTable *symtab) for (ii = 0; ii < count; ++ii) { gelf_getsym(data, ii, &sym); - if (GELF_ST_BIND(sym.st_info) & STB_GLOBAL) + if ((GELF_ST_BIND(sym.st_info) & STB_GLOBAL) && + ((GELF_ST_TYPE(sym.st_info) == STT_FUNC) || (GELF_ST_TYPE(sym.st_info) == STT_NOTYPE))) { symtab->insert(sym.st_value, elf_strptr(elf, shdr.sh_link, sym.st_name)); } -- cgit v1.2.3 From 54782bfb30a275b8294c3a993e420bc0d2b97725 Mon Sep 17 00:00:00 2001 From: Ali Saidi Date: Wed, 14 Jan 2004 16:12:00 -0500 Subject: Elf loader now conforms to coding style and config files for linux use /m5/system/linux for their binaries base/loader/elf_object.cc: Elf loader now conforms to coding style --HG-- extra : convert_revision : 558e587e969535f31987f2810ee17ec72006de0a --- base/loader/elf_object.cc | 54 +++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'base/loader/elf_object.cc') diff --git a/base/loader/elf_object.cc b/base/loader/elf_object.cc index 2cdce4259..df3e15f76 100644 --- a/base/loader/elf_object.cc +++ b/base/loader/elf_object.cc @@ -111,15 +111,15 @@ bool ElfObject::loadSections(FunctionalMemory *mem, bool loadPhys) { Elf *elf; - int secidx = 1; /* there is a 0 but it is nothing, go figure*/ + int sec_idx = 1; /* there is a 0 but it is nothing, go figure*/ Elf_Scn *section; GElf_Shdr shdr; GElf_Ehdr ehdr; - uint8_t *zeromem; - uint8_t *sectionData; + uint8_t *zero_mem; + uint8_t *section_data; Addr address; - char *secname; + char *sec_name; @@ -141,7 +141,7 @@ ElfObject::loadSections(FunctionalMemory *mem, bool loadPhys) /* Get the first section */ - section = elf_getscn(elf, secidx); + section = elf_getscn(elf, sec_idx); /* While there are no more sections */ while (section != NULL) @@ -155,23 +155,23 @@ ElfObject::loadSections(FunctionalMemory *mem, bool loadPhys) DPRINTF(Loader,"Name: %20s Address: 0x%016llx Size: 0x%08llx Offset: 0x%08llx Flags:0x%08llx %s\n", elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name), shdr.sh_addr, shdr.sh_size, shdr.sh_offset, shdr.sh_flags, shdr.sh_flags & SHF_ALLOC ? "ALLOC" : ""); - secname = elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name); + sec_name = elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name); - sectionData = fileData + shdr.sh_offset; + section_data = fileData + shdr.sh_offset; - if(secname) + if(sec_name) { - if (strcmp(secname, ".text")==0) + if (strcmp(sec_name, ".text")==0) { text.baseAddr = shdr.sh_addr; text.size = shdr.sh_size; } - if (strcmp(secname, ".data")==0) + if (strcmp(sec_name, ".data")==0) { data.baseAddr = shdr.sh_addr; data.size = shdr.sh_size; } - if (strcmp(secname, ".bss")==0) + if (strcmp(sec_name, ".bss")==0) { bss.baseAddr = shdr.sh_addr; bss.size = shdr.sh_size; @@ -179,9 +179,9 @@ ElfObject::loadSections(FunctionalMemory *mem, bool loadPhys) /* If this is the .bss section it must be 0, so just to be extra causious, lets allocate some memory bzero it, and write that */ - zeromem = (uint8_t*)malloc(shdr.sh_size); - memset(zeromem, 0, shdr.sh_size); - sectionData = zeromem; + zero_mem = (uint8_t*)malloc(shdr.sh_size); + memset(zero_mem, 0, shdr.sh_size); + section_data = zero_mem; } } if(shdr.sh_size != 0) @@ -189,20 +189,20 @@ ElfObject::loadSections(FunctionalMemory *mem, bool loadPhys) if (loadPhys) { address = shdr.sh_addr &= (ULL(1) << 40) - 1; - mem->prot_write(address, sectionData, shdr.sh_size); + mem->prot_write(address, section_data, shdr.sh_size); } else { - mem->prot_write(shdr.sh_addr, sectionData, shdr.sh_size); + mem->prot_write(shdr.sh_addr, section_data, shdr.sh_size); } } } - ++secidx; - section = elf_getscn(elf, secidx); + ++sec_idx; + section = elf_getscn(elf, sec_idx); } - free(zeromem); + free(zero_mem); elf_end(elf); @@ -214,7 +214,7 @@ bool ElfObject::loadGlobalSymbols(SymbolTable *symtab) { Elf *elf; - int secidx = 1; /* there is a 0 but it is nothing, go figure*/ + int sec_idx = 1; /* there is a 0 but it is nothing, go figure*/ Elf_Scn *section; GElf_Shdr shdr; Elf_Data *data; @@ -235,7 +235,7 @@ ElfObject::loadGlobalSymbols(SymbolTable *symtab) /* Get the first section */ - section = elf_getscn(elf, secidx); + section = elf_getscn(elf, sec_idx); /* While there are no more sections */ while (section != NULL) @@ -261,8 +261,8 @@ ElfObject::loadGlobalSymbols(SymbolTable *symtab) } } } - ++secidx; - section = elf_getscn(elf, secidx); + ++sec_idx; + section = elf_getscn(elf, sec_idx); } elf_end(elf); @@ -275,7 +275,7 @@ ElfObject::loadLocalSymbols(SymbolTable *symtab) { Elf *elf; - int secidx = 1; /* there is a 0 but it is nothing, go figure*/ + int sec_idx = 1; /* there is a 0 but it is nothing, go figure*/ Elf_Scn *section; GElf_Shdr shdr; Elf_Data *data; @@ -296,7 +296,7 @@ ElfObject::loadLocalSymbols(SymbolTable *symtab) /* Get the first section */ - section = elf_getscn(elf, secidx); + section = elf_getscn(elf, sec_idx); /* While there are no more sections */ while (section != NULL) @@ -321,8 +321,8 @@ ElfObject::loadLocalSymbols(SymbolTable *symtab) } } } - ++secidx; - section = elf_getscn(elf, secidx); + ++sec_idx; + section = elf_getscn(elf, sec_idx); } elf_end(elf); -- cgit v1.2.3