elf_object.cc (10810:683ab55819fd) elf_object.cc (10880:61a56f76222b)
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

--- 42 unchanged lines hidden (view full) ---

51#include "base/trace.hh"
52#include "debug/Loader.hh"
53#include "sim/byteswap.hh"
54#include "gelf.h"
55
56using namespace std;
57
58ObjectFile *
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

--- 42 unchanged lines hidden (view full) ---

51#include "base/trace.hh"
52#include "debug/Loader.hh"
53#include "sim/byteswap.hh"
54#include "gelf.h"
55
56using namespace std;
57
58ObjectFile *
59ElfObject::tryFile(const string &fname, int fd, size_t len, uint8_t *data)
59ElfObject::tryFile(const string &fname, size_t len, uint8_t *data)
60{
61 Elf *elf;
62 GElf_Ehdr ehdr;
63 Arch arch = UnknownArch;
64 OpSys opSys = UnknownOpSys;
65
66 // check that header matches library version
67 if (elf_version(EV_CURRENT) == EV_NONE)
68 panic("wrong elf version number!");
69
70 // get a pointer to elf structure
71 elf = elf_memory((char*)data,len);
60{
61 Elf *elf;
62 GElf_Ehdr ehdr;
63 Arch arch = UnknownArch;
64 OpSys opSys = UnknownOpSys;
65
66 // check that header matches library version
67 if (elf_version(EV_CURRENT) == EV_NONE)
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
76 if (gelf_getehdr(elf, &ehdr) == 0) {
77 DPRINTFR(Loader, "Not ELF\n");
78 elf_end(elf);
79 return NULL;
80 } else {

--- 127 unchanged lines hidden (view full) ---

208 opSys = ObjectFile::FreeBSD;
209 }
210 }
211
212 section = elf_getscn(elf, ++secIdx);
213 } // while sections
214 }
215
72 assert(elf != NULL);
73
74 // Check that we actually have a elf file
75 if (gelf_getehdr(elf, &ehdr) == 0) {
76 DPRINTFR(Loader, "Not ELF\n");
77 elf_end(elf);
78 return NULL;
79 } else {

--- 127 unchanged lines hidden (view full) ---

207 opSys = ObjectFile::FreeBSD;
208 }
209 }
210
211 section = elf_getscn(elf, ++secIdx);
212 } // while sections
213 }
214
216 ElfObject * result = new ElfObject(fname, fd, len, data, arch, opSys);
215 ElfObject * result = new ElfObject(fname, len, data, arch, opSys);
217
218 //The number of headers in the file
219 result->_programHeaderCount = ehdr.e_phnum;
220 //Record the size of each entry
221 result->_programHeaderSize = ehdr.e_phentsize;
222 if(result->_programHeaderCount) //If there is a program header table
223 {
224 //Figure out the virtual address of the header table in the

--- 20 unchanged lines hidden (view full) ---

245
246
247 elf_end(elf);
248 return result;
249 }
250}
251
252
216
217 //The number of headers in the file
218 result->_programHeaderCount = ehdr.e_phnum;
219 //Record the size of each entry
220 result->_programHeaderSize = ehdr.e_phentsize;
221 if(result->_programHeaderCount) //If there is a program header table
222 {
223 //Figure out the virtual address of the header table in the

--- 20 unchanged lines hidden (view full) ---

244
245
246 elf_end(elf);
247 return result;
248 }
249}
250
251
253ElfObject::ElfObject(const string &_filename, int _fd,
254 size_t _len, uint8_t *_data,
252ElfObject::ElfObject(const string &_filename, size_t _len, uint8_t *_data,
255 Arch _arch, OpSys _opSys)
253 Arch _arch, OpSys _opSys)
256 : ObjectFile(_filename, _fd, _len, _data, _arch, _opSys),
254 : ObjectFile(_filename, _len, _data, _arch, _opSys),
257 _programHeaderTable(0), _programHeaderSize(0), _programHeaderCount(0)
258
259{
260 Elf *elf;
261 GElf_Ehdr ehdr;
262
263 // check that header matches library version
264 if (elf_version(EV_CURRENT) == EV_NONE)
265 panic("wrong elf version number!");
266
267 // get a pointer to elf structure
268 elf = elf_memory((char*)fileData,len);
255 _programHeaderTable(0), _programHeaderSize(0), _programHeaderCount(0)
256
257{
258 Elf *elf;
259 GElf_Ehdr ehdr;
260
261 // check that header matches library version
262 if (elf_version(EV_CURRENT) == EV_NONE)
263 panic("wrong elf version number!");
264
265 // get a pointer to elf structure
266 elf = elf_memory((char*)fileData,len);
269 // will only fail if fd is invalid
270 assert(elf != NULL);
271
272 // Check that we actually have a elf file
273 if (gelf_getehdr(elf, &ehdr) ==0) {
274 panic("Not ELF, shouldn't be here");
275 }
276
277 entry = ehdr.e_entry;

--- 238 unchanged lines hidden ---
267 assert(elf != NULL);
268
269 // Check that we actually have a elf file
270 if (gelf_getehdr(elf, &ehdr) ==0) {
271 panic("Not ELF, shouldn't be here");
272 }
273
274 entry = ehdr.e_entry;

--- 238 unchanged lines hidden ---