elf_object.cc (9810:e895db06e69f) | elf_object.cc (10037:5cac77888310) |
---|---|
1/* | 1/* |
2 * Copyright (c) 2011-2013 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * |
|
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright --- 46 unchanged lines hidden (view full) --- 56 panic("wrong elf version number!"); 57 58 // get a pointer to elf structure 59 elf = elf_memory((char*)data,len); 60 // will only fail if fd is invalid 61 assert(elf != NULL); 62 63 // Check that we actually have a elf file | 14 * Copyright (c) 2003-2005 The Regents of The University of Michigan 15 * All rights reserved. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions are 19 * met: redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer; 21 * redistributions in binary form must reproduce the above copyright --- 46 unchanged lines hidden (view full) --- 68 panic("wrong elf version number!"); 69 70 // get a pointer to elf structure 71 elf = elf_memory((char*)data,len); 72 // will only fail if fd is invalid 73 assert(elf != NULL); 74 75 // Check that we actually have a elf file |
64 if (gelf_getehdr(elf, &ehdr) ==0) { | 76 if (gelf_getehdr(elf, &ehdr) == 0) { |
65 DPRINTFR(Loader, "Not ELF\n"); 66 elf_end(elf); 67 return NULL; 68 } else { 69 //Detect the architecture 70 //Since we don't know how to check for alpha right now, we'll 71 //just assume if it wasn't something else and it's 64 bit, that's 72 //what it must be. --- 16 unchanged lines hidden (view full) --- 89 "Please recompile your binary.\n"); 90 } 91 } else if (ehdr.e_machine == EM_X86_64 && 92 ehdr.e_ident[EI_CLASS] == ELFCLASS64) { 93 arch = ObjectFile::X86_64; 94 } else if (ehdr.e_machine == EM_386 && 95 ehdr.e_ident[EI_CLASS] == ELFCLASS32) { 96 arch = ObjectFile::I386; | 77 DPRINTFR(Loader, "Not ELF\n"); 78 elf_end(elf); 79 return NULL; 80 } else { 81 //Detect the architecture 82 //Since we don't know how to check for alpha right now, we'll 83 //just assume if it wasn't something else and it's 64 bit, that's 84 //what it must be. --- 16 unchanged lines hidden (view full) --- 101 "Please recompile your binary.\n"); 102 } 103 } else if (ehdr.e_machine == EM_X86_64 && 104 ehdr.e_ident[EI_CLASS] == ELFCLASS64) { 105 arch = ObjectFile::X86_64; 106 } else if (ehdr.e_machine == EM_386 && 107 ehdr.e_ident[EI_CLASS] == ELFCLASS32) { 108 arch = ObjectFile::I386; |
97 } else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64) { 98 arch = ObjectFile::Alpha; 99 } else if (ehdr.e_machine == EM_ARM) { | 109 } else if (ehdr.e_machine == EM_ARM && 110 ehdr.e_ident[EI_CLASS] == ELFCLASS32) { |
100 if (bits(ehdr.e_entry, 0)) { 101 arch = ObjectFile::Thumb; 102 } else { 103 arch = ObjectFile::Arm; 104 } | 111 if (bits(ehdr.e_entry, 0)) { 112 arch = ObjectFile::Thumb; 113 } else { 114 arch = ObjectFile::Arm; 115 } |
116 } else if ((ehdr.e_machine == EM_AARCH64) && 117 ehdr.e_ident[EI_CLASS] == ELFCLASS64) { 118 arch = ObjectFile::Arm64; 119 } else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64) { 120 arch = ObjectFile::Alpha; |
|
105 } else if (ehdr.e_machine == EM_PPC && 106 ehdr.e_ident[EI_CLASS] == ELFCLASS32) { | 121 } else if (ehdr.e_machine == EM_PPC && 122 ehdr.e_ident[EI_CLASS] == ELFCLASS32) { |
107 if (ehdr.e_ident[EI_DATA] == ELFDATA2MSB) { 108 arch = ObjectFile::Power; 109 } else { 110 fatal("The binary you're trying to load is compiled for " | 123 if (ehdr.e_ident[EI_DATA] == ELFDATA2MSB) { 124 arch = ObjectFile::Power; 125 } else { 126 fatal("The binary you're trying to load is compiled for " |
111 "little endian Power.\nM5 only supports big " 112 "endian Power. Please recompile your binary.\n"); | 127 "little endian Power.\nM5 only supports big " 128 "endian Power. Please recompile your binary.\n"); |
113 } | 129 } |
114 } else if (ehdr.e_machine == EM_PPC64) { 115 fatal("The binary you're trying to load is compiled for 64-bit " 116 "Power. M5\n only supports 32-bit Power. Please " 117 "recompile your binary.\n"); 118 } else { 119 warn("Unknown architecture: %d\n", ehdr.e_machine); 120 arch = ObjectFile::UnknownArch; 121 } 122 123 //Detect the operating system | 130 } else if (ehdr.e_machine == EM_PPC64) { 131 fatal("The binary you're trying to load is compiled for 64-bit " 132 "Power. M5\n only supports 32-bit Power. Please " 133 "recompile your binary.\n"); 134 } else { 135 warn("Unknown architecture: %d\n", ehdr.e_machine); 136 arch = ObjectFile::UnknownArch; 137 } 138 139 //Detect the operating system |
124 switch (ehdr.e_ident[EI_OSABI]) 125 { 126 | 140 switch (ehdr.e_ident[EI_OSABI]) { |
127 case ELFOSABI_LINUX: 128 opSys = ObjectFile::Linux; 129 break; 130 case ELFOSABI_SOLARIS: 131 opSys = ObjectFile::Solaris; 132 break; 133 case ELFOSABI_TRU64: 134 opSys = ObjectFile::Tru64; --- 66 unchanged lines hidden (view full) --- 201 result->_programHeaderTable = 0; 202 for(int hdrnum = 0; hdrnum < result->_programHeaderCount; hdrnum++) 203 { 204 gelf_getphdr(elf, hdrnum, &phdr); 205 //Check if we've found the segment with the headers in it 206 if(phdr.p_offset <= e_phoff && 207 phdr.p_offset + phdr.p_filesz > e_phoff) 208 { | 141 case ELFOSABI_LINUX: 142 opSys = ObjectFile::Linux; 143 break; 144 case ELFOSABI_SOLARIS: 145 opSys = ObjectFile::Solaris; 146 break; 147 case ELFOSABI_TRU64: 148 opSys = ObjectFile::Tru64; --- 66 unchanged lines hidden (view full) --- 215 result->_programHeaderTable = 0; 216 for(int hdrnum = 0; hdrnum < result->_programHeaderCount; hdrnum++) 217 { 218 gelf_getphdr(elf, hdrnum, &phdr); 219 //Check if we've found the segment with the headers in it 220 if(phdr.p_offset <= e_phoff && 221 phdr.p_offset + phdr.p_filesz > e_phoff) 222 { |
209 result->_programHeaderTable = phdr.p_paddr + e_phoff; | 223 result->_programHeaderTable = 224 phdr.p_paddr + (e_phoff - phdr.p_offset); |
210 break; 211 } 212 } 213 } 214 else 215 result->_programHeaderTable = 0; 216 217 --- 200 unchanged lines hidden (view full) --- 418 419bool 420ElfObject::loadWeakSymbols(SymbolTable *symtab, Addr addrMask) 421{ 422 return loadSomeSymbols(symtab, STB_WEAK, addrMask); 423} 424 425bool | 225 break; 226 } 227 } 228 } 229 else 230 result->_programHeaderTable = 0; 231 232 --- 200 unchanged lines hidden (view full) --- 433 434bool 435ElfObject::loadWeakSymbols(SymbolTable *symtab, Addr addrMask) 436{ 437 return loadSomeSymbols(symtab, STB_WEAK, addrMask); 438} 439 440bool |
426ElfObject::loadSections(PortProxy& memProxy, Addr addrMask) | 441ElfObject::loadSections(PortProxy& memProxy, Addr addrMask, Addr offset) |
427{ | 442{ |
428 if (!ObjectFile::loadSections(memProxy, addrMask)) | 443 if (!ObjectFile::loadSections(memProxy, addrMask, offset)) |
429 return false; 430 431 vector<Segment>::iterator extraIt; 432 for (extraIt = extraSegments.begin(); 433 extraIt != extraSegments.end(); extraIt++) { | 444 return false; 445 446 vector<Segment>::iterator extraIt; 447 for (extraIt = extraSegments.begin(); 448 extraIt != extraSegments.end(); extraIt++) { |
434 if (!loadSection(&(*extraIt), memProxy, addrMask)) { | 449 if (!loadSection(&(*extraIt), memProxy, addrMask, offset)) { |
435 return false; 436 } 437 } 438 return true; 439} 440 441void 442ElfObject::getSections() --- 43 unchanged lines hidden --- | 450 return false; 451 } 452 } 453 return true; 454} 455 456void 457ElfObject::getSections() --- 43 unchanged lines hidden --- |