src/hotspot/share/utilities/elfFile.hpp
author coleenp
Thu, 10 Jan 2019 15:13:51 -0500
changeset 53244 9807daeb47c4
parent 49364 601146c66cad
permissions -rw-r--r--
8216167: Update include guards to reflect correct directories Summary: Use script and some manual fixup to fix directores names in include guards. Reviewed-by: lfoltan, eosterlund, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49364
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     4
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     8
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    13
 * accompanied this code).
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    14
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    18
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    21
 * questions.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    22
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    23
 */
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49364
diff changeset
    25
#ifndef SHARE_UTILITIES_ELFFILE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49364
diff changeset
    26
#define SHARE_UTILITIES_ELFFILE_HPP
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    27
48988
c2cd23e1d9cb 8198275: AIX build broken after latest whitebox.cpp changes
mbaesken
parents: 48975
diff changeset
    28
#if !defined(_WINDOWS) && !defined(__APPLE__) && !defined(_AIX)
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    29
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7447
diff changeset
    30
#if defined(__OpenBSD__)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7447
diff changeset
    31
#include <sys/exec_elf.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7447
diff changeset
    32
#else
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    33
#include <elf.h>
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7447
diff changeset
    34
#endif
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    35
#include <stdio.h>
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    36
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    37
#ifdef _LP64
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    38
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    39
typedef Elf64_Half      Elf_Half;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    40
typedef Elf64_Word      Elf_Word;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    41
typedef Elf64_Off       Elf_Off;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    42
typedef Elf64_Addr      Elf_Addr;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    43
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    44
typedef Elf64_Ehdr      Elf_Ehdr;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    45
typedef Elf64_Shdr      Elf_Shdr;
15926
8e87d545195f 7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents: 13963
diff changeset
    46
typedef Elf64_Phdr      Elf_Phdr;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    47
typedef Elf64_Sym       Elf_Sym;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    48
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7447
diff changeset
    49
#if !defined(_ALLBSD_SOURCE) || defined(__APPLE__)
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    50
#define ELF_ST_TYPE ELF64_ST_TYPE
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7447
diff changeset
    51
#endif
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    52
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    53
#else
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    54
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    55
typedef Elf32_Half      Elf_Half;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    56
typedef Elf32_Word      Elf_Word;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    57
typedef Elf32_Off       Elf_Off;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    58
typedef Elf32_Addr      Elf_Addr;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    59
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    60
typedef Elf32_Ehdr      Elf_Ehdr;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    61
typedef Elf32_Shdr      Elf_Shdr;
15926
8e87d545195f 7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents: 13963
diff changeset
    62
typedef Elf32_Phdr      Elf_Phdr;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    63
typedef Elf32_Sym       Elf_Sym;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    64
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7447
diff changeset
    65
#if !defined(_ALLBSD_SOURCE) || defined(__APPLE__)
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    66
#define ELF_ST_TYPE ELF32_ST_TYPE
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    67
#endif
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7447
diff changeset
    68
#endif
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    69
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    70
#include "globalDefinitions.hpp"
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    71
#include "memory/allocation.hpp"
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    72
#include "utilities/decoder.hpp"
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    73
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    74
class ElfStringTable;
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    75
class ElfSymbolTable;
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 15926
diff changeset
    76
class ElfFuncDescTable;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    77
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    78
// ELF section, may or may not have cached data
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 48988
diff changeset
    79
class ElfSection {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    80
private:
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    81
  Elf_Shdr      _section_hdr;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    82
  void*         _section_data;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    83
  NullDecoder::decoder_status _stat;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    84
public:
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    85
  ElfSection(FILE* fd, const Elf_Shdr& hdr);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    86
  ~ElfSection();
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    87
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    88
  NullDecoder::decoder_status status() const { return _stat; }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    89
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    90
  const Elf_Shdr* section_header() const { return &_section_hdr; }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    91
  const void*     section_data()   const { return (const void*)_section_data; }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    92
private:
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    93
  // load this section.
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    94
  // it return no_error, when it fails to cache the section data due to lack of memory
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    95
  NullDecoder::decoder_status load_section(FILE* const file, const Elf_Shdr& hdr);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    96
};
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    97
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    98
class FileReader : public StackObj {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    99
protected:
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   100
  FILE* const _fd;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   101
public:
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   102
  FileReader(FILE* const fd) : _fd(fd) {};
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   103
  bool read(void* buf, size_t size);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   104
  int  read_buffer(void* buf, size_t size);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   105
  bool set_position(long offset);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   106
};
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   107
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   108
// Mark current position, so we can get back to it after
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   109
// reads.
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   110
class MarkedFileReader : public FileReader {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   111
private:
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   112
  long  _marked_pos;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   113
public:
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   114
  MarkedFileReader(FILE* const fd);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   115
  ~MarkedFileReader();
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   116
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   117
  bool has_mark() const { return _marked_pos >= 0; }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   118
};
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   119
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   120
// ElfFile is basically an elf file parser, which can lookup the symbol
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   121
// that is the nearest to the given address.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   122
// Beware, this code is called from vm error reporting code, when vm is already
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   123
// in "error" state, so there are scenarios, lookup will fail. We want this
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   124
// part of code to be very defensive, and bait out if anything went wrong.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11483
diff changeset
   125
