Make gimple_build_vector take a tree_vector_builder
[official-gcc.git] / libbacktrace / xcoff.c
blobf84bf268e6c053dc1603c81e09081f1d4d9e25ab
1 /* xcoff.c -- Get debug data from an XCOFF file for backtraces.
2 Copyright (C) 2012-2017 Free Software Foundation, Inc.
3 Adapted from elf.c.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
9 (1) Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
12 (2) Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the
15 distribution.
17 (3) The name of the author may not be used to
18 endorse or promote products derived from this software without
19 specific prior written permission.
21 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE. */
33 #include "config.h"
35 #include <errno.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <sys/types.h>
40 #ifdef HAVE_LOADQUERY
41 #include <sys/ldr.h>
42 #endif
44 #include "backtrace.h"
45 #include "internal.h"
47 /* The configure script must tell us whether we are 32-bit or 64-bit
48 XCOFF. We could make this code test and support either possibility,
49 but there is no point. This code only works for the currently
50 running executable, which means that we know the XCOFF mode at
51 configure time. */
53 #if BACKTRACE_XCOFF_SIZE != 32 && BACKTRACE_XCOFF_SIZE != 64
54 #error "Unknown BACKTRACE_XCOFF_SIZE"
55 #endif
57 /* XCOFF file header. */
59 #if BACKTRACE_XCOFF_SIZE == 32
61 typedef struct {
62 uint16_t f_magic;
63 uint16_t f_nscns;
64 uint32_t f_timdat;
65 uint32_t f_symptr;
66 uint32_t f_nsyms;
67 uint16_t f_opthdr;
68 uint16_t f_flags;
69 } b_xcoff_filhdr;
71 #define XCOFF_MAGIC 0737
73 #else /* BACKTRACE_XCOFF_SIZE != 32 */
75 typedef struct {
76 uint16_t f_magic;
77 uint16_t f_nscns;
78 uint32_t f_timdat;
79 uint64_t f_symptr;
80 uint16_t f_opthdr;
81 uint16_t f_flags;
82 uint32_t f_nsyms;
83 } b_xcoff_filhdr;
85 #define XCOFF_MAGIC 0767
87 #endif /* BACKTRACE_XCOFF_SIZE != 32 */
89 #define F_SHROBJ 0x2000 /* File is a shared object. */
91 /* XCOFF section header. */
93 #if BACKTRACE_XCOFF_SIZE == 32
95 typedef struct {
96 char s_name[8];
97 uint32_t s_paddr;
98 uint32_t s_vaddr;
99 uint32_t s_size;
100 uint32_t s_scnptr;
101 uint32_t s_relptr;
102 uint32_t s_lnnoptr;
103 uint16_t s_nreloc;
104 uint16_t s_nlnno;
105 uint32_t s_flags;
106 } b_xcoff_scnhdr;
108 #define _OVERFLOW_MARKER 65535
110 #else /* BACKTRACE_XCOFF_SIZE != 32 */
112 typedef struct {
113 char name[8];
114 uint64_t s_paddr;
115 uint64_t s_vaddr;
116 uint64_t s_size;
117 uint64_t s_scnptr;
118 uint64_t s_relptr;
119 uint64_t s_lnnoptr;
120 uint32_t s_nreloc;
121 uint32_t s_nlnno;
122 uint32_t s_flags;
123 } b_xcoff_scnhdr;
125 #endif /* BACKTRACE_XCOFF_SIZE != 32 */
127 #define STYP_DWARF 0x10 /* DWARF debugging section. */
128 #define STYP_TEXT 0x20 /* Executable text (code) section. */
129 #define STYP_OVRFLO 0x8000 /* Line-number field overflow section. */
131 #define SSUBTYP_DWINFO 0x10000 /* DWARF info section. */
132 #define SSUBTYP_DWLINE 0x20000 /* DWARF line-number section. */
133 #define SSUBTYP_DWARNGE 0x50000 /* DWARF aranges section. */
134 #define SSUBTYP_DWABREV 0x60000 /* DWARF abbreviation section. */
135 #define SSUBTYP_DWSTR 0x70000 /* DWARF strings section. */
137 /* XCOFF symbol. */
139 #define SYMNMLEN 8
141 #if BACKTRACE_XCOFF_SIZE == 32
143 typedef struct {
144 union {
145 char _name[SYMNMLEN];
146 struct {
147 uint32_t _zeroes;
148 uint32_t _offset;
149 } _s;
150 } _u;
151 #define n_name _u._name
152 #define n_zeroes _u._s._zeroes
153 #define n_offset_ _u._s._offset
155 uint32_t n_value;
156 int16_t n_scnum;
157 uint16_t n_type;
158 uint8_t n_sclass;
159 uint8_t n_numaux;
160 } __attribute__ ((packed)) b_xcoff_syment;
162 #else /* BACKTRACE_XCOFF_SIZE != 32 */
164 typedef struct {
165 uint64_t n_value;
166 uint32_t n_offset_;
167 int16_t n_scnum;
168 uint16_t n_type;
169 uint8_t n_sclass;
170 uint8_t n_numaux;
171 } __attribute__ ((packed)) b_xcoff_syment;
173 #endif /* BACKTRACE_XCOFF_SIZE != 32 */
175 #define SYMESZ 18
177 #define C_EXT 2 /* External symbol. */
178 #define C_FCN 101 /* Beginning or end of function. */
179 #define C_FILE 103 /* Source file name. */
180 #define C_HIDEXT 107 /* Unnamed external symbol. */
181 #define C_BINCL 108 /* Beginning of include file. */
182 #define C_EINCL 109 /* End of include file. */
183 #define C_WEAKEXT 111 /* Weak external symbol. */
185 #define ISFCN(x) ((x) & 0x0020)
187 /* XCOFF AUX entry. */
189 #define AUXESZ 18
190 #define FILNMLEN 14
192 typedef union {
193 #if BACKTRACE_XCOFF_SIZE == 32
194 struct {
195 uint16_t pad;
196 uint16_t x_lnnohi;
197 uint16_t x_lnno;
198 } x_block;
199 #else
200 struct {
201 uint32_t x_lnno;
202 } x_block;
203 #endif
204 union {
205 char x_fname[FILNMLEN];
206 struct {
207 uint32_t x_zeroes;
208 uint32_t x_offset;
209 char pad[FILNMLEN-8];
210 uint8_t x_ftype;
211 } _x;
212 } x_file;
213 #if BACKTRACE_XCOFF_SIZE == 32
214 struct {
215 uint32_t x_exptr;
216 uint32_t x_fsize;
217 uint32_t x_lnnoptr;
218 uint32_t x_endndx;
219 } x_fcn;
220 #else
221 struct {
222 uint64_t x_lnnoptr;
223 uint32_t x_fsize;
224 uint32_t x_endndx;
225 } x_fcn;
226 #endif
227 struct {
228 uint8_t pad[AUXESZ-1];
229 uint8_t x_auxtype;
230 } x_auxtype;
231 } __attribute__ ((packed)) b_xcoff_auxent;
233 /* XCOFF line number entry. */
235 #if BACKTRACE_XCOFF_SIZE == 32
237 typedef struct {
238 union {
239 uint32_t l_symndx;
240 uint32_t l_paddr;
241 } l_addr;
242 uint16_t l_lnno;
243 } b_xcoff_lineno;
245 #define LINESZ 6
247 #else /* BACKTRACE_XCOFF_SIZE != 32 */
249 typedef struct {
250 union {
251 uint32_t l_symndx;
252 uint64_t l_paddr;
253 } l_addr;
254 uint32_t l_lnno;
255 } b_xcoff_lineno;
257 #define LINESZ 12
259 #endif /* BACKTRACE_XCOFF_SIZE != 32 */
261 #if BACKTRACE_XCOFF_SIZE == 32
262 #define XCOFF_AIX_TEXTBASE 0x10000000u
263 #else
264 #define XCOFF_AIX_TEXTBASE 0x100000000ul
265 #endif
267 /* AIX big archive fixed-length header. */
269 #define AIAMAGBIG "<bigaf>\n"
271 typedef struct {
272 char fl_magic[8]; /* Archive magic string. */
273 char fl_memoff[20]; /* Offset to member table. */
274 char fl_gstoff[20]; /* Offset to global symbol table. */
275 char fl_gst64off[20]; /* Offset to global symbol table for 64-bit objects. */
276 char fl_fstmoff[20]; /* Offset to first archive member. */
277 char fl_freeoff[20]; /* Offset to first member on free list. */
278 } b_ar_fl_hdr;
280 /* AIX big archive file member header. */
282 typedef struct {
283 char ar_size[20]; /* File member size - decimal. */
284 char ar_nxtmem[20]; /* Next member offset - decimal. */
285 char ar_prvmem[20]; /* Previous member offset - decimal. */
286 char ar_date[12]; /* File member date - decimal. */
287 char ar_uid[12]; /* File member userid - decimal. */
288 char ar_gid[12]; /* File member group id - decimal. */
289 char ar_mode[12]; /* File member mode - octal. */
290 char ar_namlen[4]; /* File member name length - decimal. */
291 char ar_name[2]; /* Start of member name. */
292 } b_ar_hdr;
295 /* Information we keep for an XCOFF symbol. */
297 struct xcoff_symbol
299 /* The name of the symbol. */
300 const char *name;
301 /* The address of the symbol. */
302 uintptr_t address;
303 /* The size of the symbol. */
304 size_t size;
307 /* Information to pass to xcoff_syminfo. */
309 struct xcoff_syminfo_data
311 /* Symbols for the next module. */
312 struct xcoff_syminfo_data *next;
313 /* The XCOFF symbols, sorted by address. */
314 struct xcoff_symbol *symbols;
315 /* The number of symbols. */
316 size_t count;
319 /* Information about an include file. */
321 struct xcoff_incl
323 /* File name. */
324 const char *filename;
325 /* Offset to first line number from the include file. */
326 uintptr_t begin;
327 /* Offset to last line number from the include file. */
328 uintptr_t end;
331 /* A growable vector of include files information. */
333 struct xcoff_incl_vector
335 /* Memory. This is an array of struct xcoff_incl. */
336 struct backtrace_vector vec;
337 /* Number of include files. */
338 size_t count;
341 /* Map a single PC value to a file/function/line. */
343 struct xcoff_line
345 /* PC. */
346 uintptr_t pc;
347 /* File name. Many entries in the array are expected to point to
348 the same file name. */
349 const char *filename;
350 /* Function name. */
351 const char *function;
352 /* Line number. */
353 int lineno;
356 /* A growable vector of line number information. This is used while
357 reading the line numbers. */
359 struct xcoff_line_vector
361 /* Memory. This is an array of struct xcoff_line. */
362 struct backtrace_vector vec;
363 /* Number of valid mappings. */
364 size_t count;
367 /* The information we need to map a PC to a file and line. */
369 struct xcoff_fileline_data
371 /* The data for the next file we know about. */
372 struct xcoff_fileline_data *next;
373 /* Line number information. */
374 struct xcoff_line_vector vec;
377 /* An index of DWARF sections we care about. */
379 enum dwarf_section
381 DWSECT_INFO,
382 DWSECT_LINE,
383 DWSECT_ABBREV,
384 DWSECT_RANGES,
385 DWSECT_STR,
386 DWSECT_MAX
389 /* Information we gather for the DWARF sections we care about. */
391 struct dwsect_info
393 /* Section file offset. */
394 off_t offset;
395 /* Section size. */
396 size_t size;
397 /* Section contents, after read from file. */
398 const unsigned char *data;
401 /* A dummy callback function used when we can't find any debug info. */
403 static int
404 xcoff_nodebug (struct backtrace_state *state ATTRIBUTE_UNUSED,
405 uintptr_t pc ATTRIBUTE_UNUSED,
406 backtrace_full_callback callback ATTRIBUTE_UNUSED,
407 backtrace_error_callback error_callback, void *data)
409 error_callback (data, "no debug info in XCOFF executable", -1);
410 return 0;
413 /* A dummy callback function used when we can't find a symbol
414 table. */
416 static void
417 xcoff_nosyms (struct backtrace_state *state ATTRIBUTE_UNUSED,
418 uintptr_t addr ATTRIBUTE_UNUSED,
419 backtrace_syminfo_callback callback ATTRIBUTE_UNUSED,
420 backtrace_error_callback error_callback, void *data)
422 error_callback (data, "no symbol table in XCOFF executable", -1);
425 /* Compare struct xcoff_symbol for qsort. */
427 static int
428 xcoff_symbol_compare (const void *v1, const void *v2)
430 const struct xcoff_symbol *e1 = (const struct xcoff_symbol *) v1;
431 const struct xcoff_symbol *e2 = (const struct xcoff_symbol *) v2;
433 if (e1->address < e2->address)
434 return -1;
435 else if (e1->address > e2->address)
436 return 1;
437 else
438 return 0;
441 /* Compare an ADDR against an xcoff_symbol for bsearch. */
443 static int
444 xcoff_symbol_search (const void *vkey, const void *ventry)
446 const uintptr_t *key = (const uintptr_t *) vkey;
447 const struct xcoff_symbol *entry = (const struct xcoff_symbol *) ventry;
448 uintptr_t addr;
450 addr = *key;
451 if (addr < entry->address)
452 return -1;
453 else if ((entry->size == 0 && addr > entry->address)
454 || (entry->size > 0 && addr >= entry->address + entry->size))
455 return 1;
456 else
457 return 0;
460 /* Add XDATA to the list in STATE. */
462 static void
463 xcoff_add_syminfo_data (struct backtrace_state *state,
464 struct xcoff_syminfo_data *xdata)
466 if (!state->threaded)
468 struct xcoff_syminfo_data **pp;
470 for (pp = (struct xcoff_syminfo_data **) (void *) &state->syminfo_data;
471 *pp != NULL;
472 pp = &(*pp)->next)
474 *pp = xdata;
476 else
478 while (1)
480 struct xcoff_syminfo_data **pp;
482 pp = (struct xcoff_syminfo_data **) (void *) &state->syminfo_data;
484 while (1)
486 struct xcoff_syminfo_data *p;
488 p = backtrace_atomic_load_pointer (pp);
490 if (p == NULL)
491 break;
493 pp = &p->next;
496 if (__sync_bool_compare_and_swap (pp, NULL, xdata))
497 break;
502 /* Return the symbol name and value for an ADDR. */
504 static void
505 xcoff_syminfo (struct backtrace_state *state ATTRIBUTE_UNUSED, uintptr_t addr,
506 backtrace_syminfo_callback callback,
507 backtrace_error_callback error_callback ATTRIBUTE_UNUSED,
508 void *data)
510 struct xcoff_syminfo_data *edata;
511 struct xcoff_symbol *sym = NULL;
513 if (!state->threaded)
515 for (edata = (struct xcoff_syminfo_data *) state->syminfo_data;
516 edata != NULL;
517 edata = edata->next)
519 sym = ((struct xcoff_symbol *)
520 bsearch (&addr, edata->symbols, edata->count,
521 sizeof (struct xcoff_symbol), xcoff_symbol_search));
522 if (sym != NULL)
523 break;
526 else
528 struct xcoff_syminfo_data **pp;
530 pp = (struct xcoff_syminfo_data **) (void *) &state->syminfo_data;
531 while (1)
533 edata = backtrace_atomic_load_pointer (pp);
534 if (edata == NULL)
535 break;
537 sym = ((struct xcoff_symbol *)
538 bsearch (&addr, edata->symbols, edata->count,
539 sizeof (struct xcoff_symbol), xcoff_symbol_search));
540 if (sym != NULL)
541 break;
543 pp = &edata->next;
547 if (sym == NULL)
548 callback (data, addr, NULL, 0, 0);
549 else
550 callback (data, addr, sym->name, sym->address, sym->size);
553 /* Return the name of an XCOFF symbol. */
555 static const char *
556 xcoff_symname (const b_xcoff_syment *asym,
557 const unsigned char *strtab, size_t strtab_size)
559 #if BACKTRACE_XCOFF_SIZE == 32
560 if (asym->n_zeroes != 0)
562 /* Make a copy as we will release the symtab view. */
563 char name[SYMNMLEN+1];
564 strncpy (name, asym->n_name, SYMNMLEN);
565 name[SYMNMLEN] = '\0';
566 return strdup (name);
568 #endif
569 if (asym->n_sclass & 0x80)
570 return NULL; /* .debug */
571 if (asym->n_offset_ >= strtab_size)
572 return NULL;
573 return (const char *) strtab + asym->n_offset_;
576 /* Initialize the symbol table info for xcoff_syminfo. */
578 static int
579 xcoff_initialize_syminfo (struct backtrace_state *state,
580 uintptr_t base_address,
581 const b_xcoff_scnhdr *sects,
582 const b_xcoff_syment *syms, size_t nsyms,
583 const unsigned char *strtab, size_t strtab_size,
584 backtrace_error_callback error_callback, void *data,
585 struct xcoff_syminfo_data *sdata)
587 size_t xcoff_symbol_count;
588 size_t xcoff_symbol_size;
589 struct xcoff_symbol *xcoff_symbols;
590 size_t i;
591 unsigned int j;
593 /* We only care about function symbols. Count them. */
594 xcoff_symbol_count = 0;
595 for (i = 0; i < nsyms; ++i)
597 const b_xcoff_syment *asym = &syms[i];
598 if ((asym->n_sclass == C_EXT || asym->n_sclass == C_HIDEXT
599 || asym->n_sclass == C_WEAKEXT)
600 && ISFCN (asym->n_type) && asym->n_numaux > 0 && asym->n_scnum > 0)
601 ++xcoff_symbol_count;
603 i += asym->n_numaux;
606 xcoff_symbol_size = xcoff_symbol_count * sizeof (struct xcoff_symbol);
607 xcoff_symbols = ((struct xcoff_symbol *)
608 backtrace_alloc (state, xcoff_symbol_size, error_callback,
609 data));
610 if (xcoff_symbols == NULL)
611 return 0;
613 j = 0;
614 for (i = 0; i < nsyms; ++i)
616 const b_xcoff_syment *asym = &syms[i];
617 if ((asym->n_sclass == C_EXT || asym->n_sclass == C_HIDEXT
618 || asym->n_sclass == C_WEAKEXT)
619 && ISFCN (asym->n_type) && asym->n_numaux > 0 && asym->n_scnum > 0)
621 const b_xcoff_auxent *aux = (const b_xcoff_auxent *) (asym + 1);
622 xcoff_symbols[j].name = xcoff_symname (asym, strtab, strtab_size);
623 xcoff_symbols[j].address = base_address + asym->n_value
624 - sects[asym->n_scnum - 1].s_paddr;
625 /* x_fsize will be 0 if there is no debug information. */
626 xcoff_symbols[j].size = aux->x_fcn.x_fsize;
627 ++j;
630 i += asym->n_numaux;
633 backtrace_qsort (xcoff_symbols, xcoff_symbol_count,
634 sizeof (struct xcoff_symbol), xcoff_symbol_compare);
636 sdata->next = NULL;
637 sdata->symbols = xcoff_symbols;
638 sdata->count = xcoff_symbol_count;
640 return 1;
643 /* Compare struct xcoff_line for qsort. */
645 static int
646 xcoff_line_compare (const void *v1, const void *v2)
648 const struct xcoff_line *ln1 = (const struct xcoff_line *) v1;
649 const struct xcoff_line *ln2 = (const struct xcoff_line *) v2;
651 if (ln1->pc < ln2->pc)
652 return -1;
653 else if (ln1->pc > ln2->pc)
654 return 1;
655 else
656 return 0;
659 /* Find a PC in a line vector. We always allocate an extra entry at
660 the end of the lines vector, so that this routine can safely look
661 at the next entry. */
663 static int
664 xcoff_line_search (const void *vkey, const void *ventry)
666 const uintptr_t *key = (const uintptr_t *) vkey;
667 const struct xcoff_line *entry = (const struct xcoff_line *) ventry;
668 uintptr_t pc;
670 pc = *key;
671 if (pc < entry->pc)
672 return -1;
673 else if ((entry + 1)->pc == (uintptr_t) -1 || pc >= (entry + 1)->pc)
674 return 1;
675 else
676 return 0;
679 /* Look for a PC in the line vector for one module. On success,
680 call CALLBACK and return whatever it returns. On error, call
681 ERROR_CALLBACK and return 0. Sets *FOUND to 1 if the PC is found,
682 0 if not. */
684 static int
685 xcoff_lookup_pc (struct backtrace_state *state ATTRIBUTE_UNUSED,
686 struct xcoff_fileline_data *fdata, uintptr_t pc,
687 backtrace_full_callback callback,
688 backtrace_error_callback error_callback ATTRIBUTE_UNUSED,
689 void *data, int *found)
691 const struct xcoff_line *ln;
692 const char *function;
694 *found = 1;
696 ln = (struct xcoff_line *) bsearch (&pc, fdata->vec.vec.base,
697 fdata->vec.count,
698 sizeof (struct xcoff_line),
699 xcoff_line_search);
700 if (ln == NULL)
702 *found = 0;
703 return 0;
706 function = ln->function;
707 /* AIX prepends a '.' to function entry points, remove it. */
708 if (*function == '.')
709 ++function;
710 return callback (data, pc, ln->filename, ln->lineno, function);
713 /* Return the file/line information for a PC using the XCOFF lineno
714 mapping we built earlier. */
716 static int
717 xcoff_fileline (struct backtrace_state *state, uintptr_t pc,
718 backtrace_full_callback callback,
719 backtrace_error_callback error_callback, void *data)
722 struct xcoff_fileline_data *fdata;
723 int found;
724 int ret;
726 if (!state->threaded)
728 for (fdata = (struct xcoff_fileline_data *) state->fileline_data;
729 fdata != NULL;
730 fdata = fdata->next)
732 ret = xcoff_lookup_pc (state, fdata, pc, callback, error_callback,
733 data, &found);
734 if (ret != 0 || found)
735 return ret;
738 else
740 struct xcoff_fileline_data **pp;
742 pp = (struct xcoff_fileline_data **) (void *) &state->fileline_data;
743 while (1)
745 fdata = backtrace_atomic_load_pointer (pp);
746 if (fdata == NULL)
747 break;
749 ret = xcoff_lookup_pc (state, fdata, pc, callback, error_callback,
750 data, &found);
751 if (ret != 0 || found)
752 return ret;
754 pp = &fdata->next;
758 /* FIXME: See if any libraries have been dlopen'ed. */
760 return callback (data, pc, NULL, 0, NULL);
763 /* Add a new mapping to the vector of line mappings that we are
764 building. Returns 1 on success, 0 on failure. */
766 static int
767 xcoff_add_line (struct backtrace_state *state, uintptr_t pc,
768 const char *filename, const char *function, uint32_t lnno,
769 backtrace_error_callback error_callback, void *data,
770 struct xcoff_line_vector *vec)
772 struct xcoff_line *ln;
774 ln = ((struct xcoff_line *)
775 backtrace_vector_grow (state, sizeof (struct xcoff_line),
776 error_callback, data, &vec->vec));
777 if (ln == NULL)
778 return 0;
780 ln->pc = pc;
781 ln->filename = filename;
782 ln->function = function;
783 ln->lineno = lnno;
785 ++vec->count;
787 return 1;
790 /* Add the line number entries for a function to the line vector. */
792 static int
793 xcoff_process_linenos (struct backtrace_state *state, uintptr_t base_address,
794 const b_xcoff_syment *fsym, const char *filename,
795 const b_xcoff_scnhdr *sects,
796 const unsigned char *strtab, size_t strtab_size,
797 uint32_t fcn_lnno, struct xcoff_incl_vector *vec,
798 struct xcoff_line_vector *lvec,
799 const unsigned char *linenos, size_t linenos_size,
800 uintptr_t lnnoptr0,
801 backtrace_error_callback error_callback, void *data)
803 const b_xcoff_auxent *aux;
804 const b_xcoff_lineno *lineno;
805 const unsigned char *lineptr;
806 const char *function;
807 struct xcoff_incl *incl = NULL;
808 uintptr_t lnnoptr;
809 uintptr_t pc;
810 uint32_t lnno;
811 int begincl;
812 size_t i;
814 aux = (const b_xcoff_auxent *) (fsym + 1);
815 lnnoptr = aux->x_fcn.x_lnnoptr;
817 if (lnnoptr < lnnoptr0 || lnnoptr + LINESZ > lnnoptr0 + linenos_size)
818 return 0;
820 function = xcoff_symname (fsym, strtab, strtab_size);
821 if (function == NULL)
822 return 0;
824 /* Skip first entry that points to symtab. */
826 lnnoptr += LINESZ;
828 lineptr = linenos + (lnnoptr - lnnoptr0);
830 begincl = -1;
831 while (lineptr + LINESZ <= linenos + linenos_size)
833 lineno = (const b_xcoff_lineno *) lineptr;
835 lnno = lineno->l_lnno;
836 if (lnno == 0)
837 break;
839 /* If part of a function other than the beginning comes from an
840 include file, the line numbers are absolute, rather than
841 relative to the beginning of the function. */
842 for (i = 0; i < vec->count; ++i)
844 incl = (struct xcoff_incl *) vec->vec.base + i;
845 if (incl->begin <= lnnoptr && lnnoptr <= incl->end)
846 break;
848 if (begincl == -1)
849 begincl = (i < vec->count);
850 if (i < vec->count)
852 filename = incl->filename;
853 if (begincl == 1)
854 lnno += fcn_lnno - 1;
856 else
857 lnno += fcn_lnno - 1;
859 pc = base_address + lineno->l_addr.l_paddr
860 - sects[fsym->n_scnum - 1].s_paddr;
861 xcoff_add_line (state, pc, filename, function, lnno, error_callback,
862 data, lvec);
864 lnnoptr += LINESZ;
865 lineptr += LINESZ;
868 return 1;
871 /* Initialize the line vector info for xcoff_fileline. */
873 static int
874 xcoff_initialize_fileline (struct backtrace_state *state,
875 uintptr_t base_address,
876 const b_xcoff_scnhdr *sects,
877 const b_xcoff_syment *syms, size_t nsyms,
878 const unsigned char *strtab, size_t strtab_size,
879 const unsigned char *linenos, size_t linenos_size,
880 uint64_t lnnoptr0,
881 backtrace_error_callback error_callback, void *data)
883 struct xcoff_fileline_data *fdata;
884 struct xcoff_incl_vector vec;
885 struct xcoff_line *ln;
886 const b_xcoff_syment *fsym;
887 const b_xcoff_auxent *aux;
888 const char *filename;
889 const char *name;
890 struct xcoff_incl *incl;
891 uintptr_t begin, end;
892 uintptr_t lnno;
893 size_t i;
895 fdata = ((struct xcoff_fileline_data *)
896 backtrace_alloc (state, sizeof (struct xcoff_fileline_data),
897 error_callback, data));
898 if (fdata == NULL)
899 return 0;
901 memset (fdata, 0, sizeof *fdata);
902 memset (&vec, 0, sizeof vec);
904 /* Process include files first. */
906 begin = 0;
907 for (i = 0; i < nsyms; ++i)
909 const b_xcoff_syment *asym = &syms[i];
911 switch (asym->n_sclass)
913 case C_BINCL:
914 begin = asym->n_value;
915 break;
917 case C_EINCL:
918 if (begin == 0)
919 break;
920 end = asym->n_value;
921 incl = ((struct xcoff_incl *)
922 backtrace_vector_grow (state, sizeof (struct xcoff_incl),
923 error_callback, data, &vec.vec));
924 if (incl != NULL)
926 incl->filename = xcoff_symname (asym, strtab, strtab_size);
927 incl->begin = begin;
928 incl->end = end;
929 ++vec.count;
931 begin = 0;
932 break;
935 i += asym->n_numaux;
938 filename = NULL;
939 fsym = NULL;
940 for (i = 0; i < nsyms; ++i)
942 const b_xcoff_syment *asym = &syms[i];
944 switch (asym->n_sclass)
946 case C_FILE:
947 filename = xcoff_symname (asym, strtab, strtab_size);
948 if (filename == NULL)
949 break;
951 /* If the file auxiliary entry is not used, the symbol name is
952 the name of the source file. If the file auxiliary entry is
953 used, then the symbol name should be .file, and the first
954 file auxiliary entry (by convention) contains the source
955 file name. */
957 if (asym->n_numaux > 0 && !strcmp (filename, ".file"))
959 aux = (const b_xcoff_auxent *) (asym + 1);
960 if (aux->x_file._x.x_zeroes != 0)
962 /* Make a copy as we will release the symtab view. */
963 char name[FILNMLEN+1];
964 strncpy (name, aux->x_file.x_fname, FILNMLEN);
965 name[FILNMLEN] = '\0';
966 filename = strdup (name);
968 else if (aux->x_file._x.x_offset < strtab_size)
969 filename = (const char *) strtab + aux->x_file._x.x_offset;
970 else
971 filename = NULL;
973 break;
975 case C_EXT:
976 case C_HIDEXT:
977 case C_WEAKEXT:
978 fsym = NULL;
979 if (!ISFCN (asym->n_type) || asym->n_numaux == 0)
980 break;
981 if (filename == NULL)
982 break;
983 fsym = asym;
984 break;
986 case C_FCN:
987 if (asym->n_numaux == 0)
988 break;
989 if (fsym == NULL)
990 break;
991 name = xcoff_symname (asym, strtab, strtab_size);
992 if (name == NULL)
993 break;
994 aux = (const b_xcoff_auxent *) (asym + 1);
995 #if BACKTRACE_XCOFF_SIZE == 32
996 lnno = (uint32_t) aux->x_block.x_lnnohi << 16
997 | aux->x_block.x_lnno;
998 #else
999 lnno = aux->x_block.x_lnno;
1000 #endif
1001 if (!strcmp (name, ".bf"))
1003 xcoff_process_linenos (state, base_address, fsym, filename,
1004 sects, strtab, strtab_size, lnno, &vec,
1005 &fdata->vec, linenos, linenos_size,
1006 lnnoptr0, error_callback, data);
1008 else if (!strcmp (name, ".ef"))
1010 fsym = NULL;
1012 break;
1015 i += asym->n_numaux;
1018 /* Allocate one extra entry at the end. */
1019 ln = ((struct xcoff_line *)
1020 backtrace_vector_grow (state, sizeof (struct xcoff_line),
1021 error_callback, data, &fdata->vec.vec));
1022 if (ln == NULL)
1023 goto fail;
1024 ln->pc = (uintptr_t) -1;
1025 ln->filename = NULL;
1026 ln->function = NULL;
1027 ln->lineno = 0;
1029 if (!backtrace_vector_release (state, &fdata->vec.vec, error_callback, data))
1030 goto fail;
1032 backtrace_qsort (fdata->vec.vec.base, fdata->vec.count,
1033 sizeof (struct xcoff_line), xcoff_line_compare);
1035 if (!state->threaded)
1037 struct xcoff_fileline_data **pp;
1039 for (pp = (struct xcoff_fileline_data **) (void *) &state->fileline_data;
1040 *pp != NULL;
1041 pp = &(*pp)->next)
1043 *pp = fdata;
1045 else
1047 while (1)
1049 struct xcoff_fileline_data **pp;
1051 pp = (struct xcoff_fileline_data **) (void *) &state->fileline_data;
1053 while (1)
1055 struct xcoff_fileline_data *p;
1057 p = backtrace_atomic_load_pointer (pp);
1059 if (p == NULL)
1060 break;
1062 pp = &p->next;
1065 if (__sync_bool_compare_and_swap (pp, NULL, fdata))
1066 break;
1070 return 1;
1072 fail:
1073 return 0;
1076 /* Add the backtrace data for one XCOFF file. Returns 1 on success,
1077 0 on failure (in both cases descriptor is closed). */
1079 static int
1080 xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
1081 uintptr_t base_address, backtrace_error_callback error_callback,
1082 void *data, fileline *fileline_fn, int *found_sym, int exe)
1084 struct backtrace_view fhdr_view;
1085 struct backtrace_view sects_view;
1086 struct backtrace_view linenos_view;
1087 struct backtrace_view syms_view;
1088 struct backtrace_view str_view;
1089 struct backtrace_view dwarf_view;
1090 b_xcoff_filhdr fhdr;
1091 const b_xcoff_scnhdr *sects;
1092 const b_xcoff_scnhdr *stext;
1093 uint64_t lnnoptr;
1094 uint32_t nlnno;
1095 off_t str_off;
1096 off_t min_offset;
1097 off_t max_offset;
1098 struct dwsect_info dwsect[DWSECT_MAX];
1099 size_t sects_size;
1100 size_t syms_size;
1101 int32_t str_size;
1102 int sects_view_valid;
1103 int linenos_view_valid;
1104 int syms_view_valid;
1105 int str_view_valid;
1106 int dwarf_view_valid;
1107 int magic_ok;
1108 int i;
1110 *found_sym = 0;
1112 sects_view_valid = 0;
1113 linenos_view_valid = 0;
1114 syms_view_valid = 0;
1115 str_view_valid = 0;
1116 dwarf_view_valid = 0;
1118 str_size = 0;
1120 /* Map the XCOFF file header. */
1121 if (!backtrace_get_view (state, descriptor, offset, sizeof (b_xcoff_filhdr),
1122 error_callback, data, &fhdr_view))
1123 goto fail;
1125 memcpy (&fhdr, fhdr_view.data, sizeof fhdr);
1126 magic_ok = (fhdr.f_magic == XCOFF_MAGIC);
1128 backtrace_release_view (state, &fhdr_view, error_callback, data);
1130 if (!magic_ok)
1132 if (exe)
1133 error_callback (data, "executable file is not XCOFF", 0);
1134 goto fail;
1137 /* Verify object is of expected type. */
1138 if ((exe && (fhdr.f_flags & F_SHROBJ))
1139 || (!exe && !(fhdr.f_flags & F_SHROBJ)))
1140 goto fail;
1142 /* Read the section headers. */
1144 sects_size = fhdr.f_nscns * sizeof (b_xcoff_scnhdr);
1146 if (!backtrace_get_view (state, descriptor,
1147 offset + sizeof (fhdr) + fhdr.f_opthdr,
1148 sects_size, error_callback, data, &sects_view))
1149 goto fail;
1150 sects_view_valid = 1;
1151 sects = (const b_xcoff_scnhdr *) sects_view.data;
1153 /* FIXME: assumes only one .text section. */
1154 for (i = 0; i < fhdr.f_nscns; ++i)
1155 if ((sects[i].s_flags & 0xffff) == STYP_TEXT)
1156 break;
1157 if (i == fhdr.f_nscns)
1158 goto fail;
1160 stext = &sects[i];
1162 /* AIX ldinfo_textorg includes the XCOFF headers. */
1163 base_address = (exe ? XCOFF_AIX_TEXTBASE : base_address) + stext->s_scnptr;
1165 lnnoptr = stext->s_lnnoptr;
1166 nlnno = stext->s_nlnno;
1168 #if BACKTRACE_XCOFF_SIZE == 32
1169 if (nlnno == _OVERFLOW_MARKER)
1171 int sntext = i + 1;
1172 /* Find the matching .ovrflo section. */
1173 for (i = 0; i < fhdr.f_nscns; ++i)
1175 if (((sects[i].s_flags & 0xffff) == STYP_OVRFLO)
1176 && sects[i].s_nlnno == sntext)
1178 nlnno = sects[i].s_vaddr;
1179 break;
1183 #endif
1185 /* Read the symbol table and the string table. */
1187 if (fhdr.f_symptr != 0)
1189 struct xcoff_syminfo_data *sdata;
1191 /* Symbol table is followed by the string table. The string table
1192 starts with its length (on 4 bytes).
1193 Map the symbol table and the length of the string table. */
1194 syms_size = fhdr.f_nsyms * sizeof (b_xcoff_syment);
1196 if (!backtrace_get_view (state, descriptor, offset + fhdr.f_symptr,
1197 syms_size + 4, error_callback, data,
1198 &syms_view))
1199 goto fail;
1200 syms_view_valid = 1;
1202 memcpy (&str_size, syms_view.data + syms_size, 4);
1204 str_off = fhdr.f_symptr + syms_size;
1206 if (str_size > 4)
1208 /* Map string table (including the length word). */
1210 if (!backtrace_get_view (state, descriptor, offset + str_off,
1211 str_size, error_callback, data, &str_view))
1212 goto fail;
1213 str_view_valid = 1;
1216 sdata = ((struct xcoff_syminfo_data *)
1217 backtrace_alloc (state, sizeof *sdata, error_callback, data));
1218 if (sdata == NULL)
1219 goto fail;
1221 if (!xcoff_initialize_syminfo (state, base_address, sects,
1222 syms_view.data, fhdr.f_nsyms,
1223 str_view.data, str_size,
1224 error_callback, data, sdata))
1226 backtrace_free (state, sdata, sizeof *sdata, error_callback, data);
1227 goto fail;
1230 *found_sym = 1;
1232 xcoff_add_syminfo_data (state, sdata);
1235 /* Read all the DWARF sections in a single view, since they are
1236 probably adjacent in the file. We never release this view. */
1238 min_offset = 0;
1239 max_offset = 0;
1240 memset (dwsect, 0, sizeof dwsect);
1241 for (i = 0; i < fhdr.f_nscns; ++i)
1243 off_t end;
1244 int idx;
1246 if ((sects[i].s_flags & 0xffff) != STYP_DWARF
1247 || sects[i].s_size == 0)
1248 continue;
1249 /* Map DWARF section to array index. */
1250 switch (sects[i].s_flags & 0xffff0000)
1252 case SSUBTYP_DWINFO:
1253 idx = DWSECT_INFO;
1254 break;
1255 case SSUBTYP_DWLINE:
1256 idx = DWSECT_LINE;
1257 break;
1258 case SSUBTYP_DWABREV:
1259 idx = DWSECT_ABBREV;
1260 break;
1261 case SSUBTYP_DWARNGE:
1262 idx = DWSECT_RANGES;
1263 break;
1264 case SSUBTYP_DWSTR:
1265 idx = DWSECT_STR;
1266 break;
1267 default:
1268 continue;
1270 if (min_offset == 0 || (off_t) sects[i].s_scnptr < min_offset)
1271 min_offset = sects[i].s_scnptr;
1272 end = sects[i].s_scnptr + sects[i].s_size;
1273 if (end > max_offset)
1274 max_offset = end;
1275 dwsect[idx].offset = sects[i].s_scnptr;
1276 dwsect[idx].size = sects[i].s_size;
1278 if (min_offset != 0 && max_offset != 0)
1280 if (!backtrace_get_view (state, descriptor, offset + min_offset,
1281 max_offset - min_offset,
1282 error_callback, data, &dwarf_view))
1283 goto fail;
1284 dwarf_view_valid = 1;
1286 for (i = 0; i < (int) DWSECT_MAX; ++i)
1288 if (dwsect[i].offset == 0)
1289 dwsect[i].data = NULL;
1290 else
1291 dwsect[i].data = ((const unsigned char *) dwarf_view.data
1292 + (dwsect[i].offset - min_offset));
1295 if (!backtrace_dwarf_add (state, 0,
1296 dwsect[DWSECT_INFO].data,
1297 dwsect[DWSECT_INFO].size,
1298 #if BACKTRACE_XCOFF_SIZE == 32
1299 /* XXX workaround for broken lineoff */
1300 dwsect[DWSECT_LINE].data - 4,
1301 #else
1302 /* XXX workaround for broken lineoff */
1303 dwsect[DWSECT_LINE].data - 12,
1304 #endif
1305 dwsect[DWSECT_LINE].size,
1306 dwsect[DWSECT_ABBREV].data,
1307 dwsect[DWSECT_ABBREV].size,
1308 dwsect[DWSECT_RANGES].data,
1309 dwsect[DWSECT_RANGES].size,
1310 dwsect[DWSECT_STR].data,
1311 dwsect[DWSECT_STR].size,
1312 1, /* big endian */
1313 error_callback, data, fileline_fn))
1314 goto fail;
1317 /* Read the XCOFF line number entries if DWARF sections not found. */
1319 if (!dwarf_view_valid && fhdr.f_symptr != 0 && lnnoptr != 0)
1321 size_t linenos_size = (size_t) nlnno * LINESZ;
1323 if (!backtrace_get_view (state, descriptor, offset + lnnoptr,
1324 linenos_size,
1325 error_callback, data, &linenos_view))
1326 goto fail;
1327 linenos_view_valid = 1;
1329 if (xcoff_initialize_fileline (state, base_address, sects,
1330 syms_view.data, fhdr.f_nsyms,
1331 str_view.data, str_size,
1332 linenos_view.data, linenos_size,
1333 lnnoptr, error_callback, data))
1334 *fileline_fn = xcoff_fileline;
1336 backtrace_release_view (state, &linenos_view, error_callback, data);
1337 linenos_view_valid = 0;
1340 backtrace_release_view (state, &sects_view, error_callback, data);
1341 sects_view_valid = 0;
1342 if (syms_view_valid)
1343 backtrace_release_view (state, &syms_view, error_callback, data);
1344 syms_view_valid = 0;
1346 /* We've read all we need from the executable. */
1347 if (!backtrace_close (descriptor, error_callback, data))
1348 goto fail;
1349 descriptor = -1;
1351 return 1;
1353 fail:
1354 if (sects_view_valid)
1355 backtrace_release_view (state, &sects_view, error_callback, data);
1356 if (str_view_valid)
1357 backtrace_release_view (state, &str_view, error_callback, data);
1358 if (syms_view_valid)
1359 backtrace_release_view (state, &syms_view, error_callback, data);
1360 if (linenos_view_valid)
1361 backtrace_release_view (state, &linenos_view, error_callback, data);
1362 if (dwarf_view_valid)
1363 backtrace_release_view (state, &dwarf_view, error_callback, data);
1364 if (descriptor != -1 && offset == 0)
1365 backtrace_close (descriptor, error_callback, data);
1366 return 0;
1369 #ifdef HAVE_LOADQUERY
1371 /* Read an integer value in human-readable format from an AIX
1372 big archive fixed-length or member header. */
1374 static int
1375 xcoff_parse_decimal (const char *buf, size_t size, off_t *off)
1377 char str[32];
1378 char *end;
1380 if (size >= sizeof str)
1381 return 0;
1382 memcpy (str, buf, size);
1383 str[size] = '\0';
1384 *off = strtol (str, &end, 10);
1385 if (*end != '\0' && *end != ' ')
1386 return 0;
1388 return 1;
1391 /* Add the backtrace data for a member of an AIX big archive.
1392 Returns 1 on success, 0 on failure. */
1394 static int
1395 xcoff_armem_add (struct backtrace_state *state, int descriptor,
1396 uintptr_t base_address, const char *member,
1397 backtrace_error_callback error_callback, void *data,
1398 fileline *fileline_fn, int *found_sym)
1400 struct backtrace_view view;
1401 b_ar_fl_hdr fl_hdr;
1402 const b_ar_hdr *ar_hdr;
1403 off_t off;
1404 off_t len;
1405 int memlen;
1407 *found_sym = 0;
1409 /* Map archive fixed-length header. */
1411 if (!backtrace_get_view (state, descriptor, 0, sizeof (b_ar_fl_hdr),
1412 error_callback, data, &view))
1413 goto fail;
1415 memcpy (&fl_hdr, view.data, sizeof (b_ar_fl_hdr));
1417 backtrace_release_view (state, &view, error_callback, data);
1419 if (memcmp (fl_hdr.fl_magic, AIAMAGBIG, 8) != 0)
1420 goto fail;
1422 memlen = strlen (member);
1424 /* Read offset of first archive member. */
1425 if (!xcoff_parse_decimal (fl_hdr.fl_fstmoff, sizeof fl_hdr.fl_fstmoff, &off))
1426 goto fail;
1427 while (off != 0)
1429 /* Map archive member header and member name. */
1431 if (!backtrace_get_view (state, descriptor, off,
1432 sizeof (b_ar_hdr) + memlen,
1433 error_callback, data, &view))
1434 break;
1436 ar_hdr = (const b_ar_hdr *) view.data;
1438 /* Read archive member name length. */
1439 if (!xcoff_parse_decimal (ar_hdr->ar_namlen, sizeof ar_hdr->ar_namlen,
1440 &len))
1442 backtrace_release_view (state, &view, error_callback, data);
1443 break;
1445 if (len == memlen && !memcmp (ar_hdr->ar_name, member, memlen))
1447 off = (off + sizeof (b_ar_hdr) + memlen + 1) & ~1;
1449 /* The archive can contain several members with the same name
1450 (e.g. 32-bit and 64-bit), so continue if not ok. */
1452 if (xcoff_add (state, descriptor, off, base_address, error_callback,
1453 data, fileline_fn, found_sym, 0))
1455 backtrace_release_view (state, &view, error_callback, data);
1456 return 1;
1460 /* Read offset of next archive member. */
1461 if (!xcoff_parse_decimal (ar_hdr->ar_nxtmem, sizeof ar_hdr->ar_nxtmem,
1462 &off))
1464 backtrace_release_view (state, &view, error_callback, data);
1465 break;
1467 backtrace_release_view (state, &view, error_callback, data);
1470 fail:
1471 /* No matching member found. */
1472 backtrace_close (descriptor, error_callback, data);
1473 return 0;
1476 /* Add the backtrace data for dynamically loaded libraries. */
1478 static void
1479 xcoff_add_shared_libs (struct backtrace_state *state,
1480 backtrace_error_callback error_callback,
1481 void *data, fileline *fileline_fn, int *found_sym)
1483 const struct ld_info *ldinfo;
1484 void *buf;
1485 unsigned int buflen;
1486 const char *member;
1487 int descriptor;
1488 int does_not_exist;
1489 int lib_found_sym;
1490 int ret;
1492 /* Retrieve the list of loaded libraries. */
1494 buf = NULL;
1495 buflen = 512;
1498 buf = realloc (buf, buflen);
1499 if (buf == NULL)
1501 ret = -1;
1502 break;
1504 ret = loadquery (L_GETINFO, buf, buflen);
1505 if (ret == 0)
1506 break;
1507 buflen *= 2;
1509 while (ret == -1 && errno == ENOMEM);
1510 if (ret != 0)
1512 free (buf);
1513 return;
1516 ldinfo = (const struct ld_info *) buf;
1517 while ((const char *) ldinfo < (const char *) buf + buflen)
1519 if (*ldinfo->ldinfo_filename != '/')
1520 goto next;
1522 descriptor = backtrace_open (ldinfo->ldinfo_filename, error_callback,
1523 data, &does_not_exist);
1524 if (descriptor < 0)
1525 goto next;
1527 /* Check if it is an archive (member name not empty). */
1529 member = ldinfo->ldinfo_filename + strlen (ldinfo->ldinfo_filename) + 1;
1530 if (*member)
1532 xcoff_armem_add (state, descriptor,
1533 (uintptr_t) ldinfo->ldinfo_textorg, member,
1534 error_callback, data, fileline_fn, &lib_found_sym);
1536 else
1538 xcoff_add (state, descriptor, 0, (uintptr_t) ldinfo->ldinfo_textorg,
1539 error_callback, data, fileline_fn, &lib_found_sym, 0);
1541 if (lib_found_sym)
1542 *found_sym = 1;
1544 next:
1545 if (ldinfo->ldinfo_next == 0)
1546 break;
1547 ldinfo = (const struct ld_info *) ((const char *) ldinfo
1548 + ldinfo->ldinfo_next);
1551 free (buf);
1553 #endif /* HAVE_LOADQUERY */
1555 /* Initialize the backtrace data we need from an XCOFF executable.
1556 Returns 1 on success, 0 on failure. */
1559 backtrace_initialize (struct backtrace_state *state,
1560 const char *filename ATTRIBUTE_UNUSED, int descriptor,
1561 backtrace_error_callback error_callback,
1562 void *data, fileline *fileline_fn)
1564 int ret;
1565 int found_sym;
1566 fileline xcoff_fileline_fn = xcoff_nodebug;
1568 ret = xcoff_add (state, descriptor, 0, 0, error_callback, data,
1569 &xcoff_fileline_fn, &found_sym, 1);
1570 if (!ret)
1571 return 0;
1573 #ifdef HAVE_LOADQUERY
1574 xcoff_add_shared_libs (state, error_callback, data, &xcoff_fileline_fn,
1575 &found_sym);
1576 #endif
1578 if (!state->threaded)
1580 if (found_sym)
1581 state->syminfo_fn = xcoff_syminfo;
1582 else if (state->syminfo_fn == NULL)
1583 state->syminfo_fn = xcoff_nosyms;
1585 else
1587 if (found_sym)
1588 backtrace_atomic_store_pointer (&state->syminfo_fn, xcoff_syminfo);
1589 else
1590 __sync_bool_compare_and_swap (&state->syminfo_fn, NULL, xcoff_nosyms);
1593 if (!state->threaded)
1595 if (state->fileline_fn == NULL || state->fileline_fn == xcoff_nodebug)
1596 *fileline_fn = xcoff_fileline_fn;
1598 else
1600 fileline current_fn;
1602 current_fn = backtrace_atomic_load_pointer (&state->fileline_fn);
1603 if (current_fn == NULL || current_fn == xcoff_nodebug)
1604 *fileline_fn = xcoff_fileline_fn;
1607 return 1;