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:
5411906SBrandon.Potter@amd.com    // The global definition of a gem5 "Section" is closest to ELF's segments.
555090Sgblack@eecs.umich.edu    typedef ObjectFile::Section Segment;
565090Sgblack@eecs.umich.edu
5711906SBrandon.Potter@amd.com    // These values are provided to a linux process by the kernel, so we
5811906SBrandon.Potter@amd.com    // need to keep them around.
592976Sgblack@eecs.umich.edu    Addr _programHeaderTable;
602976Sgblack@eecs.umich.edu    uint16_t _programHeaderSize;
612976Sgblack@eecs.umich.edu    uint16_t _programHeaderCount;
625070Ssaidi@eecs.umich.edu    std::set<std::string> sectionNames;
632976Sgblack@eecs.umich.edu
6411389Sbrandon.potter@amd.com    ElfObject *interpreter;
6511389Sbrandon.potter@amd.com
6611389Sbrandon.potter@amd.com    // An interpreter load bias is the location in the process address space
6711389Sbrandon.potter@amd.com    // where the interpreter is chosen to reside. Typically, this is carved
6811389Sbrandon.potter@amd.com    // out of the top of the mmap reserve section.
6911389Sbrandon.potter@amd.com    Addr ldBias;
7011389Sbrandon.potter@amd.com
7111389Sbrandon.potter@amd.com    // The interpreter is typically a relocatable shared library and will
7211389Sbrandon.potter@amd.com    // have a default value of zero which means that it does not care where
7311389Sbrandon.potter@amd.com    // it is placed. However, the loader can be compiled and linked so that
7411389Sbrandon.potter@amd.com    // it does care and needs a specific entry point.
7511389Sbrandon.potter@amd.com    bool relocate;
7611389Sbrandon.potter@amd.com
7711389Sbrandon.potter@amd.com    // The ldMin and ldMax fields are required to know how large of an
7811389Sbrandon.potter@amd.com    // area is required to map the interpreter.
7911389Sbrandon.potter@amd.com    Addr ldMin;
8011389Sbrandon.potter@amd.com    Addr ldMax;
8111389Sbrandon.potter@amd.com
82468SN/A    /// Helper functions for loadGlobalSymbols() and loadLocalSymbols().
8311392Sbrandon.potter@amd.com    bool loadSomeSymbols(SymbolTable *symtab, int binding, Addr mask,
8411392Sbrandon.potter@amd.com                         Addr base, Addr offset);
85468SN/A
8610880SCurtis.Dunham@arm.com    ElfObject(const std::string &_filename, size_t _len, uint8_t *_data,
87360SN/A              Arch _arch, OpSys _opSys);
8812SN/A
895070Ssaidi@eecs.umich.edu    void getSections();
905070Ssaidi@eecs.umich.edu    bool sectionExists(std::string sec);
915070Ssaidi@eecs.umich.edu
925090Sgblack@eecs.umich.edu    std::vector<Segment> extraSegments;
935090Sgblack@eecs.umich.edu
9412SN/A  public:
9512SN/A    virtual ~ElfObject() {}
9612SN/A
9714017Sbrandon.potter@amd.com    bool loadSections(const PortProxy& mem_proxy, Addr addr_mask = maxAddr,
9811392Sbrandon.potter@amd.com                      Addr offset = 0) override;
9911392Sbrandon.potter@amd.com
10011392Sbrandon.potter@amd.com    virtual bool loadAllSymbols(SymbolTable *symtab, Addr base = 0,
10111392Sbrandon.potter@amd.com                                Addr offset = 0, Addr addr_mask = maxAddr)
10211392Sbrandon.potter@amd.com                                override;
10311392Sbrandon.potter@amd.com
10411392Sbrandon.potter@amd.com    virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr base = 0,
10511392Sbrandon.potter@amd.com                                   Addr offset = 0, Addr addr_mask = maxAddr)
10611392Sbrandon.potter@amd.com                                   override;
10711392Sbrandon.potter@amd.com
10811392Sbrandon.potter@amd.com    virtual bool loadLocalSymbols(SymbolTable *symtab, Addr base = 0,
10911392Sbrandon.potter@amd.com                                  Addr offset = 0, Addr addr_mask = maxAddr)
11011392Sbrandon.potter@amd.com                                  override;
11111392Sbrandon.potter@amd.com
11211392Sbrandon.potter@amd.com    virtual bool loadWeakSymbols(SymbolTable *symtab, Addr base = 0,
11311392Sbrandon.potter@amd.com                                 Addr offset = 0, Addr addr_mask = maxAddr)
11411392Sbrandon.potter@amd.com                                 override;
11511392Sbrandon.potter@amd.com
11612SN/A
11711389Sbrandon.potter@amd.com    virtual ObjectFile *getInterpreter() const override
11811389Sbrandon.potter@amd.com    { return interpreter; }
11911389Sbrandon.potter@amd.com    virtual Addr bias() const override { return ldBias; }
12011389Sbrandon.potter@amd.com    virtual bool relocatable() const override { return relocate; }
12111389Sbrandon.potter@amd.com    virtual Addr mapSize() const override { return ldMax - ldMin; }
12211389Sbrandon.potter@amd.com    virtual void updateBias(Addr bias_addr) override;
12311389Sbrandon.potter@amd.com
12411389Sbrandon.potter@amd.com    virtual bool hasTLS() override { return sectionExists(".tbss"); }
1253917Ssaidi@eecs.umich.edu
12610880SCurtis.Dunham@arm.com    static ObjectFile *tryFile(const std::string &fname,
12711389Sbrandon.potter@amd.com                               size_t len, uint8_t *data,
12811389Sbrandon.potter@amd.com                               bool skip_interp_check = false);
1292976Sgblack@eecs.umich.edu    Addr programHeaderTable() {return _programHeaderTable;}
1302976Sgblack@eecs.umich.edu    uint16_t programHeaderSize() {return _programHeaderSize;}
1312976Sgblack@eecs.umich.edu    uint16_t programHeaderCount() {return _programHeaderCount;}
13212SN/A};
13312SN/A
13412SN/A#endif // __ELF_OBJECT_HH__
135