elf_object.hh revision 8229
112966SMatteo.Andreozzi@arm.com/*
212966SMatteo.Andreozzi@arm.com * Copyright (c) 2003-2005 The Regents of The University of Michigan
312966SMatteo.Andreozzi@arm.com * All rights reserved.
412966SMatteo.Andreozzi@arm.com *
512966SMatteo.Andreozzi@arm.com * Redistribution and use in source and binary forms, with or without
612966SMatteo.Andreozzi@arm.com * modification, are permitted provided that the following conditions are
712966SMatteo.Andreozzi@arm.com * met: redistributions of source code must retain the above copyright
812966SMatteo.Andreozzi@arm.com * notice, this list of conditions and the following disclaimer;
912966SMatteo.Andreozzi@arm.com * redistributions in binary form must reproduce the above copyright
1012966SMatteo.Andreozzi@arm.com * notice, this list of conditions and the following disclaimer in the
1112966SMatteo.Andreozzi@arm.com * documentation and/or other materials provided with the distribution;
1212966SMatteo.Andreozzi@arm.com * neither the name of the copyright holders nor the names of its
1312966SMatteo.Andreozzi@arm.com * contributors may be used to endorse or promote products derived from
1412966SMatteo.Andreozzi@arm.com * this software without specific prior written permission.
1512966SMatteo.Andreozzi@arm.com *
1612966SMatteo.Andreozzi@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712966SMatteo.Andreozzi@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812966SMatteo.Andreozzi@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912966SMatteo.Andreozzi@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012966SMatteo.Andreozzi@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112966SMatteo.Andreozzi@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212966SMatteo.Andreozzi@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312966SMatteo.Andreozzi@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412966SMatteo.Andreozzi@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512966SMatteo.Andreozzi@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612966SMatteo.Andreozzi@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712966SMatteo.Andreozzi@arm.com *
2812966SMatteo.Andreozzi@arm.com * Authors: Steve Reinhardt
2912966SMatteo.Andreozzi@arm.com */
3012966SMatteo.Andreozzi@arm.com
3112966SMatteo.Andreozzi@arm.com#ifndef __ELF_OBJECT_HH__
3212966SMatteo.Andreozzi@arm.com#define __ELF_OBJECT_HH__
3312966SMatteo.Andreozzi@arm.com
3412966SMatteo.Andreozzi@arm.com#include <set>
3512966SMatteo.Andreozzi@arm.com#include <vector>
3612966SMatteo.Andreozzi@arm.com
3712966SMatteo.Andreozzi@arm.com#include "base/loader/object_file.hh"
3812966SMatteo.Andreozzi@arm.com
3912966SMatteo.Andreozzi@arm.comclass ElfObject : public ObjectFile
4012966SMatteo.Andreozzi@arm.com{
4112966SMatteo.Andreozzi@arm.com  protected:
4212966SMatteo.Andreozzi@arm.com
4312966SMatteo.Andreozzi@arm.com    //The global definition of a "Section" is closest to elf's segments.
4412966SMatteo.Andreozzi@arm.com    typedef ObjectFile::Section Segment;
4512966SMatteo.Andreozzi@arm.com
4612966SMatteo.Andreozzi@arm.com    //These values are provided to a linux process by the kernel, so we
4712966SMatteo.Andreozzi@arm.com    //need to keep them around.
4812966SMatteo.Andreozzi@arm.com    Addr _programHeaderTable;
4912966SMatteo.Andreozzi@arm.com    uint16_t _programHeaderSize;
5012966SMatteo.Andreozzi@arm.com    uint16_t _programHeaderCount;
5112966SMatteo.Andreozzi@arm.com    std::set<std::string> sectionNames;
5212966SMatteo.Andreozzi@arm.com
5312966SMatteo.Andreozzi@arm.com    /// Helper functions for loadGlobalSymbols() and loadLocalSymbols().
5412966SMatteo.Andreozzi@arm.com    bool loadSomeSymbols(SymbolTable *symtab, int binding, Addr mask);
5512966SMatteo.Andreozzi@arm.com
5612966SMatteo.Andreozzi@arm.com    ElfObject(const std::string &_filename, int _fd,
5712966SMatteo.Andreozzi@arm.com              size_t _len, uint8_t *_data,
5812966SMatteo.Andreozzi@arm.com              Arch _arch, OpSys _opSys);
5912966SMatteo.Andreozzi@arm.com
6012966SMatteo.Andreozzi@arm.com    void getSections();
6112966SMatteo.Andreozzi@arm.com    bool sectionExists(std::string sec);
6212966SMatteo.Andreozzi@arm.com
6312966SMatteo.Andreozzi@arm.com    std::vector<Segment> extraSegments;
6412966SMatteo.Andreozzi@arm.com
6512966SMatteo.Andreozzi@arm.com  public:
6612966SMatteo.Andreozzi@arm.com    virtual ~ElfObject() {}
6712966SMatteo.Andreozzi@arm.com
6812966SMatteo.Andreozzi@arm.com    bool loadSections(Port *memPort,
6912966SMatteo.Andreozzi@arm.com            Addr addrMask = std::numeric_limits<Addr>::max());
7012966SMatteo.Andreozzi@arm.com    virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr addrMask =
7112966SMatteo.Andreozzi@arm.com            std::numeric_limits<Addr>::max());
7212966SMatteo.Andreozzi@arm.com    virtual bool loadLocalSymbols(SymbolTable *symtab, Addr addrMask =
7312966SMatteo.Andreozzi@arm.com            std::numeric_limits<Addr>::max());
7412966SMatteo.Andreozzi@arm.com
7512966SMatteo.Andreozzi@arm.com    virtual bool isDynamic() { return sectionExists(".interp"); }
7612966SMatteo.Andreozzi@arm.com    virtual bool hasTLS() { return sectionExists(".tbss"); }
7712966SMatteo.Andreozzi@arm.com
7812966SMatteo.Andreozzi@arm.com    static ObjectFile *tryFile(const std::string &fname, int fd,
7912966SMatteo.Andreozzi@arm.com                               size_t len, uint8_t *data);
8012966SMatteo.Andreozzi@arm.com    Addr programHeaderTable() {return _programHeaderTable;}
8112966SMatteo.Andreozzi@arm.com    uint16_t programHeaderSize() {return _programHeaderSize;}
82    uint16_t programHeaderCount() {return _programHeaderCount;}
83};
84
85#endif // __ELF_OBJECT_HH__
86