elf_object.hh revision 8852
112SN/A/* 21762SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan 312SN/A * All rights reserved. 412SN/A * 512SN/A * Redistribution and use in source and binary forms, with or without 612SN/A * modification, are permitted provided that the following conditions are 712SN/A * met: redistributions of source code must retain the above copyright 812SN/A * notice, this list of conditions and the following disclaimer; 912SN/A * redistributions in binary form must reproduce the above copyright 1012SN/A * notice, this list of conditions and the following disclaimer in the 1112SN/A * documentation and/or other materials provided with the distribution; 1212SN/A * neither the name of the copyright holders nor the names of its 1312SN/A * contributors may be used to endorse or promote products derived from 1412SN/A * this software without specific prior written permission. 1512SN/A * 1612SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 2912SN/A */ 3012SN/A 3112SN/A#ifndef __ELF_OBJECT_HH__ 3212SN/A#define __ELF_OBJECT_HH__ 3312SN/A 345070Ssaidi@eecs.umich.edu#include <set> 355090Sgblack@eecs.umich.edu#include <vector> 3612SN/A 378229Snate@binkert.org#include "base/loader/object_file.hh" 388229Snate@binkert.org 3912SN/Aclass ElfObject : public ObjectFile 4012SN/A{ 4112SN/A protected: 4212SN/A 435090Sgblack@eecs.umich.edu //The global definition of a "Section" is closest to elf's segments. 445090Sgblack@eecs.umich.edu typedef ObjectFile::Section Segment; 455090Sgblack@eecs.umich.edu 462976Sgblack@eecs.umich.edu //These values are provided to a linux process by the kernel, so we 472976Sgblack@eecs.umich.edu //need to keep them around. 482976Sgblack@eecs.umich.edu Addr _programHeaderTable; 492976Sgblack@eecs.umich.edu uint16_t _programHeaderSize; 502976Sgblack@eecs.umich.edu uint16_t _programHeaderCount; 515070Ssaidi@eecs.umich.edu std::set<std::string> sectionNames; 522976Sgblack@eecs.umich.edu 53468SN/A /// Helper functions for loadGlobalSymbols() and loadLocalSymbols(). 547581SAli.Saidi@arm.com bool loadSomeSymbols(SymbolTable *symtab, int binding, Addr mask); 55468SN/A 5612SN/A ElfObject(const std::string &_filename, int _fd, 572479SN/A size_t _len, uint8_t *_data, 58360SN/A Arch _arch, OpSys _opSys); 5912SN/A 605070Ssaidi@eecs.umich.edu void getSections(); 615070Ssaidi@eecs.umich.edu bool sectionExists(std::string sec); 625070Ssaidi@eecs.umich.edu 635090Sgblack@eecs.umich.edu std::vector<Segment> extraSegments; 645090Sgblack@eecs.umich.edu 6512SN/A public: 6612SN/A virtual ~ElfObject() {} 6712SN/A 688852Sandreas.hansson@arm.com bool loadSections(PortProxy& memProxy, 695090Sgblack@eecs.umich.edu Addr addrMask = std::numeric_limits<Addr>::max()); 703812Ssaidi@eecs.umich.edu virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr addrMask = 713812Ssaidi@eecs.umich.edu std::numeric_limits<Addr>::max()); 723812Ssaidi@eecs.umich.edu virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask = 733812Ssaidi@eecs.umich.edu std::numeric_limits<Addr>::max()); 7412SN/A 755070Ssaidi@eecs.umich.edu virtual bool isDynamic() { return sectionExists(".interp"); } 765070Ssaidi@eecs.umich.edu virtual bool hasTLS() { return sectionExists(".tbss"); } 773917Ssaidi@eecs.umich.edu 7812SN/A static ObjectFile *tryFile(const std::string &fname, int fd, 7912SN/A size_t len, uint8_t *data); 802976Sgblack@eecs.umich.edu Addr programHeaderTable() {return _programHeaderTable;} 812976Sgblack@eecs.umich.edu uint16_t programHeaderSize() {return _programHeaderSize;} 822976Sgblack@eecs.umich.edu uint16_t programHeaderCount() {return _programHeaderCount;} 8312SN/A}; 8412SN/A 8512SN/A#endif // __ELF_OBJECT_HH__ 86