elf_object.hh revision 10880
112SN/A/* 210037SARM gem5 Developers * Copyright (c) 2013 ARM Limited 310037SARM gem5 Developers * All rights reserved 410037SARM gem5 Developers * 510037SARM gem5 Developers * The license below extends only to copyright in the software and shall 610037SARM gem5 Developers * not be construed as granting a license to any other intellectual 710037SARM gem5 Developers * property including but not limited to intellectual property relating 810037SARM gem5 Developers * to a hardware implementation of the functionality of the software 910037SARM gem5 Developers * licensed hereunder. You may use the software subject to the license 1010037SARM gem5 Developers * terms below provided that you ensure that this notice is replicated 1110037SARM gem5 Developers * unmodified and in its entirety in all distributions of the software, 1210037SARM gem5 Developers * modified or unmodified, in source code or in binary form. 1310037SARM gem5 Developers * 141762SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan 1512SN/A * All rights reserved. 1612SN/A * 1712SN/A * Redistribution and use in source and binary forms, with or without 1812SN/A * modification, are permitted provided that the following conditions are 1912SN/A * met: redistributions of source code must retain the above copyright 2012SN/A * notice, this list of conditions and the following disclaimer; 2112SN/A * redistributions in binary form must reproduce the above copyright 2212SN/A * notice, this list of conditions and the following disclaimer in the 2312SN/A * documentation and/or other materials provided with the distribution; 2412SN/A * neither the name of the copyright holders nor the names of its 2512SN/A * contributors may be used to endorse or promote products derived from 2612SN/A * this software without specific prior written permission. 2712SN/A * 2812SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2912SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3012SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3112SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3212SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3312SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3412SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3512SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3612SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3712SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3812SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665Ssaidi@eecs.umich.edu * 402665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 4112SN/A */ 4212SN/A 4312SN/A#ifndef __ELF_OBJECT_HH__ 4412SN/A#define __ELF_OBJECT_HH__ 4512SN/A 465070Ssaidi@eecs.umich.edu#include <set> 475090Sgblack@eecs.umich.edu#include <vector> 4812SN/A 498229Snate@binkert.org#include "base/loader/object_file.hh" 508229Snate@binkert.org 5112SN/Aclass ElfObject : public ObjectFile 5212SN/A{ 5312SN/A protected: 5412SN/A 555090Sgblack@eecs.umich.edu //The global definition of a "Section" is closest to elf's segments. 565090Sgblack@eecs.umich.edu typedef ObjectFile::Section Segment; 575090Sgblack@eecs.umich.edu 582976Sgblack@eecs.umich.edu //These values are provided to a linux process by the kernel, so we 592976Sgblack@eecs.umich.edu //need to keep them around. 602976Sgblack@eecs.umich.edu Addr _programHeaderTable; 612976Sgblack@eecs.umich.edu uint16_t _programHeaderSize; 622976Sgblack@eecs.umich.edu uint16_t _programHeaderCount; 635070Ssaidi@eecs.umich.edu std::set<std::string> sectionNames; 642976Sgblack@eecs.umich.edu 65468SN/A /// Helper functions for loadGlobalSymbols() and loadLocalSymbols(). 667581SAli.Saidi@arm.com bool loadSomeSymbols(SymbolTable *symtab, int binding, Addr mask); 67468SN/A 6810880SCurtis.Dunham@arm.com ElfObject(const std::string &_filename, size_t _len, uint8_t *_data, 69360SN/A Arch _arch, OpSys _opSys); 7012SN/A 715070Ssaidi@eecs.umich.edu void getSections(); 725070Ssaidi@eecs.umich.edu bool sectionExists(std::string sec); 735070Ssaidi@eecs.umich.edu 745090Sgblack@eecs.umich.edu std::vector<Segment> extraSegments; 755090Sgblack@eecs.umich.edu 7612SN/A public: 7712SN/A virtual ~ElfObject() {} 7812SN/A 798852Sandreas.hansson@arm.com bool loadSections(PortProxy& memProxy, 8010037SARM gem5 Developers Addr addrMask = std::numeric_limits<Addr>::max(), 8110037SARM gem5 Developers Addr offset = 0); 823812Ssaidi@eecs.umich.edu virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr addrMask = 833812Ssaidi@eecs.umich.edu std::numeric_limits<Addr>::max()); 843812Ssaidi@eecs.umich.edu virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask = 853812Ssaidi@eecs.umich.edu std::numeric_limits<Addr>::max()); 869641Sguodeyuan@tsinghua.org.cn virtual bool loadWeakSymbols(SymbolTable *symtab, Addr addrMask = 879641Sguodeyuan@tsinghua.org.cn std::numeric_limits<Addr>::max()); 8812SN/A 895070Ssaidi@eecs.umich.edu virtual bool isDynamic() { return sectionExists(".interp"); } 905070Ssaidi@eecs.umich.edu virtual bool hasTLS() { return sectionExists(".tbss"); } 913917Ssaidi@eecs.umich.edu 9210880SCurtis.Dunham@arm.com static ObjectFile *tryFile(const std::string &fname, 9312SN/A size_t len, uint8_t *data); 942976Sgblack@eecs.umich.edu Addr programHeaderTable() {return _programHeaderTable;} 952976Sgblack@eecs.umich.edu uint16_t programHeaderSize() {return _programHeaderSize;} 962976Sgblack@eecs.umich.edu uint16_t programHeaderCount() {return _programHeaderCount;} 9712SN/A}; 9812SN/A 9912SN/A#endif // __ELF_OBJECT_HH__ 100