Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/elfFuncDescTable.hpp
32285 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* Copyright 2012, 2013 SAP AG. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#ifndef SHARE_VM_UTILITIES_ELF_FUNC_DESC_TABLE_HPP26#define SHARE_VM_UTILITIES_ELF_FUNC_DESC_TABLE_HPP2728#if !defined(_WINDOWS) && !defined(__APPLE__)293031#include "memory/allocation.hpp"32#include "utilities/decoder.hpp"33#include "utilities/elfFile.hpp"3435/*3637On PowerPC-64 (and other architectures like for example IA64) a pointer to a38function is not just a plain code address, but instead a pointer to a so called39function descriptor (which is simply a structure containing 3 pointers).40This fact is also reflected in the ELF ABI for PowerPC-64.4142On architectures like x86 or SPARC, the ELF symbol table contains the start43address and size of an object. So for example for a function object (i.e. type44'STT_FUNC') the symbol table's 'st_value' and 'st_size' fields directly45represent the starting address and size of that function. On PPC64 however, the46symbol table's 'st_value' field only contains an index into another, PPC6447specific '.opd' (official procedure descriptors) section, while the 'st_size'48field still holds the size of the corresponding function. In order to get the49actual start address of a function, it is necessary to read the corresponding50function descriptor entry in the '.opd' section at the corresponding index and51extract the start address from there.5253That's exactly what this 'ElfFuncDescTable' class is used for. If the HotSpot54runs on a PPC64 machine, and the corresponding ELF files contains an '.opd'55section (which is actually mandatory on PPC64) it will be read into an object56of type 'ElfFuncDescTable' just like the string and symbol table sections.57Later on, during symbol lookup in 'ElfSymbolTable::lookup()' this function58descriptor table will be used if available to find the real function address.5960All this is how things work today (2013) on contemporary Linux distributions61(i.e. SLES 10) and new version of GCC (i.e. > 4.0). However there is a history,62and it goes like this:6364In SLES 9 times (sometimes before GCC 3.4) gcc/ld on PPC64 generated two65entries in the symbol table for every function. The value of the symbol with66the name of the function was the address of the function descriptor while the67dot '.' prefixed name was reserved to hold the actual address of that function68(http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html#FUNC-DES).6970For a C-function 'foo' this resulted in two symbol table entries like this71(extracted from the output of 'readelf -a <lib.so>'):7273Section Headers:74[ 9] .text PROGBITS 0000000000000a20 00000a207500000000000005a0 0000000000000000 AX 0 0 1676[21] .opd PROGBITS 00000000000113b8 000013b8770000000000000138 0000000000000000 WA 0 0 87879Symbol table '.symtab' contains 86 entries:80Num: Value Size Type Bind Vis Ndx Name8176: 00000000000114c0 24 FUNC GLOBAL DEFAULT 21 foo8278: 0000000000000bb0 76 FUNC GLOBAL DEFAULT 9 .foo8384You can see now that the '.foo' entry actually points into the '.text' segment85('Ndx'=9) and its value and size fields represent the functions actual address86and size. On the other hand, the entry for plain 'foo' points into the '.opd'87section ('Ndx'=21) and its value and size fields are the index into the '.opd'88section and the size of the corresponding '.opd' section entry (3 pointers on89PPC64).9091These so called 'dot symbols' were dropped around gcc 3.4 from GCC and BINUTILS,92see http://gcc.gnu.org/ml/gcc-patches/2004-08/msg00557.html.93But nevertheless it may still be necessary to support both formats because we94either run on an old system or because it is possible at any time that functions95appear in the stack trace which come from old-style libraries.9697Therefore we not only have to check for the presence of the function descriptor98table during symbol lookup in 'ElfSymbolTable::lookup()'. We additionally have99to check that the symbol table entry references the '.opd' section. Only in100that case we can resolve the actual function address from there. Otherwise we101use the plain 'st_value' field from the symbol table as function address. This102way we can also lookup the symbols in old-style ELF libraries (although we get103the 'dotted' versions in that case). However, if present, the 'dot' will be104conditionally removed on PPC64 from the symbol in 'ElfDecoder::demangle()' in105decoder_linux.cpp.106107Notice that we can not reliably get the function address from old-style108libraries because the 'st_value' field of the symbol table entries which point109into the '.opd' section denote the size of the corresponding '.opd' entry and110not that of the corresponding function. This has changed for the symbol table111entries in new-style libraries as described at the beginning of this112documentation.113114*/115116class ElfFuncDescTable: public CHeapObj<mtInternal> {117friend class ElfFile;118public:119ElfFuncDescTable(FILE* file, Elf_Shdr shdr, int index);120~ElfFuncDescTable();121122// return the function address for the function descriptor at 'index' or NULL on error123address lookup(Elf_Word index);124125int get_index() { return m_index; };126127NullDecoder::decoder_status get_status() { return m_status; };128129protected:130// holds the complete function descriptor section if131// we can allocate enough memory132address* m_funcDescs;133134// file contains string table135FILE* m_file;136137// section header138Elf_Shdr m_shdr;139140// The section index of this function descriptor (i.e. '.opd') section in the ELF file141int m_index;142143NullDecoder::decoder_status m_status;144};145146#endif // !_WINDOWS && !__APPLE__147148#endif // SHARE_VM_UTILITIES_ELF_FUNC_DESC_TABLE_HPP149150151