src/hotspot/share/utilities/elfFuncDescTable.cpp
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 51334 cc2c79d22508
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
     1
/*
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
35594
cc13089c6327 8147937: Adapt SAP copyrights to new company name.
goetz
parents: 22857
diff changeset
     3
 * Copyright (c) 2012, 2013 SAP SE. All rights reserved.
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
     5
 *
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
     8
 * published by the Free Software Foundation.
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
     9
 *
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    14
 * accompanied this code).
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    15
 *
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    19
 *
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    22
 * questions.
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    23
 *
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    24
 */
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    25
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    26
#include "precompiled.hpp"
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    27
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    28
#if !defined(_WINDOWS) && !defined(__APPLE__)
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    29
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    30
#include "memory/allocation.inline.hpp"
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    31
#include "utilities/elfFuncDescTable.hpp"
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    32
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    33
ElfFuncDescTable::ElfFuncDescTable(FILE* file, Elf_Shdr shdr, int index) :
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 48975
diff changeset
    34
  _section(file, shdr), _file(file), _index(index) {
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    35
  assert(file, "null file handle");
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    36
  // The actual function address (i.e. function entry point) is always the
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    37
  // first value in the function descriptor (on IA64 and PPC64 they look as follows):
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    38
  // PPC64: [function entry point, TOC pointer, environment pointer]
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    39
  // IA64 : [function entry point, GP (global pointer) value]
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    40
  // Unfortunately 'shdr.sh_entsize' doesn't always seem to contain this size (it's zero on PPC64) so we can't assert
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    41
  // assert(IA64_ONLY(2) PPC64_ONLY(3) * sizeof(address) == shdr.sh_entsize, "Size mismatch for '.opd' section entries");
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    42
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    43
  _status = _section.status();
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    44
}
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    45
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    46
ElfFuncDescTable::~ElfFuncDescTable() {
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    47
}
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    48
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    49
address ElfFuncDescTable::lookup(Elf_Word index) {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    50
  if (NullDecoder::is_error(_status)) {
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    51
    return NULL;
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    52
  }
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    53
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    54
  address*  func_descs = cached_func_descs();
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    55
  const Elf_Shdr* shdr = _section.section_header();
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    56
  if (!(shdr->sh_size > 0 && shdr->sh_addr <= index && index <= shdr->sh_addr + shdr->sh_size)) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    57
    // don't put the whole decoder in error mode if we just tried a wrong index
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    58
    return NULL;
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    59
  }
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    60
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    61
  if (func_descs != NULL) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    62
    return func_descs[(index - shdr->sh_addr) / sizeof(address)];
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    63
  } else {
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    64
    MarkedFileReader mfd(_file);
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    65
    address addr;
48975
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    66
    if (!mfd.has_mark() ||
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    67
        !mfd.set_position(shdr->sh_offset + index - shdr->sh_addr) ||
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    68
        !mfd.read((void*)&addr, sizeof(addr))) {
2c35fd3c5789 8193373: Cleanup ElfFile and family
zgu
parents: 47216
diff changeset
    69
      _status = NullDecoder::file_invalid;
22857
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    70
      return NULL;
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    71
    }
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    72
    return addr;
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    73
  }
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    74
}
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    75
2167396cfc83 8019929: PPC64 (part 107): Extend ELF-decoder to support PPC64 function descriptor tables
simonis
parents:
diff changeset
    76
#endif // !_WINDOWS && !__APPLE__