elf_object.hh revision 8229
14202Sbinkertn@umich.edu/* 24202Sbinkertn@umich.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan 34202Sbinkertn@umich.edu * All rights reserved. 44202Sbinkertn@umich.edu * 54202Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without 64202Sbinkertn@umich.edu * modification, are permitted provided that the following conditions are 74202Sbinkertn@umich.edu * met: redistributions of source code must retain the above copyright 84202Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer; 94202Sbinkertn@umich.edu * redistributions in binary form must reproduce the above copyright 104202Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer in the 114202Sbinkertn@umich.edu * documentation and/or other materials provided with the distribution; 124202Sbinkertn@umich.edu * neither the name of the copyright holders nor the names of its 134202Sbinkertn@umich.edu * contributors may be used to endorse or promote products derived from 144202Sbinkertn@umich.edu * this software without specific prior written permission. 154202Sbinkertn@umich.edu * 164202Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174202Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184202Sbinkertn@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194202Sbinkertn@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204202Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214202Sbinkertn@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224202Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234202Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244202Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254202Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264202Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274202Sbinkertn@umich.edu * 284202Sbinkertn@umich.edu * Authors: Steve Reinhardt 294202Sbinkertn@umich.edu */ 304202Sbinkertn@umich.edu 314202Sbinkertn@umich.edu#ifndef __ELF_OBJECT_HH__ 324202Sbinkertn@umich.edu#define __ELF_OBJECT_HH__ 334486Sbinkertn@umich.edu 344486Sbinkertn@umich.edu#include <set> 356165Ssanchezd@stanford.edu#include <vector> 364486Sbinkertn@umich.edu 376168Snate@binkert.org#include "base/loader/object_file.hh" 384202Sbinkertn@umich.edu 394202Sbinkertn@umich.educlass ElfObject : public ObjectFile 404202Sbinkertn@umich.edu{ 414202Sbinkertn@umich.edu protected: 424202Sbinkertn@umich.edu 434202Sbinkertn@umich.edu //The global definition of a "Section" is closest to elf's segments. 444202Sbinkertn@umich.edu typedef ObjectFile::Section Segment; 454202Sbinkertn@umich.edu 465650Sgblack@eecs.umich.edu //These values are provided to a linux process by the kernel, so we 476168Snate@binkert.org //need to keep them around. 484202Sbinkertn@umich.edu Addr _programHeaderTable; 494202Sbinkertn@umich.edu uint16_t _programHeaderSize; 504202Sbinkertn@umich.edu uint16_t _programHeaderCount; 514202Sbinkertn@umich.edu std::set<std::string> sectionNames; 524202Sbinkertn@umich.edu 535192Ssaidi@eecs.umich.edu /// Helper functions for loadGlobalSymbols() and loadLocalSymbols(). 545192Ssaidi@eecs.umich.edu bool loadSomeSymbols(SymbolTable *symtab, int binding, Addr mask); 555192Ssaidi@eecs.umich.edu 565192Ssaidi@eecs.umich.edu ElfObject(const std::string &_filename, int _fd, 575192Ssaidi@eecs.umich.edu size_t _len, uint8_t *_data, 585192Ssaidi@eecs.umich.edu Arch _arch, OpSys _opSys); 595192Ssaidi@eecs.umich.edu 606765SBrad.Beckmann@amd.com void getSections(); 61 bool sectionExists(std::string sec); 62 63 std::vector<Segment> extraSegments; 64 65 public: 66 virtual ~ElfObject() {} 67 68 bool loadSections(Port *memPort, 69 Addr addrMask = std::numeric_limits<Addr>::max()); 70 virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr addrMask = 71 std::numeric_limits<Addr>::max()); 72 virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask = 73 std::numeric_limits<Addr>::max()); 74 75 virtual bool isDynamic() { return sectionExists(".interp"); } 76 virtual bool hasTLS() { return sectionExists(".tbss"); } 77 78 static ObjectFile *tryFile(const std::string &fname, int fd, 79 size_t len, uint8_t *data); 80 Addr programHeaderTable() {return _programHeaderTable;} 81 uint16_t programHeaderSize() {return _programHeaderSize;} 82 uint16_t programHeaderCount() {return _programHeaderCount;} 83}; 84 85#endif // __ELF_OBJECT_HH__ 86