class ElfFile: public CHeapObj<mtInternal> {
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   126
  friend class ElfDecoder;
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   127
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   128
private:
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   129
  // link ElfFiles
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   130
  ElfFile*          _next;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   131
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   132
  // Elf file
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   133
  char*             _filepath;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   134
  FILE*             _file;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   135
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   136
  // Elf header
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   137
  Elf_Ehdr          _elfHdr;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   138
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   139
  // symbol tables
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   140
  ElfSymbolTable*   _symbol_tables;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   141
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   142
  // regular string tables
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   143
  ElfStringTable*   _string_tables;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   144
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   145
  // section header string table, used for finding section name
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   146
  ElfStringTable*   _shdr_string_table;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   147
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   148
  // function descriptors table
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   149
  ElfFuncDescTable* _funcDesc_table;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   150
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   151
  NullDecoder::decoder_status  _status;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   152
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   153
public:
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   154
  ElfFile(const char* filepath);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   155
  ~ElfFile();
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   156
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   157
  bool decode(address addr, char* buf, int buflen, int* offset);
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   158
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   159
  const char* filepath() const {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   160
    return _filepath;
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   161
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   162
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   163
  bool same_elf_file(const char* filepath) const {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   164
    assert(filepath != NULL, "null file path");
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   165
    return (_filepath != NULL && !strcmp(filepath, _filepath));
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   166
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   167
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   168
  NullDecoder::decoder_status get_status() const {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   169
    return _status;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   170
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   171
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   172
  // Returns true if the elf file is marked NOT to require an executable stack,
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   173
  // or if the file could not be opened.
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   174
  // Returns false if the elf file requires an executable stack, the stack flag
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   175
  // is not set at all, or if the file can not be read.
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   176
  // On systems other than linux it always returns false.
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   177
  static bool specifies_noexecstack(const char* filepath) NOT_LINUX({ return false; });
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   178
private:
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   179
  // sanity check, if the file is a real elf file
46629
8eeacdc76bf2 8183262: noexecstack check in os::dll_load on Linux is too expensive
kvn
parents: 22872
diff changeset
   180
  static bool is_elf_file(Elf_Ehdr&);
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   181
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   182
  // parse this elf file
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   183
  NullDecoder::decoder_status parse_elf(const char* filename);
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   184
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   185
  // load string, symbol and function descriptor tables from the elf file
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   186
  NullDecoder::decoder_status load_tables();
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   187
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   188
  ElfFile*  next() const { return _next; }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   189
  void set_next(ElfFile* file) { _next = file; }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   190
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   191
  // find a section by name, return section index
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   192
  // if there is no such section, return -1
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   193
  int section_by_name(const char* name, Elf_Shdr& hdr);
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   194
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   195
  // string tables are stored in a linked list
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   196
  void add_string_table(ElfStringTable* table);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   197
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   198
  // symbol tables are stored in a linked list
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   199
  void add_symbol_table(ElfSymbolTable* table);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   200
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   201
  // return a string table at specified section index
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   202
  ElfStringTable* get_string_table(int index);
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   203
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   204
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   205
  FILE* const fd() const { return _file; }
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   206
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   207
  // Cleanup string, symbol and function descriptor tables
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   208
  void cleanup_tables();
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   209
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   210
public:
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   211
  // For whitebox test
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
   212
  static bool _do_not_cache_elf_section;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   213
};
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   214
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents: 15926
diff changeset
   215
#endif // !_WINDOWS && !__APPLE__
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   216
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49364
diff changeset
   217
#endif // SHARE_UTILITIES_ELFFILE_HPP