Mercurial > hg > graal-compiler
comparison src/share/vm/utilities/elfSymbolTable.cpp @ 14909:4ca6dc0799b6
Backout jdk9 merge
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Tue, 01 Apr 2014 13:57:07 +0200 |
parents | e7cbc95179c4 |
children | 52b4284cb496 |
comparison
equal
deleted
inserted
replaced
14908:8db6e76cb658 | 14909:4ca6dc0799b6 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
25 #include "precompiled.hpp" | 25 #include "precompiled.hpp" |
26 | 26 |
27 #if !defined(_WINDOWS) && !defined(__APPLE__) | 27 #if !defined(_WINDOWS) && !defined(__APPLE__) |
28 | 28 |
29 #include "memory/allocation.inline.hpp" | 29 #include "memory/allocation.inline.hpp" |
30 #include "utilities/elfFuncDescTable.hpp" | |
31 #include "utilities/elfSymbolTable.hpp" | 30 #include "utilities/elfSymbolTable.hpp" |
32 | 31 |
33 ElfSymbolTable::ElfSymbolTable(FILE* file, Elf_Shdr shdr) { | 32 ElfSymbolTable::ElfSymbolTable(FILE* file, Elf_Shdr shdr) { |
34 assert(file, "null file handle"); | 33 assert(file, "null file handle"); |
35 m_symbols = NULL; | 34 m_symbols = NULL; |
67 if (m_next != NULL) { | 66 if (m_next != NULL) { |
68 delete m_next; | 67 delete m_next; |
69 } | 68 } |
70 } | 69 } |
71 | 70 |
72 bool ElfSymbolTable::lookup(address addr, int* stringtableIndex, int* posIndex, int* offset, ElfFuncDescTable* funcDescTable) { | 71 bool ElfSymbolTable::lookup(address addr, int* stringtableIndex, int* posIndex, int* offset) { |
73 assert(stringtableIndex, "null string table index pointer"); | 72 assert(stringtableIndex, "null string table index pointer"); |
74 assert(posIndex, "null string table offset pointer"); | 73 assert(posIndex, "null string table offset pointer"); |
75 assert(offset, "null offset pointer"); | 74 assert(offset, "null offset pointer"); |
76 | 75 |
77 if (NullDecoder::is_error(m_status)) { | 76 if (NullDecoder::is_error(m_status)) { |
78 return false; | 77 return false; |
79 } | 78 } |
80 | 79 |
80 address pc = 0; | |
81 size_t sym_size = sizeof(Elf_Sym); | 81 size_t sym_size = sizeof(Elf_Sym); |
82 assert((m_shdr.sh_size % sym_size) == 0, "check size"); | 82 assert((m_shdr.sh_size % sym_size) == 0, "check size"); |
83 int count = m_shdr.sh_size / sym_size; | 83 int count = m_shdr.sh_size / sym_size; |
84 if (m_symbols != NULL) { | 84 if (m_symbols != NULL) { |
85 for (int index = 0; index < count; index ++) { | 85 for (int index = 0; index < count; index ++) { |
86 if (STT_FUNC == ELF_ST_TYPE(m_symbols[index].st_info)) { | 86 if (STT_FUNC == ELF_ST_TYPE(m_symbols[index].st_info)) { |
87 Elf_Word st_size = m_symbols[index].st_size; | 87 address sym_addr = (address)m_symbols[index].st_value; |
88 address sym_addr; | 88 if (sym_addr < addr && (addr - sym_addr) < *offset) { |
89 if (funcDescTable != NULL && funcDescTable->get_index() == m_symbols[index].st_shndx) { | 89 pc = (address)m_symbols[index].st_value; |
90 // We need to go another step trough the function descriptor table (currently PPC64 only) | 90 *offset = (int)(addr - pc); |
91 sym_addr = funcDescTable->lookup(m_symbols[index].st_value); | |
92 } else { | |
93 sym_addr = (address)m_symbols[index].st_value; | |
94 } | |
95 if (sym_addr <= addr && (Elf_Word)(addr - sym_addr) < st_size) { | |
96 *offset = (int)(addr - sym_addr); | |
97 *posIndex = m_symbols[index].st_name; | 91 *posIndex = m_symbols[index].st_name; |
98 *stringtableIndex = m_shdr.sh_link; | 92 *stringtableIndex = m_shdr.sh_link; |
99 return true; | |
100 } | 93 } |
101 } | 94 } |
102 } | 95 } |
103 } else { | 96 } else { |
104 long cur_pos; | 97 long cur_pos; |
110 | 103 |
111 Elf_Sym sym; | 104 Elf_Sym sym; |
112 for (int index = 0; index < count; index ++) { | 105 for (int index = 0; index < count; index ++) { |
113 if (fread(&sym, sym_size, 1, m_file) == 1) { | 106 if (fread(&sym, sym_size, 1, m_file) == 1) { |
114 if (STT_FUNC == ELF_ST_TYPE(sym.st_info)) { | 107 if (STT_FUNC == ELF_ST_TYPE(sym.st_info)) { |
115 Elf_Word st_size = sym.st_size; | 108 address sym_addr = (address)sym.st_value; |
116 address sym_addr; | 109 if (sym_addr < addr && (addr - sym_addr) < *offset) { |
117 if (funcDescTable != NULL && funcDescTable->get_index() == sym.st_shndx) { | 110 pc = (address)sym.st_value; |
118 // We need to go another step trough the function descriptor table (currently PPC64 only) | 111 *offset = (int)(addr - pc); |
119 sym_addr = funcDescTable->lookup(sym.st_value); | |
120 } else { | |
121 sym_addr = (address)sym.st_value; | |
122 } | |
123 if (sym_addr <= addr && (Elf_Word)(addr - sym_addr) < st_size) { | |
124 *offset = (int)(addr - sym_addr); | |
125 *posIndex = sym.st_name; | 112 *posIndex = sym.st_name; |
126 *stringtableIndex = m_shdr.sh_link; | 113 *stringtableIndex = m_shdr.sh_link; |
127 return true; | |
128 } | 114 } |
129 } | 115 } |
130 } else { | 116 } else { |
131 m_status = NullDecoder::file_invalid; | 117 m_status = NullDecoder::file_invalid; |
132 return false; | 118 return false; |
135 fseek(m_file, cur_pos, SEEK_SET); | 121 fseek(m_file, cur_pos, SEEK_SET); |
136 } | 122 } |
137 return true; | 123 return true; |
138 } | 124 } |
139 | 125 |
140 #endif // !_WINDOWS && !__APPLE__ | 126 #endif // _WINDOWS |