(root)/
binutils-2.41/
gprofng/
src/
LoadObject.h
       1  /* Copyright (C) 2021-2023 Free Software Foundation, Inc.
       2     Contributed by Oracle.
       3  
       4     This file is part of GNU Binutils.
       5  
       6     This program is free software; you can redistribute it and/or modify
       7     it under the terms of the GNU General Public License as published by
       8     the Free Software Foundation; either version 3, or (at your option)
       9     any later version.
      10  
      11     This program is distributed in the hope that it will be useful,
      12     but WITHOUT ANY WARRANTY; without even the implied warranty of
      13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14     GNU General Public License for more details.
      15  
      16     You should have received a copy of the GNU General Public License
      17     along with this program; if not, write to the Free Software
      18     Foundation, 51 Franklin Street - Fifth Floor, Boston,
      19     MA 02110-1301, USA.  */
      20  
      21  #ifndef _LOADOBJECT_H
      22  #define _LOADOBJECT_H
      23  
      24  // A Segment object represents a segment of the program text.
      25  
      26  #include "Histable.h"
      27  #include "Stabs.h"
      28  #include "DbeLock.h"
      29  
      30  #define JAVA_COMPILED_METHODS   "JAVA_COMPILED_METHODS"
      31  #define DYNFUNC_SEGMENT         "DYNAMIC_FUNCTIONS"
      32  #define SEG_FLAG_DYNAMIC    0x01
      33  #define SEG_FLAG_JVM        0x02
      34  #define SEG_FLAG_OMP        0x04
      35  #define SEG_FLAG_EXE        0x08
      36  #define SEG_FLAG_REORDER    0x10
      37  
      38  /* Hash name for all comparable executions */
      39  #define COMP_EXE_NAME       "<COMP_EXE_NAME>"
      40  
      41  class Emsg;
      42  class Elf;
      43  class Experiment;
      44  class Function;
      45  class Module;
      46  template <typename Key_t, typename Value_t> class HashMap;
      47  template <typename Key_t, typename Value_t> class Map;
      48  template <class ITEM> class Vector;
      49  
      50  enum
      51  {
      52    CMP_PATH          = 1,
      53    CMP_RUNTIMEPATH   = 2,
      54    CMP_CHKSUM        = 4
      55  };
      56  
      57  class LoadObject : public HistableFile, public DbeLock
      58  {
      59  public:
      60  
      61    // The various segments types.
      62    enum seg_type
      63    {
      64      SEG_TEXT,
      65      SEG_DATA,
      66      SEG_BSS,
      67      SEG_HEAP,
      68      SEG_STACK,
      69      SEG_DEVICE,
      70      SEG_UNKNOWN
      71    };
      72  
      73    // These codes are stored in *.archive files
      74    enum Arch_status
      75    {
      76      ARCHIVE_SUCCESS,
      77      ARCHIVE_EXIST,
      78      ARCHIVE_BAD_STABS,
      79      ARCHIVE_ERR_SEG,
      80      ARCHIVE_ERR_OPEN,
      81      ARCHIVE_ERR_MAP,
      82      ARCHIVE_WARN_MTIME,
      83      ARCHIVE_WARN_HOST,
      84      ARCHIVE_ERR_VERSION,
      85      ARCHIVE_NO_STABS,
      86      ARCHIVE_WRONG_ARCH,
      87      ARCHIVE_NO_LIBDWARF,
      88      ARCHIVE_NO_DWARF,
      89      ARCHIVE_WARN_CHECKSUM
      90    };
      91  
      92    LoadObject (const char *loname);
      93  
      94    static LoadObject *create_item (const char *nm, int64_t chksum);
      95    static LoadObject *create_item (const char *nm, const char *_runTimePath, DbeFile *df);
      96  
      97    virtual ~LoadObject ();
      98    virtual void set_name (char *string);
      99    virtual uint64_t get_addr ();
     100    virtual Vector<Histable*> *get_comparable_objs ();
     101  
     102    virtual Histable_type
     103    get_type ()
     104    {
     105      return LOADOBJECT;
     106    };
     107  
     108    virtual int64_t
     109    get_size ()
     110    {
     111      return size;
     112    }
     113  
     114    char *
     115    get_pathname ()
     116    {
     117      return pathname;
     118    }
     119  
     120    void
     121    set_archname (char *aname)
     122    {
     123      free (arch_name);
     124      arch_name = aname;
     125    }
     126  
     127    bool
     128    is_relocatable ()
     129    {
     130      return isRelocatable;
     131    }
     132  
     133    bool compare (const char *nm, int64_t _checksum);
     134    int compare (const char *_path, const char *_runTimePath, DbeFile *df);
     135    void set_platform (Platform_t pltf, int wsz);
     136    void dump_functions (FILE *);
     137    int get_index (Function *func);
     138    char *get_alias (Function *func);
     139    DbeInstr *find_dbeinstr (uint64_t file_off);
     140    Function *find_function (uint64_t offset);
     141    Function *find_function (char *fname);
     142    Function *find_function (char *fname, unsigned int chksum);
     143    Module *find_module (char *mname);
     144    Module *get_comparable_Module (Module *mod);
     145    void append_module (Module *mod);
     146    Elf *get_elf ();
     147    Stabs *openDebugInfo (char *fname, Stabs::Stab_status *stp = NULL);
     148    Arch_status read_stabs ();
     149    Arch_status sync_read_stabs ();
     150    void post_process_functions ();
     151    char *status_str (Arch_status rv, char *arg = NULL);
     152    Function *get_hide_function ();
     153    DbeInstr *get_hide_instr (DbeInstr *instr);
     154    uint32_t get_checksum ();
     155  
     156    Emsg *
     157    fetch_warnings (void) // fetch the queue of warning messages
     158    {
     159      return warnq->fetch ();
     160    }
     161  
     162    Emsg *
     163    fetch_comments (void) // fetch the queue of comment messages
     164    {
     165      return commentq->fetch ();
     166    }
     167  
     168    unsigned int flags;           // SEG_FLAG_*
     169    bool isReadStabs;
     170    bool need_swap_endian;
     171    int seg_idx;                  // for compatibility (ADDRESS)
     172    seg_type type;
     173    int64_t size;                 // size of loadobject in bytes
     174    int64_t max_size;             // Maximum size of loadobject in bytes
     175    int64_t min_size;             // Min size of loadobject in bytes.
     176    Vector<Function*> *functions; // Ordered list of functions
     177    Vector<Module*> *seg_modules; // list of modules
     178    HashMap<char*, Module*> *modules;
     179    Module *noname;               // Module pointer to unknown name
     180    Platform_t platform;          // Sparc, Sparcv9, Intel
     181    WSize_t wsize;                // word size: 32,64
     182    Stabs *objStabs;
     183    HashMap<char*, Function*> *comp_funcs;    // list of comparable functions
     184    Experiment *firstExp;
     185    char *runTimePath;
     186    time_t mtime;                 // file timestamp (in seconds)
     187    int64_t checksum;             // file checksum
     188  
     189  private:
     190    Elf *elf_lo;
     191    bool elf_inited;
     192    DbeInstr **instHTable;        // hash table for DbeInstr
     193    char *pathname;               // User name of object file
     194    ino64_t inode;                // inode number of segment file
     195    bool isRelocatable;           // is relocatable .o
     196    char *arch_name;              // .archive name
     197    Emsgqueue *warnq;
     198    Emsgqueue *commentq;
     199    Function **funcHTable;        // hash table for functions
     200    Function *h_function;         // hide pseudo function
     201    DbeInstr *h_instr;            // hide pseudo instr
     202    HashMap<char*, Module*> *seg_modules_map; // to find a comparable module
     203  
     204    static int func_compare (const void *p1, const void *p2);
     205    int read_archive ();
     206    void init_datatypes ();
     207    void update_datatypes (Module*, Vaddr, uint32_t datatype_id);
     208  };
     209  
     210  #endif /* _LOADOBJECT_H */