Bug 629275 - Recent nightly kills Win7 Taskbar Jumplists/Tasks. r=rstrong, a=blocking...
[mozilla-central.git] / tools / reorder / elf_symbol_table.h
blobbdda0ed22445c45671ac97abf4adce5f15e74ac3
1 /* -*- Mode: C++ -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is ``elf_symbol_table''
17 * The Initial Developer of the Original Code is Netscape
18 * Communications Corp. Portions created by the Initial Developer are
19 * Copyright (C) 2001 the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Chris Waterson <waterson@netscape.com>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef elf_symbol_table_h__
39 #define elf_symbol_table_h__
43 Utility class for reading ELF symbol tables.
47 #include <elf.h>
48 #include <sys/mman.h>
50 #include "interval_map.h"
52 class elf_symbol_table {
53 protected:
54 int m_fd;
55 void *m_mapping;
56 size_t m_size;
57 const char *m_strtab;
58 const Elf32_Sym *m_symbols;
59 int m_nsymbols;
60 int m_text_shndx;
62 typedef interval_map<unsigned int, const Elf32_Sym *> rsymtab_t;
63 rsymtab_t m_rsymtab;
65 int verify_elf_header(const Elf32_Ehdr *hdr);
66 int finish();
68 public:
69 elf_symbol_table()
70 : m_fd(-1),
71 m_mapping(MAP_FAILED),
72 m_size(0),
73 m_strtab(0),
74 m_symbols(0),
75 m_nsymbols(0),
76 m_text_shndx(0) {}
78 ~elf_symbol_table() { finish(); }
80 /**
81 * Read the symbol table information from the specified file. (This will
82 * memory-map the file.)
84 * Currently, only symbols from the `.text' section are loaded.
86 int init(const char *file);
88 /**
89 * Determine what symbol the specified image address corresponds
90 * to. Addresses need not refer to a symbol's start address:
91 * symbol size information is used to reverse-map the address.
93 const Elf32_Sym *lookup(unsigned int addr) const;
95 /**
96 * Determine the symbol name for the specified symbol.
98 const char *get_symbol_name(const Elf32_Sym *sym) const;
101 * Return `true' if the specified symbol is a function.
103 bool is_function(const Elf32_Sym *sym) const {
104 return (sym->st_size > 0) &&
105 (ELF32_ST_TYPE(sym->st_info) == STT_FUNC) &&
106 (sym->st_shndx == m_text_shndx); }
108 typedef const Elf32_Sym *const_iterator;
110 const_iterator begin() const { return const_iterator(m_symbols); }
111 const_iterator end() const { return const_iterator(m_symbols + m_nsymbols); }
114 #endif // elf_symbol_table_h__