1 1.1 skrll /* Generic symbol-table support for the BFD library. 2 1.13 christos Copyright (C) 1990-2026 Free Software Foundation, Inc. 3 1.1 skrll Written by Cygnus Support. 4 1.1 skrll 5 1.1 skrll This file is part of BFD, the Binary File Descriptor library. 6 1.1 skrll 7 1.1 skrll This program is free software; you can redistribute it and/or modify 8 1.1 skrll it under the terms of the GNU General Public License as published by 9 1.1 skrll the Free Software Foundation; either version 3 of the License, or 10 1.1 skrll (at your option) any later version. 11 1.1 skrll 12 1.1 skrll This program is distributed in the hope that it will be useful, 13 1.1 skrll but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 skrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 skrll GNU General Public License for more details. 16 1.1 skrll 17 1.1 skrll You should have received a copy of the GNU General Public License 18 1.1 skrll along with this program; if not, write to the Free Software 19 1.1 skrll Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 20 1.1 skrll MA 02110-1301, USA. */ 21 1.1 skrll 22 1.1 skrll /* 23 1.1 skrll SECTION 24 1.1 skrll Symbols 25 1.1 skrll 26 1.1 skrll BFD tries to maintain as much symbol information as it can when 27 1.1 skrll it moves information from file to file. BFD passes information 28 1.1 skrll to applications though the <<asymbol>> structure. When the 29 1.1 skrll application requests the symbol table, BFD reads the table in 30 1.1 skrll the native form and translates parts of it into the internal 31 1.1 skrll format. To maintain more than the information passed to 32 1.1 skrll applications, some targets keep some information ``behind the 33 1.1 skrll scenes'' in a structure only the particular back end knows 34 1.1 skrll about. For example, the coff back end keeps the original 35 1.1 skrll symbol table structure as well as the canonical structure when 36 1.1 skrll a BFD is read in. On output, the coff back end can reconstruct 37 1.1 skrll the output symbol table so that no information is lost, even 38 1.1 skrll information unique to coff which BFD doesn't know or 39 1.1 skrll understand. If a coff symbol table were read, but were written 40 1.1 skrll through an a.out back end, all the coff specific information 41 1.1 skrll would be lost. The symbol table of a BFD 42 1.1 skrll is not necessarily read in until a canonicalize request is 43 1.1 skrll made. Then the BFD back end fills in a table provided by the 44 1.1 skrll application with pointers to the canonical information. To 45 1.1 skrll output symbols, the application provides BFD with a table of 46 1.1 skrll pointers to pointers to <<asymbol>>s. This allows applications 47 1.1 skrll like the linker to output a symbol as it was read, since the ``behind 48 1.1 skrll the scenes'' information will be still available. 49 1.1 skrll @menu 50 1.1 skrll @* Reading Symbols:: 51 1.1 skrll @* Writing Symbols:: 52 1.1 skrll @* Mini Symbols:: 53 1.1 skrll @* typedef asymbol:: 54 1.1 skrll @* symbol handling functions:: 55 1.1 skrll @end menu 56 1.1 skrll 57 1.1 skrll INODE 58 1.1 skrll Reading Symbols, Writing Symbols, Symbols, Symbols 59 1.1 skrll SUBSECTION 60 1.1 skrll Reading symbols 61 1.1 skrll 62 1.1 skrll There are two stages to reading a symbol table from a BFD: 63 1.1 skrll allocating storage, and the actual reading process. This is an 64 1.1 skrll excerpt from an application which reads the symbol table: 65 1.1 skrll 66 1.7 christos | long storage_needed; 67 1.7 christos | asymbol **symbol_table; 68 1.7 christos | long number_of_symbols; 69 1.7 christos | long i; 70 1.1 skrll | 71 1.7 christos | storage_needed = bfd_get_symtab_upper_bound (abfd); 72 1.1 skrll | 73 1.1 skrll | if (storage_needed < 0) 74 1.1 skrll | FAIL 75 1.1 skrll | 76 1.7 christos | if (storage_needed == 0) 77 1.7 christos | return; 78 1.5 christos | 79 1.7 christos | symbol_table = xmalloc (storage_needed); 80 1.7 christos | ... 81 1.7 christos | number_of_symbols = 82 1.7 christos | bfd_canonicalize_symtab (abfd, symbol_table); 83 1.1 skrll | 84 1.1 skrll | if (number_of_symbols < 0) 85 1.1 skrll | FAIL 86 1.1 skrll | 87 1.7 christos | for (i = 0; i < number_of_symbols; i++) 88 1.7 christos | process_symbol (symbol_table[i]); 89 1.1 skrll 90 1.1 skrll All storage for the symbols themselves is in an objalloc 91 1.1 skrll connected to the BFD; it is freed when the BFD is closed. 92 1.1 skrll 93 1.1 skrll INODE 94 1.1 skrll Writing Symbols, Mini Symbols, Reading Symbols, Symbols 95 1.1 skrll SUBSECTION 96 1.1 skrll Writing symbols 97 1.1 skrll 98 1.1 skrll Writing of a symbol table is automatic when a BFD open for 99 1.1 skrll writing is closed. The application attaches a vector of 100 1.1 skrll pointers to pointers to symbols to the BFD being written, and 101 1.1 skrll fills in the symbol count. The close and cleanup code reads 102 1.1 skrll through the table provided and performs all the necessary 103 1.1 skrll operations. The BFD output code must always be provided with an 104 1.1 skrll ``owned'' symbol: one which has come from another BFD, or one 105 1.1 skrll which has been created using <<bfd_make_empty_symbol>>. Here is an 106 1.1 skrll example showing the creation of a symbol table with only one element: 107 1.1 skrll 108 1.7 christos | #include "sysdep.h" 109 1.7 christos | #include "bfd.h" 110 1.7 christos | int main (void) 111 1.7 christos | { 112 1.7 christos | bfd *abfd; 113 1.7 christos | asymbol *ptrs[2]; 114 1.7 christos | asymbol *new; 115 1.1 skrll | 116 1.7 christos | abfd = bfd_openw ("foo","a.out-sunos-big"); 117 1.7 christos | bfd_set_format (abfd, bfd_object); 118 1.7 christos | new = bfd_make_empty_symbol (abfd); 119 1.7 christos | new->name = "dummy_symbol"; 120 1.7 christos | new->section = bfd_make_section_old_way (abfd, ".text"); 121 1.7 christos | new->flags = BSF_GLOBAL; 122 1.7 christos | new->value = 0x12345; 123 1.1 skrll | 124 1.7 christos | ptrs[0] = new; 125 1.7 christos | ptrs[1] = 0; 126 1.1 skrll | 127 1.7 christos | bfd_set_symtab (abfd, ptrs, 1); 128 1.7 christos | bfd_close (abfd); 129 1.7 christos | return 0; 130 1.7 christos | } 131 1.1 skrll | 132 1.7 christos | ./makesym 133 1.7 christos | nm foo 134 1.7 christos | 00012345 A dummy_symbol 135 1.1 skrll 136 1.1 skrll Many formats cannot represent arbitrary symbol information; for 137 1.7 christos instance, the <<a.out>> object format does not allow an 138 1.1 skrll arbitrary number of sections. A symbol pointing to a section 139 1.1 skrll which is not one of <<.text>>, <<.data>> or <<.bss>> cannot 140 1.1 skrll be described. 141 1.1 skrll 142 1.1 skrll INODE 143 1.1 skrll Mini Symbols, typedef asymbol, Writing Symbols, Symbols 144 1.1 skrll SUBSECTION 145 1.1 skrll Mini Symbols 146 1.1 skrll 147 1.1 skrll Mini symbols provide read-only access to the symbol table. 148 1.1 skrll They use less memory space, but require more time to access. 149 1.1 skrll They can be useful for tools like nm or objdump, which may 150 1.1 skrll have to handle symbol tables of extremely large executables. 151 1.1 skrll 152 1.1 skrll The <<bfd_read_minisymbols>> function will read the symbols 153 1.1 skrll into memory in an internal form. It will return a <<void *>> 154 1.1 skrll pointer to a block of memory, a symbol count, and the size of 155 1.1 skrll each symbol. The pointer is allocated using <<malloc>>, and 156 1.1 skrll should be freed by the caller when it is no longer needed. 157 1.1 skrll 158 1.1 skrll The function <<bfd_minisymbol_to_symbol>> will take a pointer 159 1.1 skrll to a minisymbol, and a pointer to a structure returned by 160 1.1 skrll <<bfd_make_empty_symbol>>, and return a <<asymbol>> structure. 161 1.1 skrll The return value may or may not be the same as the value from 162 1.1 skrll <<bfd_make_empty_symbol>> which was passed in. 163 1.1 skrll 164 1.1 skrll */ 165 1.1 skrll 166 1.1 skrll /* 167 1.1 skrll DOCDD 168 1.1 skrll INODE 169 1.1 skrll typedef asymbol, symbol handling functions, Mini Symbols, Symbols 170 1.1 skrll 171 1.1 skrll SUBSECTION 172 1.1 skrll typedef asymbol 173 1.1 skrll 174 1.1 skrll An <<asymbol>> has the form: 175 1.1 skrll 176 1.1 skrll CODE_FRAGMENT 177 1.1 skrll .typedef struct bfd_symbol 178 1.1 skrll .{ 179 1.1 skrll . {* A pointer to the BFD which owns the symbol. This information 180 1.1 skrll . is necessary so that a back end can work out what additional 181 1.1 skrll . information (invisible to the application writer) is carried 182 1.1 skrll . with the symbol. 183 1.1 skrll . 184 1.1 skrll . This field is *almost* redundant, since you can use section->owner 185 1.1 skrll . instead, except that some symbols point to the global sections 186 1.1 skrll . bfd_{abs,com,und}_section. This could be fixed by making 187 1.1 skrll . these globals be per-bfd (or per-target-flavor). FIXME. *} 188 1.1 skrll . struct bfd *the_bfd; {* Use bfd_asymbol_bfd(sym) to access this field. *} 189 1.1 skrll . 190 1.1 skrll . {* The text of the symbol. The name is left alone, and not copied; the 191 1.1 skrll . application may not alter it. *} 192 1.1 skrll . const char *name; 193 1.1 skrll . 194 1.1 skrll . {* The value of the symbol. This really should be a union of a 195 1.1 skrll . numeric value with a pointer, since some flags indicate that 196 1.1 skrll . a pointer to another symbol is stored here. *} 197 1.1 skrll . symvalue value; 198 1.1 skrll . 199 1.1 skrll . {* Attributes of a symbol. *} 200 1.7 christos .#define BSF_NO_FLAGS 0 201 1.1 skrll . 202 1.1 skrll . {* The symbol has local scope; <<static>> in <<C>>. The value 203 1.1 skrll . is the offset into the section of the data. *} 204 1.7 christos .#define BSF_LOCAL (1 << 0) 205 1.1 skrll . 206 1.1 skrll . {* The symbol has global scope; initialized data in <<C>>. The 207 1.1 skrll . value is the offset into the section of the data. *} 208 1.7 christos .#define BSF_GLOBAL (1 << 1) 209 1.1 skrll . 210 1.1 skrll . {* The symbol has global scope and is exported. The value is 211 1.1 skrll . the offset into the section of the data. *} 212 1.7 christos .#define BSF_EXPORT BSF_GLOBAL {* No real difference. *} 213 1.1 skrll . 214 1.1 skrll . {* A normal C symbol would be one of: 215 1.6 christos . <<BSF_LOCAL>>, <<BSF_UNDEFINED>> or <<BSF_GLOBAL>>. *} 216 1.1 skrll . 217 1.1 skrll . {* The symbol is a debugging record. The value has an arbitrary 218 1.1 skrll . meaning, unless BSF_DEBUGGING_RELOC is also set. *} 219 1.7 christos .#define BSF_DEBUGGING (1 << 2) 220 1.1 skrll . 221 1.1 skrll . {* The symbol denotes a function entry point. Used in ELF, 222 1.1 skrll . perhaps others someday. *} 223 1.7 christos .#define BSF_FUNCTION (1 << 3) 224 1.1 skrll . 225 1.1 skrll . {* Used by the linker. *} 226 1.7 christos .#define BSF_KEEP (1 << 5) 227 1.6 christos . 228 1.6 christos . {* An ELF common symbol. *} 229 1.7 christos .#define BSF_ELF_COMMON (1 << 6) 230 1.1 skrll . 231 1.1 skrll . {* A weak global symbol, overridable without warnings by 232 1.1 skrll . a regular global symbol of the same name. *} 233 1.7 christos .#define BSF_WEAK (1 << 7) 234 1.1 skrll . 235 1.1 skrll . {* This symbol was created to point to a section, e.g. ELF's 236 1.1 skrll . STT_SECTION symbols. *} 237 1.7 christos .#define BSF_SECTION_SYM (1 << 8) 238 1.1 skrll . 239 1.1 skrll . {* The symbol used to be a common symbol, but now it is 240 1.1 skrll . allocated. *} 241 1.7 christos .#define BSF_OLD_COMMON (1 << 9) 242 1.1 skrll . 243 1.1 skrll . {* In some files the type of a symbol sometimes alters its 244 1.1 skrll . location in an output file - ie in coff a <<ISFCN>> symbol 245 1.1 skrll . which is also <<C_EXT>> symbol appears where it was 246 1.1 skrll . declared and not at the end of a section. This bit is set 247 1.1 skrll . by the target BFD part to convey this information. *} 248 1.7 christos .#define BSF_NOT_AT_END (1 << 10) 249 1.1 skrll . 250 1.1 skrll . {* Signal that the symbol is the label of constructor section. *} 251 1.7 christos .#define BSF_CONSTRUCTOR (1 << 11) 252 1.1 skrll . 253 1.1 skrll . {* Signal that the symbol is a warning symbol. The name is a 254 1.1 skrll . warning. The name of the next symbol is the one to warn about; 255 1.1 skrll . if a reference is made to a symbol with the same name as the next 256 1.1 skrll . symbol, a warning is issued by the linker. *} 257 1.7 christos .#define BSF_WARNING (1 << 12) 258 1.1 skrll . 259 1.1 skrll . {* Signal that the symbol is indirect. This symbol is an indirect 260 1.1 skrll . pointer to the symbol with the same name as the next symbol. *} 261 1.7 christos .#define BSF_INDIRECT (1 << 13) 262 1.1 skrll . 263 1.1 skrll . {* BSF_FILE marks symbols that contain a file name. This is used 264 1.1 skrll . for ELF STT_FILE symbols. *} 265 1.7 christos .#define BSF_FILE (1 << 14) 266 1.1 skrll . 267 1.1 skrll . {* Symbol is from dynamic linking information. *} 268 1.7 christos .#define BSF_DYNAMIC (1 << 15) 269 1.1 skrll . 270 1.1 skrll . {* The symbol denotes a data object. Used in ELF, and perhaps 271 1.1 skrll . others someday. *} 272 1.7 christos .#define BSF_OBJECT (1 << 16) 273 1.1 skrll . 274 1.1 skrll . {* This symbol is a debugging symbol. The value is the offset 275 1.1 skrll . into the section of the data. BSF_DEBUGGING should be set 276 1.1 skrll . as well. *} 277 1.7 christos .#define BSF_DEBUGGING_RELOC (1 << 17) 278 1.1 skrll . 279 1.1 skrll . {* This symbol is thread local. Used in ELF. *} 280 1.7 christos .#define BSF_THREAD_LOCAL (1 << 18) 281 1.1 skrll . 282 1.1 skrll . {* This symbol represents a complex relocation expression, 283 1.1 skrll . with the expression tree serialized in the symbol name. *} 284 1.7 christos .#define BSF_RELC (1 << 19) 285 1.1 skrll . 286 1.1 skrll . {* This symbol represents a signed complex relocation expression, 287 1.1 skrll . with the expression tree serialized in the symbol name. *} 288 1.7 christos .#define BSF_SRELC (1 << 20) 289 1.1 skrll . 290 1.1 skrll . {* This symbol was created by bfd_get_synthetic_symtab. *} 291 1.7 christos .#define BSF_SYNTHETIC (1 << 21) 292 1.3 christos . 293 1.3 christos . {* This symbol is an indirect code object. Unrelated to BSF_INDIRECT. 294 1.3 christos . The dynamic linker will compute the value of this symbol by 295 1.3 christos . calling the function that it points to. BSF_FUNCTION must 296 1.3 christos . also be also set. *} 297 1.3 christos .#define BSF_GNU_INDIRECT_FUNCTION (1 << 22) 298 1.3 christos . {* This symbol is a globally unique data object. The dynamic linker 299 1.3 christos . will make sure that in the entire process there is just one symbol 300 1.3 christos . with this name and type in use. BSF_OBJECT must also be set. *} 301 1.7 christos .#define BSF_GNU_UNIQUE (1 << 23) 302 1.1 skrll . 303 1.10 christos . {* This section symbol should be included in the symbol table. *} 304 1.10 christos .#define BSF_SECTION_SYM_USED (1 << 24) 305 1.10 christos . 306 1.13 christos . {* This symbol underwent section merge resolution. *} 307 1.13 christos .#define BSF_MERGE_RESOLVED (1 << 25) 308 1.13 christos . 309 1.1 skrll . flagword flags; 310 1.1 skrll . 311 1.1 skrll . {* A pointer to the section to which this symbol is 312 1.1 skrll . relative. This will always be non NULL, there are special 313 1.1 skrll . sections for undefined and absolute symbols. *} 314 1.1 skrll . struct bfd_section *section; 315 1.1 skrll . 316 1.1 skrll . {* Back end special data. *} 317 1.1 skrll . union 318 1.1 skrll . { 319 1.1 skrll . void *p; 320 1.1 skrll . bfd_vma i; 321 1.1 skrll . } 322 1.1 skrll . udata; 323 1.1 skrll .} 324 1.1 skrll .asymbol; 325 1.1 skrll . 326 1.11 christos 327 1.11 christos EXTERNAL 328 1.11 christos .typedef enum bfd_print_symbol 329 1.11 christos .{ 330 1.11 christos . bfd_print_symbol_name, 331 1.11 christos . bfd_print_symbol_more, 332 1.11 christos . bfd_print_symbol_all 333 1.11 christos .} bfd_print_symbol_type; 334 1.11 christos . 335 1.11 christos .{* Information about a symbol that nm needs. *} 336 1.11 christos . 337 1.11 christos .typedef struct _symbol_info 338 1.11 christos .{ 339 1.11 christos . symvalue value; 340 1.11 christos . char type; 341 1.11 christos . const char *name; {* Symbol name. *} 342 1.11 christos . unsigned char stab_type; {* Stab type. *} 343 1.11 christos . char stab_other; {* Stab other. *} 344 1.11 christos . short stab_desc; {* Stab desc. *} 345 1.11 christos . const char *stab_name; {* String for stab type. *} 346 1.11 christos .} symbol_info; 347 1.11 christos . 348 1.12 christos .{* An empty string that will not match the address of any other 349 1.12 christos . symbol name, even unnamed local symbols which will also have empty 350 1.12 christos . string names. This can be used to flag a symbol as corrupt if its 351 1.12 christos . name uses an out of range string table index. *} 352 1.12 christos .extern const char bfd_symbol_error_name[]; 353 1.1 skrll */ 354 1.1 skrll 355 1.1 skrll #include "sysdep.h" 356 1.1 skrll #include "bfd.h" 357 1.1 skrll #include "libbfd.h" 358 1.1 skrll #include "safe-ctype.h" 359 1.1 skrll #include "bfdlink.h" 360 1.1 skrll #include "aout/stab_gnu.h" 361 1.1 skrll 362 1.12 christos const char bfd_symbol_error_name[] = { 0 }; 363 1.12 christos 364 1.1 skrll /* 365 1.1 skrll DOCDD 366 1.1 skrll INODE 367 1.1 skrll symbol handling functions, , typedef asymbol, Symbols 368 1.1 skrll SUBSECTION 369 1.1 skrll Symbol handling functions 370 1.1 skrll */ 371 1.1 skrll 372 1.1 skrll /* 373 1.1 skrll FUNCTION 374 1.1 skrll bfd_get_symtab_upper_bound 375 1.1 skrll 376 1.1 skrll DESCRIPTION 377 1.1 skrll Return the number of bytes required to store a vector of pointers 378 1.1 skrll to <<asymbols>> for all the symbols in the BFD @var{abfd}, 379 1.1 skrll including a terminal NULL pointer. If there are no symbols in 380 1.1 skrll the BFD, then return 0. If an error occurs, return -1. 381 1.1 skrll 382 1.1 skrll .#define bfd_get_symtab_upper_bound(abfd) \ 383 1.7 christos . BFD_SEND (abfd, _bfd_get_symtab_upper_bound, (abfd)) 384 1.1 skrll . 385 1.1 skrll */ 386 1.1 skrll 387 1.1 skrll /* 388 1.1 skrll FUNCTION 389 1.1 skrll bfd_is_local_label 390 1.1 skrll 391 1.1 skrll SYNOPSIS 392 1.10 christos bool bfd_is_local_label (bfd *abfd, asymbol *sym); 393 1.1 skrll 394 1.1 skrll DESCRIPTION 395 1.1 skrll Return TRUE if the given symbol @var{sym} in the BFD @var{abfd} is 396 1.1 skrll a compiler generated local label, else return FALSE. 397 1.1 skrll */ 398 1.1 skrll 399 1.10 christos bool 400 1.1 skrll bfd_is_local_label (bfd *abfd, asymbol *sym) 401 1.1 skrll { 402 1.1 skrll /* The BSF_SECTION_SYM check is needed for IA-64, where every label that 403 1.1 skrll starts with '.' is local. This would accidentally catch section names 404 1.1 skrll if we didn't reject them here. */ 405 1.1 skrll if ((sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_FILE | BSF_SECTION_SYM)) != 0) 406 1.10 christos return false; 407 1.12 christos if (sym->name == NULL || sym->name == bfd_symbol_error_name) 408 1.10 christos return false; 409 1.1 skrll return bfd_is_local_label_name (abfd, sym->name); 410 1.1 skrll } 411 1.1 skrll 412 1.1 skrll /* 413 1.1 skrll FUNCTION 414 1.1 skrll bfd_is_local_label_name 415 1.1 skrll 416 1.1 skrll SYNOPSIS 417 1.10 christos bool bfd_is_local_label_name (bfd *abfd, const char *name); 418 1.1 skrll 419 1.1 skrll DESCRIPTION 420 1.1 skrll Return TRUE if a symbol with the name @var{name} in the BFD 421 1.1 skrll @var{abfd} is a compiler generated local label, else return 422 1.1 skrll FALSE. This just checks whether the name has the form of a 423 1.1 skrll local label. 424 1.1 skrll 425 1.1 skrll .#define bfd_is_local_label_name(abfd, name) \ 426 1.7 christos . BFD_SEND (abfd, _bfd_is_local_label_name, (abfd, name)) 427 1.1 skrll . 428 1.1 skrll */ 429 1.1 skrll 430 1.1 skrll /* 431 1.1 skrll FUNCTION 432 1.1 skrll bfd_is_target_special_symbol 433 1.1 skrll 434 1.1 skrll SYNOPSIS 435 1.10 christos bool bfd_is_target_special_symbol (bfd *abfd, asymbol *sym); 436 1.1 skrll 437 1.1 skrll DESCRIPTION 438 1.1 skrll Return TRUE iff a symbol @var{sym} in the BFD @var{abfd} is something 439 1.1 skrll special to the particular target represented by the BFD. Such symbols 440 1.1 skrll should normally not be mentioned to the user. 441 1.1 skrll 442 1.1 skrll .#define bfd_is_target_special_symbol(abfd, sym) \ 443 1.7 christos . BFD_SEND (abfd, _bfd_is_target_special_symbol, (abfd, sym)) 444 1.1 skrll . 445 1.1 skrll */ 446 1.1 skrll 447 1.1 skrll /* 448 1.1 skrll FUNCTION 449 1.1 skrll bfd_canonicalize_symtab 450 1.1 skrll 451 1.1 skrll DESCRIPTION 452 1.1 skrll Read the symbols from the BFD @var{abfd}, and fills in 453 1.1 skrll the vector @var{location} with pointers to the symbols and 454 1.1 skrll a trailing NULL. 455 1.1 skrll Return the actual number of symbol pointers, not 456 1.1 skrll including the NULL. 457 1.1 skrll 458 1.1 skrll .#define bfd_canonicalize_symtab(abfd, location) \ 459 1.7 christos . BFD_SEND (abfd, _bfd_canonicalize_symtab, (abfd, location)) 460 1.1 skrll . 461 1.1 skrll */ 462 1.1 skrll 463 1.1 skrll /* 464 1.1 skrll FUNCTION 465 1.1 skrll bfd_set_symtab 466 1.1 skrll 467 1.1 skrll SYNOPSIS 468 1.10 christos bool bfd_set_symtab 469 1.1 skrll (bfd *abfd, asymbol **location, unsigned int count); 470 1.1 skrll 471 1.1 skrll DESCRIPTION 472 1.1 skrll Arrange that when the output BFD @var{abfd} is closed, 473 1.1 skrll the table @var{location} of @var{count} pointers to symbols 474 1.1 skrll will be written. 475 1.1 skrll */ 476 1.1 skrll 477 1.10 christos bool 478 1.1 skrll bfd_set_symtab (bfd *abfd, asymbol **location, unsigned int symcount) 479 1.1 skrll { 480 1.1 skrll if (abfd->format != bfd_object || bfd_read_p (abfd)) 481 1.1 skrll { 482 1.1 skrll bfd_set_error (bfd_error_invalid_operation); 483 1.10 christos return false; 484 1.1 skrll } 485 1.1 skrll 486 1.9 christos abfd->outsymbols = location; 487 1.9 christos abfd->symcount = symcount; 488 1.10 christos return true; 489 1.1 skrll } 490 1.1 skrll 491 1.1 skrll /* 492 1.1 skrll FUNCTION 493 1.1 skrll bfd_print_symbol_vandf 494 1.1 skrll 495 1.1 skrll SYNOPSIS 496 1.1 skrll void bfd_print_symbol_vandf (bfd *abfd, void *file, asymbol *symbol); 497 1.1 skrll 498 1.1 skrll DESCRIPTION 499 1.1 skrll Print the value and flags of the @var{symbol} supplied to the 500 1.1 skrll stream @var{file}. 501 1.1 skrll */ 502 1.1 skrll void 503 1.1 skrll bfd_print_symbol_vandf (bfd *abfd, void *arg, asymbol *symbol) 504 1.1 skrll { 505 1.3 christos FILE *file = (FILE *) arg; 506 1.1 skrll 507 1.1 skrll flagword type = symbol->flags; 508 1.1 skrll 509 1.1 skrll if (symbol->section != NULL) 510 1.1 skrll bfd_fprintf_vma (abfd, file, symbol->value + symbol->section->vma); 511 1.1 skrll else 512 1.1 skrll bfd_fprintf_vma (abfd, file, symbol->value); 513 1.1 skrll 514 1.1 skrll /* This presumes that a symbol can not be both BSF_DEBUGGING and 515 1.1 skrll BSF_DYNAMIC, nor more than one of BSF_FUNCTION, BSF_FILE, and 516 1.1 skrll BSF_OBJECT. */ 517 1.1 skrll fprintf (file, " %c%c%c%c%c%c%c", 518 1.1 skrll ((type & BSF_LOCAL) 519 1.1 skrll ? (type & BSF_GLOBAL) ? '!' : 'l' 520 1.3 christos : (type & BSF_GLOBAL) ? 'g' 521 1.3 christos : (type & BSF_GNU_UNIQUE) ? 'u' : ' '), 522 1.1 skrll (type & BSF_WEAK) ? 'w' : ' ', 523 1.1 skrll (type & BSF_CONSTRUCTOR) ? 'C' : ' ', 524 1.1 skrll (type & BSF_WARNING) ? 'W' : ' ', 525 1.3 christos (type & BSF_INDIRECT) ? 'I' : (type & BSF_GNU_INDIRECT_FUNCTION) ? 'i' : ' ', 526 1.1 skrll (type & BSF_DEBUGGING) ? 'd' : (type & BSF_DYNAMIC) ? 'D' : ' ', 527 1.1 skrll ((type & BSF_FUNCTION) 528 1.1 skrll ? 'F' 529 1.1 skrll : ((type & BSF_FILE) 530 1.1 skrll ? 'f' 531 1.1 skrll : ((type & BSF_OBJECT) ? 'O' : ' ')))); 532 1.1 skrll } 533 1.1 skrll 534 1.1 skrll /* 535 1.1 skrll FUNCTION 536 1.1 skrll bfd_make_empty_symbol 537 1.1 skrll 538 1.1 skrll DESCRIPTION 539 1.1 skrll Create a new <<asymbol>> structure for the BFD @var{abfd} 540 1.1 skrll and return a pointer to it. 541 1.1 skrll 542 1.1 skrll This routine is necessary because each back end has private 543 1.1 skrll information surrounding the <<asymbol>>. Building your own 544 1.1 skrll <<asymbol>> and pointing to it will not create the private 545 1.1 skrll information, and will cause problems later on. 546 1.1 skrll 547 1.1 skrll .#define bfd_make_empty_symbol(abfd) \ 548 1.7 christos . BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd)) 549 1.1 skrll . 550 1.1 skrll */ 551 1.1 skrll 552 1.1 skrll /* 553 1.1 skrll FUNCTION 554 1.1 skrll _bfd_generic_make_empty_symbol 555 1.1 skrll 556 1.1 skrll SYNOPSIS 557 1.1 skrll asymbol *_bfd_generic_make_empty_symbol (bfd *); 558 1.1 skrll 559 1.1 skrll DESCRIPTION 560 1.1 skrll Create a new <<asymbol>> structure for the BFD @var{abfd} 561 1.1 skrll and return a pointer to it. Used by core file routines, 562 1.1 skrll binary back-end and anywhere else where no private info 563 1.1 skrll is needed. 564 1.1 skrll */ 565 1.1 skrll 566 1.1 skrll asymbol * 567 1.1 skrll _bfd_generic_make_empty_symbol (bfd *abfd) 568 1.1 skrll { 569 1.10 christos size_t amt = sizeof (asymbol); 570 1.3 christos asymbol *new_symbol = (asymbol *) bfd_zalloc (abfd, amt); 571 1.3 christos if (new_symbol) 572 1.3 christos new_symbol->the_bfd = abfd; 573 1.3 christos return new_symbol; 574 1.1 skrll } 575 1.1 skrll 576 1.1 skrll /* 577 1.1 skrll FUNCTION 578 1.1 skrll bfd_make_debug_symbol 579 1.1 skrll 580 1.1 skrll DESCRIPTION 581 1.1 skrll Create a new <<asymbol>> structure for the BFD @var{abfd}, 582 1.11 christos to be used as a debugging symbol. 583 1.1 skrll 584 1.11 christos .#define bfd_make_debug_symbol(abfd) \ 585 1.11 christos . BFD_SEND (abfd, _bfd_make_debug_symbol, (abfd)) 586 1.1 skrll . 587 1.1 skrll */ 588 1.1 skrll 589 1.1 skrll struct section_to_type 590 1.1 skrll { 591 1.1 skrll const char *section; 592 1.1 skrll char type; 593 1.1 skrll }; 594 1.1 skrll 595 1.10 christos /* Map special section names to POSIX/BSD single-character symbol types. 596 1.1 skrll This table is probably incomplete. It is sorted for convenience of 597 1.1 skrll adding entries. Since it is so short, a linear search is used. */ 598 1.1 skrll static const struct section_to_type stt[] = 599 1.1 skrll { 600 1.12 christos {".didat", 'i'}, /* MSVC's .didat (delay import) section */ 601 1.7 christos {".drectve", 'i'}, /* MSVC's .drective section */ 602 1.7 christos {".edata", 'e'}, /* MSVC's .edata (export) section */ 603 1.7 christos {".idata", 'i'}, /* MSVC's .idata (import) section */ 604 1.7 christos {".pdata", 'p'}, /* MSVC's .pdata (stack unwind) section */ 605 1.1 skrll {0, 0} 606 1.1 skrll }; 607 1.1 skrll 608 1.1 skrll /* Return the single-character symbol type corresponding to 609 1.1 skrll section S, or '?' for an unknown COFF section. 610 1.1 skrll 611 1.9 christos Check for leading strings which match, followed by a number, '.', 612 1.10 christos or '$' so .idata5 matches the .idata entry. */ 613 1.1 skrll 614 1.1 skrll static char 615 1.1 skrll coff_section_type (const char *s) 616 1.1 skrll { 617 1.1 skrll const struct section_to_type *t; 618 1.1 skrll 619 1.1 skrll for (t = &stt[0]; t->section; t++) 620 1.9 christos { 621 1.9 christos size_t len = strlen (t->section); 622 1.9 christos if (strncmp (s, t->section, len) == 0 623 1.9 christos && memchr (".$0123456789", s[len], 13) != 0) 624 1.9 christos return t->type; 625 1.9 christos } 626 1.1 skrll 627 1.1 skrll return '?'; 628 1.1 skrll } 629 1.1 skrll 630 1.1 skrll /* Return the single-character symbol type corresponding to section 631 1.1 skrll SECTION, or '?' for an unknown section. This uses section flags to 632 1.1 skrll identify sections. 633 1.1 skrll 634 1.10 christos FIXME These types are unhandled: e, i, p. If we handled these also, 635 1.1 skrll we could perhaps obsolete coff_section_type. */ 636 1.1 skrll 637 1.1 skrll static char 638 1.1 skrll decode_section_type (const struct bfd_section *section) 639 1.1 skrll { 640 1.1 skrll if (section->flags & SEC_CODE) 641 1.1 skrll return 't'; 642 1.1 skrll if (section->flags & SEC_DATA) 643 1.1 skrll { 644 1.1 skrll if (section->flags & SEC_READONLY) 645 1.1 skrll return 'r'; 646 1.1 skrll else if (section->flags & SEC_SMALL_DATA) 647 1.1 skrll return 'g'; 648 1.1 skrll else 649 1.1 skrll return 'd'; 650 1.1 skrll } 651 1.1 skrll if ((section->flags & SEC_HAS_CONTENTS) == 0) 652 1.1 skrll { 653 1.1 skrll if (section->flags & SEC_SMALL_DATA) 654 1.1 skrll return 's'; 655 1.1 skrll else 656 1.1 skrll return 'b'; 657 1.1 skrll } 658 1.1 skrll if (section->flags & SEC_DEBUGGING) 659 1.1 skrll return 'N'; 660 1.1 skrll if ((section->flags & SEC_HAS_CONTENTS) && (section->flags & SEC_READONLY)) 661 1.1 skrll return 'n'; 662 1.1 skrll 663 1.1 skrll return '?'; 664 1.1 skrll } 665 1.1 skrll 666 1.1 skrll /* 667 1.1 skrll FUNCTION 668 1.1 skrll bfd_decode_symclass 669 1.1 skrll 670 1.11 christos SYNOPSIS 671 1.11 christos int bfd_decode_symclass (asymbol *symbol); 672 1.11 christos 673 1.1 skrll DESCRIPTION 674 1.1 skrll Return a character corresponding to the symbol 675 1.1 skrll class of @var{symbol}, or '?' for an unknown class. 676 1.1 skrll */ 677 1.1 skrll int 678 1.1 skrll bfd_decode_symclass (asymbol *symbol) 679 1.1 skrll { 680 1.1 skrll char c; 681 1.1 skrll 682 1.10 christos /* Paranoia... */ 683 1.10 christos if (symbol == NULL || symbol->section == NULL) 684 1.10 christos return '?'; 685 1.10 christos 686 1.1 skrll if (symbol->section && bfd_is_com_section (symbol->section)) 687 1.10 christos { 688 1.10 christos if (symbol->section->flags & SEC_SMALL_DATA) 689 1.10 christos return 'c'; 690 1.10 christos else 691 1.10 christos return 'C'; 692 1.10 christos } 693 1.1 skrll if (bfd_is_und_section (symbol->section)) 694 1.1 skrll { 695 1.1 skrll if (symbol->flags & BSF_WEAK) 696 1.1 skrll { 697 1.1 skrll /* If weak, determine if it's specifically an object 698 1.1 skrll or non-object weak. */ 699 1.1 skrll if (symbol->flags & BSF_OBJECT) 700 1.1 skrll return 'v'; 701 1.1 skrll else 702 1.1 skrll return 'w'; 703 1.1 skrll } 704 1.1 skrll else 705 1.1 skrll return 'U'; 706 1.1 skrll } 707 1.1 skrll if (bfd_is_ind_section (symbol->section)) 708 1.1 skrll return 'I'; 709 1.3 christos if (symbol->flags & BSF_GNU_INDIRECT_FUNCTION) 710 1.3 christos return 'i'; 711 1.1 skrll if (symbol->flags & BSF_WEAK) 712 1.1 skrll { 713 1.1 skrll /* If weak, determine if it's specifically an object 714 1.1 skrll or non-object weak. */ 715 1.1 skrll if (symbol->flags & BSF_OBJECT) 716 1.1 skrll return 'V'; 717 1.1 skrll else 718 1.1 skrll return 'W'; 719 1.1 skrll } 720 1.3 christos if (symbol->flags & BSF_GNU_UNIQUE) 721 1.3 christos return 'u'; 722 1.1 skrll if (!(symbol->flags & (BSF_GLOBAL | BSF_LOCAL))) 723 1.1 skrll return '?'; 724 1.1 skrll 725 1.1 skrll if (bfd_is_abs_section (symbol->section)) 726 1.1 skrll c = 'a'; 727 1.1 skrll else if (symbol->section) 728 1.1 skrll { 729 1.10 christos c = coff_section_type (symbol->section->name); 730 1.1 skrll if (c == '?') 731 1.10 christos c = decode_section_type (symbol->section); 732 1.1 skrll } 733 1.1 skrll else 734 1.1 skrll return '?'; 735 1.1 skrll if (symbol->flags & BSF_GLOBAL) 736 1.1 skrll c = TOUPPER (c); 737 1.1 skrll return c; 738 1.1 skrll 739 1.1 skrll /* We don't have to handle these cases just yet, but we will soon: 740 1.1 skrll N_SETV: 'v'; 741 1.1 skrll N_SETA: 'l'; 742 1.1 skrll N_SETT: 'x'; 743 1.1 skrll N_SETD: 'z'; 744 1.1 skrll N_SETB: 's'; 745 1.1 skrll N_INDR: 'i'; 746 1.1 skrll */ 747 1.1 skrll } 748 1.1 skrll 749 1.1 skrll /* 750 1.1 skrll FUNCTION 751 1.1 skrll bfd_is_undefined_symclass 752 1.1 skrll 753 1.11 christos SYNOPSIS 754 1.11 christos bool bfd_is_undefined_symclass (int symclass); 755 1.11 christos 756 1.1 skrll DESCRIPTION 757 1.1 skrll Returns non-zero if the class symbol returned by 758 1.1 skrll bfd_decode_symclass represents an undefined symbol. 759 1.1 skrll Returns zero otherwise. 760 1.1 skrll */ 761 1.1 skrll 762 1.10 christos bool 763 1.1 skrll bfd_is_undefined_symclass (int symclass) 764 1.1 skrll { 765 1.1 skrll return symclass == 'U' || symclass == 'w' || symclass == 'v'; 766 1.1 skrll } 767 1.1 skrll 768 1.1 skrll /* 769 1.1 skrll FUNCTION 770 1.1 skrll bfd_symbol_info 771 1.1 skrll 772 1.11 christos SYNOPSIS 773 1.11 christos void bfd_symbol_info (asymbol *symbol, symbol_info *ret); 774 1.11 christos 775 1.1 skrll DESCRIPTION 776 1.1 skrll Fill in the basic info about symbol that nm needs. 777 1.1 skrll Additional info may be added by the back-ends after 778 1.1 skrll calling this function. 779 1.1 skrll */ 780 1.1 skrll 781 1.1 skrll void 782 1.1 skrll bfd_symbol_info (asymbol *symbol, symbol_info *ret) 783 1.1 skrll { 784 1.1 skrll ret->type = bfd_decode_symclass (symbol); 785 1.1 skrll 786 1.1 skrll if (bfd_is_undefined_symclass (ret->type)) 787 1.1 skrll ret->value = 0; 788 1.1 skrll else 789 1.1 skrll ret->value = symbol->value + symbol->section->vma; 790 1.1 skrll 791 1.12 christos ret->name = (symbol->name != bfd_symbol_error_name 792 1.12 christos ? symbol->name : _("<corrupt>")); 793 1.1 skrll } 794 1.1 skrll 795 1.1 skrll /* 796 1.1 skrll FUNCTION 797 1.1 skrll bfd_copy_private_symbol_data 798 1.1 skrll 799 1.1 skrll DESCRIPTION 800 1.1 skrll Copy private symbol information from @var{isym} in the BFD 801 1.1 skrll @var{ibfd} to the symbol @var{osym} in the BFD @var{obfd}. 802 1.1 skrll Return <<TRUE>> on success, <<FALSE>> on error. Possible error 803 1.1 skrll returns are: 804 1.1 skrll 805 1.1 skrll o <<bfd_error_no_memory>> - 806 1.1 skrll Not enough memory exists to create private data for @var{osec}. 807 1.1 skrll 808 1.1 skrll .#define bfd_copy_private_symbol_data(ibfd, isymbol, obfd, osymbol) \ 809 1.7 christos . BFD_SEND (obfd, _bfd_copy_private_symbol_data, \ 810 1.7 christos . (ibfd, isymbol, obfd, osymbol)) 811 1.1 skrll . 812 1.1 skrll */ 813 1.1 skrll 814 1.1 skrll /* The generic version of the function which returns mini symbols. 815 1.1 skrll This is used when the backend does not provide a more efficient 816 1.1 skrll version. It just uses BFD asymbol structures as mini symbols. */ 817 1.1 skrll 818 1.1 skrll long 819 1.1 skrll _bfd_generic_read_minisymbols (bfd *abfd, 820 1.10 christos bool dynamic, 821 1.1 skrll void **minisymsp, 822 1.1 skrll unsigned int *sizep) 823 1.1 skrll { 824 1.1 skrll long storage; 825 1.1 skrll asymbol **syms = NULL; 826 1.1 skrll long symcount; 827 1.1 skrll 828 1.1 skrll if (dynamic) 829 1.1 skrll storage = bfd_get_dynamic_symtab_upper_bound (abfd); 830 1.1 skrll else 831 1.1 skrll storage = bfd_get_symtab_upper_bound (abfd); 832 1.1 skrll if (storage < 0) 833 1.1 skrll goto error_return; 834 1.1 skrll if (storage == 0) 835 1.1 skrll return 0; 836 1.1 skrll 837 1.3 christos syms = (asymbol **) bfd_malloc (storage); 838 1.1 skrll if (syms == NULL) 839 1.1 skrll goto error_return; 840 1.1 skrll 841 1.1 skrll if (dynamic) 842 1.1 skrll symcount = bfd_canonicalize_dynamic_symtab (abfd, syms); 843 1.1 skrll else 844 1.1 skrll symcount = bfd_canonicalize_symtab (abfd, syms); 845 1.1 skrll if (symcount < 0) 846 1.1 skrll goto error_return; 847 1.1 skrll 848 1.9 christos if (symcount == 0) 849 1.9 christos /* We return 0 above when storage is 0. Exit in the same state 850 1.9 christos here, so as to not complicate callers with having to deal with 851 1.9 christos freeing memory for zero symcount. */ 852 1.9 christos free (syms); 853 1.9 christos else 854 1.9 christos { 855 1.9 christos *minisymsp = syms; 856 1.9 christos *sizep = sizeof (asymbol *); 857 1.9 christos } 858 1.1 skrll return symcount; 859 1.1 skrll 860 1.1 skrll error_return: 861 1.1 skrll bfd_set_error (bfd_error_no_symbols); 862 1.10 christos free (syms); 863 1.1 skrll return -1; 864 1.1 skrll } 865 1.1 skrll 866 1.1 skrll /* The generic version of the function which converts a minisymbol to 867 1.1 skrll an asymbol. We don't worry about the sym argument we are passed; 868 1.1 skrll we just return the asymbol the minisymbol points to. */ 869 1.1 skrll 870 1.1 skrll asymbol * 871 1.1 skrll _bfd_generic_minisymbol_to_symbol (bfd *abfd ATTRIBUTE_UNUSED, 872 1.10 christos bool dynamic ATTRIBUTE_UNUSED, 873 1.1 skrll const void *minisym, 874 1.1 skrll asymbol *sym ATTRIBUTE_UNUSED) 875 1.1 skrll { 876 1.1 skrll return *(asymbol **) minisym; 877 1.1 skrll } 878 1.1 skrll 879 1.1 skrll /* Look through stabs debugging information in .stab and .stabstr 880 1.1 skrll sections to find the source file and line closest to a desired 881 1.1 skrll location. This is used by COFF and ELF targets. It sets *pfound 882 1.1 skrll to TRUE if it finds some information. The *pinfo field is used to 883 1.1 skrll pass cached information in and out of this routine; this first time 884 1.1 skrll the routine is called for a BFD, *pinfo should be NULL. The value 885 1.1 skrll placed in *pinfo should be saved with the BFD, and passed back each 886 1.1 skrll time this function is called. */ 887 1.1 skrll 888 1.1 skrll /* We use a cache by default. */ 889 1.1 skrll 890 1.1 skrll #define ENABLE_CACHING 891 1.1 skrll 892 1.1 skrll /* We keep an array of indexentry structures to record where in the 893 1.1 skrll stabs section we should look to find line number information for a 894 1.1 skrll particular address. */ 895 1.1 skrll 896 1.1 skrll struct indexentry 897 1.1 skrll { 898 1.1 skrll bfd_vma val; 899 1.1 skrll bfd_byte *stab; 900 1.1 skrll bfd_byte *str; 901 1.1 skrll char *directory_name; 902 1.1 skrll char *file_name; 903 1.1 skrll char *function_name; 904 1.9 christos int idx; 905 1.1 skrll }; 906 1.1 skrll 907 1.1 skrll /* Compare two indexentry structures. This is called via qsort. */ 908 1.1 skrll 909 1.1 skrll static int 910 1.1 skrll cmpindexentry (const void *a, const void *b) 911 1.1 skrll { 912 1.3 christos const struct indexentry *contestantA = (const struct indexentry *) a; 913 1.3 christos const struct indexentry *contestantB = (const struct indexentry *) b; 914 1.1 skrll 915 1.1 skrll if (contestantA->val < contestantB->val) 916 1.1 skrll return -1; 917 1.9 christos if (contestantA->val > contestantB->val) 918 1.1 skrll return 1; 919 1.9 christos return contestantA->idx - contestantB->idx; 920 1.1 skrll } 921 1.1 skrll 922 1.1 skrll /* A pointer to this structure is stored in *pinfo. */ 923 1.1 skrll 924 1.1 skrll struct stab_find_info 925 1.1 skrll { 926 1.1 skrll /* The .stab section. */ 927 1.1 skrll asection *stabsec; 928 1.1 skrll /* The .stabstr section. */ 929 1.1 skrll asection *strsec; 930 1.1 skrll /* The contents of the .stab section. */ 931 1.1 skrll bfd_byte *stabs; 932 1.1 skrll /* The contents of the .stabstr section. */ 933 1.1 skrll bfd_byte *strs; 934 1.1 skrll 935 1.1 skrll /* A table that indexes stabs by memory address. */ 936 1.1 skrll struct indexentry *indextable; 937 1.1 skrll /* The number of entries in indextable. */ 938 1.1 skrll int indextablesize; 939 1.1 skrll 940 1.1 skrll #ifdef ENABLE_CACHING 941 1.1 skrll /* Cached values to restart quickly. */ 942 1.1 skrll struct indexentry *cached_indexentry; 943 1.1 skrll bfd_vma cached_offset; 944 1.1 skrll bfd_byte *cached_stab; 945 1.1 skrll char *cached_file_name; 946 1.1 skrll #endif 947 1.1 skrll 948 1.1 skrll /* Saved ptr to malloc'ed filename. */ 949 1.1 skrll char *filename; 950 1.1 skrll }; 951 1.1 skrll 952 1.10 christos bool 953 1.1 skrll _bfd_stab_section_find_nearest_line (bfd *abfd, 954 1.1 skrll asymbol **symbols, 955 1.1 skrll asection *section, 956 1.1 skrll bfd_vma offset, 957 1.10 christos bool *pfound, 958 1.1 skrll const char **pfilename, 959 1.1 skrll const char **pfnname, 960 1.1 skrll unsigned int *pline, 961 1.1 skrll void **pinfo) 962 1.1 skrll { 963 1.1 skrll struct stab_find_info *info; 964 1.1 skrll bfd_size_type stabsize, strsize; 965 1.1 skrll bfd_byte *stab, *str; 966 1.5 christos bfd_byte *nul_fun, *nul_str; 967 1.1 skrll bfd_size_type stroff; 968 1.1 skrll struct indexentry *indexentry; 969 1.1 skrll char *file_name; 970 1.1 skrll char *directory_name; 971 1.10 christos bool saw_line, saw_func; 972 1.1 skrll 973 1.10 christos *pfound = false; 974 1.1 skrll *pfilename = bfd_get_filename (abfd); 975 1.1 skrll *pfnname = NULL; 976 1.1 skrll *pline = 0; 977 1.1 skrll 978 1.1 skrll /* Stabs entries use a 12 byte format: 979 1.1 skrll 4 byte string table index 980 1.1 skrll 1 byte stab type 981 1.1 skrll 1 byte stab other field 982 1.1 skrll 2 byte stab desc field 983 1.1 skrll 4 byte stab value 984 1.1 skrll FIXME: This will have to change for a 64 bit object format. 985 1.1 skrll 986 1.1 skrll The stabs symbols are divided into compilation units. For the 987 1.1 skrll first entry in each unit, the type of 0, the value is the length 988 1.1 skrll of the string table for this unit, and the desc field is the 989 1.1 skrll number of stabs symbols for this unit. */ 990 1.1 skrll 991 1.1 skrll #define STRDXOFF (0) 992 1.1 skrll #define TYPEOFF (4) 993 1.1 skrll #define OTHEROFF (5) 994 1.1 skrll #define DESCOFF (6) 995 1.1 skrll #define VALOFF (8) 996 1.1 skrll #define STABSIZE (12) 997 1.1 skrll 998 1.3 christos info = (struct stab_find_info *) *pinfo; 999 1.1 skrll if (info != NULL) 1000 1.1 skrll { 1001 1.1 skrll if (info->stabsec == NULL || info->strsec == NULL) 1002 1.1 skrll { 1003 1.11 christos /* No usable stabs debugging information. */ 1004 1.10 christos return true; 1005 1.1 skrll } 1006 1.1 skrll 1007 1.1 skrll stabsize = (info->stabsec->rawsize 1008 1.1 skrll ? info->stabsec->rawsize 1009 1.1 skrll : info->stabsec->size); 1010 1.1 skrll strsize = (info->strsec->rawsize 1011 1.1 skrll ? info->strsec->rawsize 1012 1.1 skrll : info->strsec->size); 1013 1.1 skrll } 1014 1.1 skrll else 1015 1.1 skrll { 1016 1.1 skrll long reloc_size, reloc_count; 1017 1.1 skrll arelent **reloc_vector; 1018 1.1 skrll int i; 1019 1.1 skrll char *function_name; 1020 1.1 skrll bfd_size_type amt = sizeof *info; 1021 1.1 skrll 1022 1.3 christos info = (struct stab_find_info *) bfd_zalloc (abfd, amt); 1023 1.1 skrll if (info == NULL) 1024 1.10 christos return false; 1025 1.11 christos *pinfo = info; 1026 1.1 skrll 1027 1.1 skrll /* FIXME: When using the linker --split-by-file or 1028 1.1 skrll --split-by-reloc options, it is possible for the .stab and 1029 1.1 skrll .stabstr sections to be split. We should handle that. */ 1030 1.1 skrll 1031 1.1 skrll info->stabsec = bfd_get_section_by_name (abfd, ".stab"); 1032 1.1 skrll info->strsec = bfd_get_section_by_name (abfd, ".stabstr"); 1033 1.1 skrll 1034 1.1 skrll if (info->stabsec == NULL || info->strsec == NULL) 1035 1.1 skrll { 1036 1.1 skrll /* Try SOM section names. */ 1037 1.1 skrll info->stabsec = bfd_get_section_by_name (abfd, "$GDB_SYMBOLS$"); 1038 1.1 skrll info->strsec = bfd_get_section_by_name (abfd, "$GDB_STRINGS$"); 1039 1.5 christos 1040 1.1 skrll if (info->stabsec == NULL || info->strsec == NULL) 1041 1.11 christos return true; 1042 1.1 skrll } 1043 1.1 skrll 1044 1.11 christos if ((info->stabsec->flags & SEC_HAS_CONTENTS) == 0 1045 1.11 christos || (info->strsec->flags & SEC_HAS_CONTENTS) == 0) 1046 1.11 christos goto out; 1047 1.11 christos 1048 1.1 skrll stabsize = (info->stabsec->rawsize 1049 1.1 skrll ? info->stabsec->rawsize 1050 1.1 skrll : info->stabsec->size); 1051 1.5 christos stabsize = (stabsize / STABSIZE) * STABSIZE; 1052 1.1 skrll strsize = (info->strsec->rawsize 1053 1.1 skrll ? info->strsec->rawsize 1054 1.1 skrll : info->strsec->size); 1055 1.1 skrll 1056 1.11 christos if (stabsize == 0 || strsize == 0) 1057 1.11 christos goto out; 1058 1.1 skrll 1059 1.11 christos if (!bfd_malloc_and_get_section (abfd, info->stabsec, &info->stabs)) 1060 1.11 christos goto out; 1061 1.11 christos if (!bfd_malloc_and_get_section (abfd, info->strsec, &info->strs)) 1062 1.11 christos goto out1; 1063 1.1 skrll 1064 1.9 christos /* Stab strings ought to be nul terminated. Ensure the last one 1065 1.9 christos is, to prevent running off the end of the buffer. */ 1066 1.9 christos info->strs[strsize - 1] = 0; 1067 1.9 christos 1068 1.1 skrll /* If this is a relocatable object file, we have to relocate 1069 1.1 skrll the entries in .stab. This should always be simple 32 bit 1070 1.1 skrll relocations against symbols defined in this object file, so 1071 1.1 skrll this should be no big deal. */ 1072 1.1 skrll reloc_size = bfd_get_reloc_upper_bound (abfd, info->stabsec); 1073 1.1 skrll if (reloc_size < 0) 1074 1.11 christos goto out2; 1075 1.3 christos reloc_vector = (arelent **) bfd_malloc (reloc_size); 1076 1.1 skrll if (reloc_vector == NULL && reloc_size != 0) 1077 1.11 christos goto out2; 1078 1.1 skrll reloc_count = bfd_canonicalize_reloc (abfd, info->stabsec, reloc_vector, 1079 1.1 skrll symbols); 1080 1.1 skrll if (reloc_count < 0) 1081 1.1 skrll { 1082 1.11 christos out3: 1083 1.10 christos free (reloc_vector); 1084 1.11 christos out2: 1085 1.11 christos free (info->strs); 1086 1.11 christos info->strs = NULL; 1087 1.11 christos out1: 1088 1.11 christos free (info->stabs); 1089 1.11 christos info->stabs = NULL; 1090 1.11 christos out: 1091 1.11 christos info->stabsec = NULL; 1092 1.10 christos return false; 1093 1.1 skrll } 1094 1.1 skrll if (reloc_count > 0) 1095 1.1 skrll { 1096 1.1 skrll arelent **pr; 1097 1.1 skrll 1098 1.1 skrll for (pr = reloc_vector; *pr != NULL; pr++) 1099 1.1 skrll { 1100 1.1 skrll arelent *r; 1101 1.1 skrll unsigned long val; 1102 1.1 skrll asymbol *sym; 1103 1.9 christos bfd_size_type octets; 1104 1.1 skrll 1105 1.1 skrll r = *pr; 1106 1.1 skrll /* Ignore R_*_NONE relocs. */ 1107 1.1 skrll if (r->howto->dst_mask == 0) 1108 1.1 skrll continue; 1109 1.1 skrll 1110 1.9 christos octets = r->address * bfd_octets_per_byte (abfd, NULL); 1111 1.1 skrll if (r->howto->rightshift != 0 1112 1.10 christos || bfd_get_reloc_size (r->howto) != 4 1113 1.1 skrll || r->howto->bitsize != 32 1114 1.1 skrll || r->howto->pc_relative 1115 1.1 skrll || r->howto->bitpos != 0 1116 1.9 christos || r->howto->dst_mask != 0xffffffff 1117 1.11 christos || octets > stabsize - 4) 1118 1.1 skrll { 1119 1.7 christos _bfd_error_handler 1120 1.8 christos (_("unsupported .stab relocation")); 1121 1.1 skrll bfd_set_error (bfd_error_invalid_operation); 1122 1.11 christos goto out3; 1123 1.1 skrll } 1124 1.1 skrll 1125 1.9 christos val = bfd_get_32 (abfd, info->stabs + octets); 1126 1.1 skrll val &= r->howto->src_mask; 1127 1.1 skrll sym = *r->sym_ptr_ptr; 1128 1.1 skrll val += sym->value + sym->section->vma + r->addend; 1129 1.9 christos bfd_put_32 (abfd, (bfd_vma) val, info->stabs + octets); 1130 1.1 skrll } 1131 1.1 skrll } 1132 1.1 skrll 1133 1.10 christos free (reloc_vector); 1134 1.1 skrll 1135 1.1 skrll /* First time through this function, build a table matching 1136 1.1 skrll function VM addresses to stabs, then sort based on starting 1137 1.1 skrll VM address. Do this in two passes: once to count how many 1138 1.1 skrll table entries we'll need, and a second to actually build the 1139 1.1 skrll table. */ 1140 1.1 skrll 1141 1.1 skrll info->indextablesize = 0; 1142 1.5 christos nul_fun = NULL; 1143 1.1 skrll for (stab = info->stabs; stab < info->stabs + stabsize; stab += STABSIZE) 1144 1.1 skrll { 1145 1.1 skrll if (stab[TYPEOFF] == (bfd_byte) N_SO) 1146 1.1 skrll { 1147 1.1 skrll /* if we did not see a function def, leave space for one. */ 1148 1.5 christos if (nul_fun != NULL) 1149 1.1 skrll ++info->indextablesize; 1150 1.1 skrll 1151 1.5 christos /* N_SO with null name indicates EOF */ 1152 1.5 christos if (bfd_get_32 (abfd, stab + STRDXOFF) == 0) 1153 1.5 christos nul_fun = NULL; 1154 1.5 christos else 1155 1.5 christos { 1156 1.5 christos nul_fun = stab; 1157 1.1 skrll 1158 1.5 christos /* two N_SO's in a row is a filename and directory. Skip */ 1159 1.5 christos if (stab + STABSIZE + TYPEOFF < info->stabs + stabsize 1160 1.5 christos && *(stab + STABSIZE + TYPEOFF) == (bfd_byte) N_SO) 1161 1.5 christos stab += STABSIZE; 1162 1.1 skrll } 1163 1.1 skrll } 1164 1.5 christos else if (stab[TYPEOFF] == (bfd_byte) N_FUN 1165 1.5 christos && bfd_get_32 (abfd, stab + STRDXOFF) != 0) 1166 1.1 skrll { 1167 1.5 christos nul_fun = NULL; 1168 1.1 skrll ++info->indextablesize; 1169 1.1 skrll } 1170 1.1 skrll } 1171 1.1 skrll 1172 1.5 christos if (nul_fun != NULL) 1173 1.1 skrll ++info->indextablesize; 1174 1.1 skrll 1175 1.1 skrll if (info->indextablesize == 0) 1176 1.11 christos { 1177 1.11 christos free (info->strs); 1178 1.11 christos info->strs = NULL; 1179 1.11 christos free (info->stabs); 1180 1.11 christos info->stabs = NULL; 1181 1.11 christos info->stabsec = NULL; 1182 1.11 christos return true; 1183 1.11 christos } 1184 1.1 skrll ++info->indextablesize; 1185 1.1 skrll 1186 1.1 skrll amt = info->indextablesize; 1187 1.1 skrll amt *= sizeof (struct indexentry); 1188 1.11 christos info->indextable = (struct indexentry *) bfd_malloc (amt); 1189 1.1 skrll if (info->indextable == NULL) 1190 1.11 christos goto out3; 1191 1.1 skrll 1192 1.1 skrll file_name = NULL; 1193 1.1 skrll directory_name = NULL; 1194 1.5 christos nul_fun = NULL; 1195 1.5 christos stroff = 0; 1196 1.1 skrll 1197 1.5 christos for (i = 0, stab = info->stabs, nul_str = str = info->strs; 1198 1.1 skrll i < info->indextablesize && stab < info->stabs + stabsize; 1199 1.1 skrll stab += STABSIZE) 1200 1.1 skrll { 1201 1.1 skrll switch (stab[TYPEOFF]) 1202 1.1 skrll { 1203 1.1 skrll case 0: 1204 1.1 skrll /* This is the first entry in a compilation unit. */ 1205 1.1 skrll if ((bfd_size_type) ((info->strs + strsize) - str) < stroff) 1206 1.1 skrll break; 1207 1.1 skrll str += stroff; 1208 1.1 skrll stroff = bfd_get_32 (abfd, stab + VALOFF); 1209 1.1 skrll break; 1210 1.1 skrll 1211 1.1 skrll case N_SO: 1212 1.1 skrll /* The main file name. */ 1213 1.1 skrll 1214 1.1 skrll /* The following code creates a new indextable entry with 1215 1.7 christos a NULL function name if there were no N_FUNs in a file. 1216 1.7 christos Note that a N_SO without a file name is an EOF and 1217 1.7 christos there could be 2 N_SO following it with the new filename 1218 1.7 christos and directory. */ 1219 1.5 christos if (nul_fun != NULL) 1220 1.1 skrll { 1221 1.5 christos info->indextable[i].val = bfd_get_32 (abfd, nul_fun + VALOFF); 1222 1.5 christos info->indextable[i].stab = nul_fun; 1223 1.5 christos info->indextable[i].str = nul_str; 1224 1.1 skrll info->indextable[i].directory_name = directory_name; 1225 1.1 skrll info->indextable[i].file_name = file_name; 1226 1.1 skrll info->indextable[i].function_name = NULL; 1227 1.9 christos info->indextable[i].idx = i; 1228 1.1 skrll ++i; 1229 1.1 skrll } 1230 1.1 skrll 1231 1.5 christos directory_name = NULL; 1232 1.1 skrll file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF); 1233 1.5 christos if (file_name == (char *) str) 1234 1.1 skrll { 1235 1.1 skrll file_name = NULL; 1236 1.5 christos nul_fun = NULL; 1237 1.1 skrll } 1238 1.1 skrll else 1239 1.1 skrll { 1240 1.5 christos nul_fun = stab; 1241 1.5 christos nul_str = str; 1242 1.9 christos if (file_name >= (char *) info->strs + strsize 1243 1.9 christos || file_name < (char *) str) 1244 1.5 christos file_name = NULL; 1245 1.5 christos if (stab + STABSIZE + TYPEOFF < info->stabs + stabsize 1246 1.5 christos && *(stab + STABSIZE + TYPEOFF) == (bfd_byte) N_SO) 1247 1.1 skrll { 1248 1.1 skrll /* Two consecutive N_SOs are a directory and a 1249 1.1 skrll file name. */ 1250 1.1 skrll stab += STABSIZE; 1251 1.1 skrll directory_name = file_name; 1252 1.1 skrll file_name = ((char *) str 1253 1.1 skrll + bfd_get_32 (abfd, stab + STRDXOFF)); 1254 1.9 christos if (file_name >= (char *) info->strs + strsize 1255 1.9 christos || file_name < (char *) str) 1256 1.5 christos file_name = NULL; 1257 1.1 skrll } 1258 1.1 skrll } 1259 1.1 skrll break; 1260 1.1 skrll 1261 1.1 skrll case N_SOL: 1262 1.1 skrll /* The name of an include file. */ 1263 1.1 skrll file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF); 1264 1.5 christos /* PR 17512: file: 0c680a1f. */ 1265 1.5 christos /* PR 17512: file: 5da8aec4. */ 1266 1.9 christos if (file_name >= (char *) info->strs + strsize 1267 1.9 christos || file_name < (char *) str) 1268 1.5 christos file_name = NULL; 1269 1.1 skrll break; 1270 1.1 skrll 1271 1.1 skrll case N_FUN: 1272 1.1 skrll /* A function name. */ 1273 1.5 christos function_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF); 1274 1.5 christos if (function_name == (char *) str) 1275 1.1 skrll continue; 1276 1.9 christos if (function_name >= (char *) info->strs + strsize 1277 1.9 christos || function_name < (char *) str) 1278 1.5 christos function_name = NULL; 1279 1.1 skrll 1280 1.5 christos nul_fun = NULL; 1281 1.1 skrll info->indextable[i].val = bfd_get_32 (abfd, stab + VALOFF); 1282 1.1 skrll info->indextable[i].stab = stab; 1283 1.1 skrll info->indextable[i].str = str; 1284 1.1 skrll info->indextable[i].directory_name = directory_name; 1285 1.1 skrll info->indextable[i].file_name = file_name; 1286 1.1 skrll info->indextable[i].function_name = function_name; 1287 1.9 christos info->indextable[i].idx = i; 1288 1.1 skrll ++i; 1289 1.1 skrll break; 1290 1.1 skrll } 1291 1.1 skrll } 1292 1.1 skrll 1293 1.5 christos if (nul_fun != NULL) 1294 1.1 skrll { 1295 1.5 christos info->indextable[i].val = bfd_get_32 (abfd, nul_fun + VALOFF); 1296 1.5 christos info->indextable[i].stab = nul_fun; 1297 1.5 christos info->indextable[i].str = nul_str; 1298 1.1 skrll info->indextable[i].directory_name = directory_name; 1299 1.1 skrll info->indextable[i].file_name = file_name; 1300 1.1 skrll info->indextable[i].function_name = NULL; 1301 1.9 christos info->indextable[i].idx = i; 1302 1.1 skrll ++i; 1303 1.1 skrll } 1304 1.1 skrll 1305 1.1 skrll info->indextable[i].val = (bfd_vma) -1; 1306 1.1 skrll info->indextable[i].stab = info->stabs + stabsize; 1307 1.1 skrll info->indextable[i].str = str; 1308 1.1 skrll info->indextable[i].directory_name = NULL; 1309 1.1 skrll info->indextable[i].file_name = NULL; 1310 1.1 skrll info->indextable[i].function_name = NULL; 1311 1.9 christos info->indextable[i].idx = i; 1312 1.1 skrll ++i; 1313 1.1 skrll 1314 1.1 skrll info->indextablesize = i; 1315 1.1 skrll qsort (info->indextable, (size_t) i, sizeof (struct indexentry), 1316 1.1 skrll cmpindexentry); 1317 1.1 skrll } 1318 1.1 skrll 1319 1.1 skrll /* We are passed a section relative offset. The offsets in the 1320 1.1 skrll stabs information are absolute. */ 1321 1.9 christos offset += bfd_section_vma (section); 1322 1.1 skrll 1323 1.1 skrll #ifdef ENABLE_CACHING 1324 1.1 skrll if (info->cached_indexentry != NULL 1325 1.1 skrll && offset >= info->cached_offset 1326 1.1 skrll && offset < (info->cached_indexentry + 1)->val) 1327 1.1 skrll { 1328 1.1 skrll stab = info->cached_stab; 1329 1.1 skrll indexentry = info->cached_indexentry; 1330 1.1 skrll file_name = info->cached_file_name; 1331 1.1 skrll } 1332 1.1 skrll else 1333 1.1 skrll #endif 1334 1.1 skrll { 1335 1.1 skrll long low, high; 1336 1.1 skrll long mid = -1; 1337 1.1 skrll 1338 1.1 skrll /* Cache non-existent or invalid. Do binary search on 1339 1.7 christos indextable. */ 1340 1.1 skrll indexentry = NULL; 1341 1.1 skrll 1342 1.1 skrll low = 0; 1343 1.1 skrll high = info->indextablesize - 1; 1344 1.1 skrll while (low != high) 1345 1.1 skrll { 1346 1.1 skrll mid = (high + low) / 2; 1347 1.1 skrll if (offset >= info->indextable[mid].val 1348 1.1 skrll && offset < info->indextable[mid + 1].val) 1349 1.1 skrll { 1350 1.1 skrll indexentry = &info->indextable[mid]; 1351 1.1 skrll break; 1352 1.1 skrll } 1353 1.1 skrll 1354 1.1 skrll if (info->indextable[mid].val > offset) 1355 1.1 skrll high = mid; 1356 1.1 skrll else 1357 1.1 skrll low = mid + 1; 1358 1.1 skrll } 1359 1.1 skrll 1360 1.1 skrll if (indexentry == NULL) 1361 1.10 christos return true; 1362 1.1 skrll 1363 1.1 skrll stab = indexentry->stab + STABSIZE; 1364 1.1 skrll file_name = indexentry->file_name; 1365 1.1 skrll } 1366 1.1 skrll 1367 1.1 skrll directory_name = indexentry->directory_name; 1368 1.1 skrll str = indexentry->str; 1369 1.1 skrll 1370 1.10 christos saw_line = false; 1371 1.10 christos saw_func = false; 1372 1.1 skrll for (; stab < (indexentry+1)->stab; stab += STABSIZE) 1373 1.1 skrll { 1374 1.10 christos bool done; 1375 1.1 skrll bfd_vma val; 1376 1.1 skrll 1377 1.10 christos done = false; 1378 1.1 skrll 1379 1.1 skrll switch (stab[TYPEOFF]) 1380 1.1 skrll { 1381 1.1 skrll case N_SOL: 1382 1.1 skrll /* The name of an include file. */ 1383 1.1 skrll val = bfd_get_32 (abfd, stab + VALOFF); 1384 1.1 skrll if (val <= offset) 1385 1.1 skrll { 1386 1.1 skrll file_name = (char *) str + bfd_get_32 (abfd, stab + STRDXOFF); 1387 1.9 christos if (file_name >= (char *) info->strs + strsize 1388 1.9 christos || file_name < (char *) str) 1389 1.5 christos file_name = NULL; 1390 1.1 skrll *pline = 0; 1391 1.1 skrll } 1392 1.1 skrll break; 1393 1.1 skrll 1394 1.1 skrll case N_SLINE: 1395 1.1 skrll case N_DSLINE: 1396 1.1 skrll case N_BSLINE: 1397 1.1 skrll /* A line number. If the function was specified, then the value 1398 1.1 skrll is relative to the start of the function. Otherwise, the 1399 1.1 skrll value is an absolute address. */ 1400 1.1 skrll val = ((indexentry->function_name ? indexentry->val : 0) 1401 1.1 skrll + bfd_get_32 (abfd, stab + VALOFF)); 1402 1.1 skrll /* If this line starts before our desired offset, or if it's 1403 1.1 skrll the first line we've been able to find, use it. The 1404 1.1 skrll !saw_line check works around a bug in GCC 2.95.3, which emits 1405 1.1 skrll the first N_SLINE late. */ 1406 1.1 skrll if (!saw_line || val <= offset) 1407 1.1 skrll { 1408 1.1 skrll *pline = bfd_get_16 (abfd, stab + DESCOFF); 1409 1.1 skrll 1410 1.1 skrll #ifdef ENABLE_CACHING 1411 1.1 skrll info->cached_stab = stab; 1412 1.1 skrll info->cached_offset = val; 1413 1.1 skrll info->cached_file_name = file_name; 1414 1.1 skrll info->cached_indexentry = indexentry; 1415 1.1 skrll #endif 1416 1.1 skrll } 1417 1.1 skrll if (val > offset) 1418 1.10 christos done = true; 1419 1.10 christos saw_line = true; 1420 1.1 skrll break; 1421 1.1 skrll 1422 1.1 skrll case N_FUN: 1423 1.1 skrll case N_SO: 1424 1.1 skrll if (saw_func || saw_line) 1425 1.10 christos done = true; 1426 1.10 christos saw_func = true; 1427 1.1 skrll break; 1428 1.1 skrll } 1429 1.1 skrll 1430 1.1 skrll if (done) 1431 1.1 skrll break; 1432 1.1 skrll } 1433 1.1 skrll 1434 1.10 christos *pfound = true; 1435 1.1 skrll 1436 1.1 skrll if (file_name == NULL || IS_ABSOLUTE_PATH (file_name) 1437 1.1 skrll || directory_name == NULL) 1438 1.1 skrll *pfilename = file_name; 1439 1.1 skrll else 1440 1.1 skrll { 1441 1.1 skrll size_t dirlen; 1442 1.1 skrll 1443 1.1 skrll dirlen = strlen (directory_name); 1444 1.1 skrll if (info->filename == NULL 1445 1.4 christos || filename_ncmp (info->filename, directory_name, dirlen) != 0 1446 1.4 christos || filename_cmp (info->filename + dirlen, file_name) != 0) 1447 1.1 skrll { 1448 1.1 skrll size_t len; 1449 1.1 skrll 1450 1.2 skrll /* Don't free info->filename here. objdump and other 1451 1.2 skrll apps keep a copy of a previously returned file name 1452 1.2 skrll pointer. */ 1453 1.1 skrll len = strlen (file_name) + 1; 1454 1.3 christos info->filename = (char *) bfd_alloc (abfd, dirlen + len); 1455 1.1 skrll if (info->filename == NULL) 1456 1.10 christos return false; 1457 1.1 skrll memcpy (info->filename, directory_name, dirlen); 1458 1.1 skrll memcpy (info->filename + dirlen, file_name, len); 1459 1.1 skrll } 1460 1.1 skrll 1461 1.1 skrll *pfilename = info->filename; 1462 1.1 skrll } 1463 1.1 skrll 1464 1.1 skrll if (indexentry->function_name != NULL) 1465 1.1 skrll { 1466 1.1 skrll char *s; 1467 1.1 skrll 1468 1.1 skrll /* This will typically be something like main:F(0,1), so we want 1469 1.7 christos to clobber the colon. It's OK to change the name, since the 1470 1.7 christos string is in our own local storage anyhow. */ 1471 1.1 skrll s = strchr (indexentry->function_name, ':'); 1472 1.1 skrll if (s != NULL) 1473 1.1 skrll *s = '\0'; 1474 1.1 skrll 1475 1.1 skrll *pfnname = indexentry->function_name; 1476 1.1 skrll } 1477 1.1 skrll 1478 1.10 christos return true; 1479 1.1 skrll } 1480 1.8 christos 1481 1.11 christos void 1482 1.11 christos _bfd_stab_cleanup (bfd *abfd ATTRIBUTE_UNUSED, void **pinfo) 1483 1.11 christos { 1484 1.11 christos struct stab_find_info *info = (struct stab_find_info *) *pinfo; 1485 1.11 christos if (info == NULL) 1486 1.11 christos return; 1487 1.11 christos 1488 1.11 christos free (info->indextable); 1489 1.11 christos free (info->strs); 1490 1.11 christos free (info->stabs); 1491 1.11 christos } 1492 1.11 christos 1493 1.8 christos long 1494 1.8 christos _bfd_nosymbols_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED, 1495 1.8 christos asymbol **location ATTRIBUTE_UNUSED) 1496 1.8 christos { 1497 1.8 christos return 0; 1498 1.8 christos } 1499 1.8 christos 1500 1.8 christos void 1501 1.8 christos _bfd_nosymbols_print_symbol (bfd *abfd ATTRIBUTE_UNUSED, 1502 1.8 christos void *afile ATTRIBUTE_UNUSED, 1503 1.8 christos asymbol *symbol ATTRIBUTE_UNUSED, 1504 1.8 christos bfd_print_symbol_type how ATTRIBUTE_UNUSED) 1505 1.8 christos { 1506 1.8 christos } 1507 1.8 christos 1508 1.8 christos void 1509 1.8 christos _bfd_nosymbols_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED, 1510 1.8 christos asymbol *sym ATTRIBUTE_UNUSED, 1511 1.8 christos symbol_info *ret ATTRIBUTE_UNUSED) 1512 1.8 christos { 1513 1.8 christos } 1514 1.8 christos 1515 1.8 christos const char * 1516 1.8 christos _bfd_nosymbols_get_symbol_version_string (bfd *abfd, 1517 1.8 christos asymbol *symbol ATTRIBUTE_UNUSED, 1518 1.10 christos bool base_p ATTRIBUTE_UNUSED, 1519 1.10 christos bool *hidden ATTRIBUTE_UNUSED) 1520 1.8 christos { 1521 1.8 christos return (const char *) _bfd_ptr_bfd_null_error (abfd); 1522 1.8 christos } 1523 1.8 christos 1524 1.10 christos bool 1525 1.8 christos _bfd_nosymbols_bfd_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED, 1526 1.8 christos const char *name ATTRIBUTE_UNUSED) 1527 1.8 christos { 1528 1.10 christos return false; 1529 1.8 christos } 1530 1.8 christos 1531 1.8 christos alent * 1532 1.8 christos _bfd_nosymbols_get_lineno (bfd *abfd, asymbol *sym ATTRIBUTE_UNUSED) 1533 1.8 christos { 1534 1.8 christos return (alent *) _bfd_ptr_bfd_null_error (abfd); 1535 1.8 christos } 1536 1.8 christos 1537 1.10 christos bool 1538 1.8 christos _bfd_nosymbols_find_nearest_line 1539 1.8 christos (bfd *abfd, 1540 1.8 christos asymbol **symbols ATTRIBUTE_UNUSED, 1541 1.8 christos asection *section ATTRIBUTE_UNUSED, 1542 1.8 christos bfd_vma offset ATTRIBUTE_UNUSED, 1543 1.8 christos const char **filename_ptr ATTRIBUTE_UNUSED, 1544 1.8 christos const char **functionname_ptr ATTRIBUTE_UNUSED, 1545 1.8 christos unsigned int *line_ptr ATTRIBUTE_UNUSED, 1546 1.8 christos unsigned int *discriminator_ptr ATTRIBUTE_UNUSED) 1547 1.8 christos { 1548 1.8 christos return _bfd_bool_bfd_false_error (abfd); 1549 1.8 christos } 1550 1.8 christos 1551 1.10 christos bool 1552 1.11 christos _bfd_nosymbols_find_nearest_line_with_alt 1553 1.11 christos (bfd *abfd, 1554 1.11 christos const char *alt_filename ATTRIBUTE_UNUSED, 1555 1.11 christos asymbol **symbols ATTRIBUTE_UNUSED, 1556 1.11 christos asection *section ATTRIBUTE_UNUSED, 1557 1.11 christos bfd_vma offset ATTRIBUTE_UNUSED, 1558 1.11 christos const char **filename_ptr ATTRIBUTE_UNUSED, 1559 1.11 christos const char **functionname_ptr ATTRIBUTE_UNUSED, 1560 1.11 christos unsigned int *line_ptr ATTRIBUTE_UNUSED, 1561 1.11 christos unsigned int *discriminator_ptr ATTRIBUTE_UNUSED) 1562 1.11 christos { 1563 1.11 christos return _bfd_bool_bfd_false_error (abfd); 1564 1.11 christos } 1565 1.11 christos 1566 1.11 christos bool 1567 1.8 christos _bfd_nosymbols_find_line (bfd *abfd, 1568 1.8 christos asymbol **symbols ATTRIBUTE_UNUSED, 1569 1.8 christos asymbol *symbol ATTRIBUTE_UNUSED, 1570 1.8 christos const char **filename_ptr ATTRIBUTE_UNUSED, 1571 1.8 christos unsigned int *line_ptr ATTRIBUTE_UNUSED) 1572 1.8 christos { 1573 1.8 christos return _bfd_bool_bfd_false_error (abfd); 1574 1.8 christos } 1575 1.8 christos 1576 1.10 christos bool 1577 1.8 christos _bfd_nosymbols_find_inliner_info 1578 1.8 christos (bfd *abfd, 1579 1.8 christos const char **filename_ptr ATTRIBUTE_UNUSED, 1580 1.8 christos const char **functionname_ptr ATTRIBUTE_UNUSED, 1581 1.8 christos unsigned int *line_ptr ATTRIBUTE_UNUSED) 1582 1.8 christos { 1583 1.8 christos return _bfd_bool_bfd_false_error (abfd); 1584 1.8 christos } 1585 1.8 christos 1586 1.8 christos asymbol * 1587 1.11 christos _bfd_nosymbols_bfd_make_debug_symbol (bfd *abfd) 1588 1.8 christos { 1589 1.8 christos return (asymbol *) _bfd_ptr_bfd_null_error (abfd); 1590 1.8 christos } 1591 1.8 christos 1592 1.8 christos long 1593 1.8 christos _bfd_nosymbols_read_minisymbols (bfd *abfd, 1594 1.10 christos bool dynamic ATTRIBUTE_UNUSED, 1595 1.8 christos void **minisymsp ATTRIBUTE_UNUSED, 1596 1.8 christos unsigned int *sizep ATTRIBUTE_UNUSED) 1597 1.8 christos { 1598 1.8 christos return _bfd_long_bfd_n1_error (abfd); 1599 1.8 christos } 1600 1.8 christos 1601 1.8 christos asymbol * 1602 1.8 christos _bfd_nosymbols_minisymbol_to_symbol (bfd *abfd, 1603 1.10 christos bool dynamic ATTRIBUTE_UNUSED, 1604 1.8 christos const void *minisym ATTRIBUTE_UNUSED, 1605 1.8 christos asymbol *sym ATTRIBUTE_UNUSED) 1606 1.8 christos { 1607 1.8 christos return (asymbol *) _bfd_ptr_bfd_null_error (abfd); 1608 1.8 christos } 1609 1.8 christos 1610 1.8 christos long 1611 1.8 christos _bfd_nodynamic_get_synthetic_symtab (bfd *abfd, 1612 1.8 christos long symcount ATTRIBUTE_UNUSED, 1613 1.8 christos asymbol **syms ATTRIBUTE_UNUSED, 1614 1.8 christos long dynsymcount ATTRIBUTE_UNUSED, 1615 1.8 christos asymbol **dynsyms ATTRIBUTE_UNUSED, 1616 1.8 christos asymbol **ret ATTRIBUTE_UNUSED) 1617 1.8 christos { 1618 1.8 christos return _bfd_long_bfd_n1_error (abfd); 1619 1.8 christos } 1620