View | Details | Raw Unified | Return to bug 198611 | Differences between
and this patch

Collapse All | Expand All

(-)b/contrib/elftoolchain/common/_elftc.h (-1 / +2 lines)
Lines 342-353 struct name { \ Link Here
342
342
343
343
344
#if defined(__GLIBC__) || defined(__linux__)
344
#if defined(__GLIBC__) || defined(__linux__)
345
345
#ifndef _GNU_SOURCE
346
/*
346
/*
347
 * GLIBC based systems have a global 'char *' pointer referencing
347
 * GLIBC based systems have a global 'char *' pointer referencing
348
 * the executable's name.
348
 * the executable's name.
349
 */
349
 */
350
extern const char *program_invocation_short_name;
350
extern const char *program_invocation_short_name;
351
#endif	/* !_GNU_SOURCE */
351
352
352
#define	ELFTC_GETPROGNAME()	program_invocation_short_name
353
#define	ELFTC_GETPROGNAME()	program_invocation_short_name
353
354
(-)b/contrib/elftoolchain/common/elfdefinitions.h (+1 lines)
Lines 565-570 _ELF_DEFINE_EM(EM_SPARC, 2, "SPARC") \ Link Here
565
_ELF_DEFINE_EM(EM_386,              3, "Intel 80386")			\
565
_ELF_DEFINE_EM(EM_386,              3, "Intel 80386")			\
566
_ELF_DEFINE_EM(EM_68K,              4, "Motorola 68000")		\
566
_ELF_DEFINE_EM(EM_68K,              4, "Motorola 68000")		\
567
_ELF_DEFINE_EM(EM_88K,              5, "Motorola 88000")		\
567
_ELF_DEFINE_EM(EM_88K,              5, "Motorola 88000")		\
568
_ELF_DEFINE_EM(EM_IAMCU,            6, "Intel MCU")			\
568
_ELF_DEFINE_EM(EM_860,              7, "Intel 80860")			\
569
_ELF_DEFINE_EM(EM_860,              7, "Intel 80860")			\
569
_ELF_DEFINE_EM(EM_MIPS,             8, "MIPS I Architecture")		\
570
_ELF_DEFINE_EM(EM_MIPS,             8, "MIPS I Architecture")		\
570
_ELF_DEFINE_EM(EM_S370,             9, "IBM System/370 Processor")	\
571
_ELF_DEFINE_EM(EM_S370,             9, "IBM System/370 Processor")	\
(-)b/contrib/elftoolchain/elfcopy/elfcopy.h (+1 lines)
Lines 237-242 struct elfcopy { Link Here
237
	uint64_t	*secndx;	/* section index map. */
237
	uint64_t	*secndx;	/* section index map. */
238
	uint64_t	*symndx;	/* symbol index map. */
238
	uint64_t	*symndx;	/* symbol index map. */
239
	unsigned char	*v_rel;		/* symbols needed by relocation. */
239
	unsigned char	*v_rel;		/* symbols needed by relocation. */
240
	unsigned char	*v_grp;		/* symbols refered by section group. */
240
	unsigned char	*v_secsym;	/* sections with section symbol. */
241
	unsigned char	*v_secsym;	/* sections with section symbol. */
241
	STAILQ_HEAD(, segment) v_seg;	/* list of segments. */
242
	STAILQ_HEAD(, segment) v_seg;	/* list of segments. */
242
	STAILQ_HEAD(, sec_action) v_sac;/* list of section operations. */
243
	STAILQ_HEAD(, sec_action) v_sac;/* list of section operations. */
(-)b/contrib/elftoolchain/elfcopy/main.c (-1 / +17 lines)
Lines 404-411 create_elf(struct elfcopy *ecp) Link Here
404
	 * Insert SHDR table into the internal section list as a "pseudo"
404
	 * Insert SHDR table into the internal section list as a "pseudo"
405
	 * section, so later it will get sorted and resynced just as "normal"
405
	 * section, so later it will get sorted and resynced just as "normal"
406
	 * sections.
406
	 * sections.
407
	 *
408
	 * Under FreeBSD, Binutils objcopy always put the section header
409
	 * at the end of all the sections. We want to do the same here.
410
	 *
411
	 * However, note that the behaviour is still different with Binutils:
412
	 * elfcopy checks the FreeBSD OSABI tag to tell whether it needs to
413
	 * move the section headers, while Binutils is probably configured
414
	 * this way when it's compiled on FreeBSD.
407
	 */
415
	 */
408
	shtab = insert_shtab(ecp, 0);
416
	if (oeh.e_ident[EI_OSABI] == ELFOSABI_FREEBSD)
417
		shtab = insert_shtab(ecp, 1);
418
	else
419
		shtab = insert_shtab(ecp, 0);
409
420
410
	/*
421
	/*
411
	 * Resync section offsets in the output object. This is needed
422
	 * Resync section offsets in the output object. This is needed
Lines 485-490 free_elf(struct elfcopy *ecp) Link Here
485
			free(sec);
496
			free(sec);
486
		}
497
		}
487
	}
498
	}
499
500
	if (ecp->secndx != NULL) {
501
		free(ecp->secndx);
502
		ecp->secndx = NULL;
503
	}
488
}
504
}
489
505
490
/* Create a temporary file. */
506
/* Create a temporary file. */
(-)b/contrib/elftoolchain/elfcopy/sections.c (-1 / +78 lines)
Lines 56-61 static void print_data(const char *d, size_t sz); Link Here
56
static void	print_section(struct section *s);
56
static void	print_section(struct section *s);
57
static void	*read_section(struct section *s, size_t *size);
57
static void	*read_section(struct section *s, size_t *size);
58
static void	update_reloc(struct elfcopy *ecp, struct section *s);
58
static void	update_reloc(struct elfcopy *ecp, struct section *s);
59
static void	update_section_group(struct elfcopy *ecp, struct section *s);
59
60
60
int
61
int
61
is_remove_section(struct elfcopy *ecp, const char *name)
62
is_remove_section(struct elfcopy *ecp, const char *name)
Lines 552-557 copy_content(struct elfcopy *ecp) Link Here
552
		    (s->type == SHT_REL || s->type == SHT_RELA))
553
		    (s->type == SHT_REL || s->type == SHT_RELA))
553
			filter_reloc(ecp, s);
554
			filter_reloc(ecp, s);
554
555
556
		/*
557
		 * The section indices in the SHT_GROUP section needs
558
		 * to be updated since we might have stripped some
559
		 * sections and changed section numbering.
560
		 */
561
		if (s->type == SHT_GROUP)
562
			update_section_group(ecp, s);
563
555
		if (is_modify_section(ecp, s->name))
564
		if (is_modify_section(ecp, s->name))
556
			modify_section(ecp, s);
565
			modify_section(ecp, s);
557
566
Lines 571-576 copy_content(struct elfcopy *ecp) Link Here
571
	}
580
	}
572
}
581
}
573
582
583
584
/*
585
 * Update section group section. The section indices in the SHT_GROUP
586
 * section need update after section numbering changed.
587
 */
588
static void
589
update_section_group(struct elfcopy *ecp, struct section *s)
590
{
591
	GElf_Shdr	 ish;
592
	Elf_Data	*id;
593
	uint32_t	*ws, *wd;
594
	uint64_t	 n;
595
	size_t		 ishnum;
596
	int		 i, j;
597
598
	if (!elf_getshnum(ecp->ein, &ishnum))
599
		errx(EXIT_FAILURE, "elf_getshnum failed: %s",
600
		    elf_errmsg(-1));
601
602
	if (gelf_getshdr(s->is, &ish) == NULL)
603
		errx(EXIT_FAILURE, "gelf_getehdr() failed: %s",
604
		    elf_errmsg(-1));
605
606
	if ((id = elf_getdata(s->is, NULL)) == NULL)
607
		errx(EXIT_FAILURE, "elf_getdata() failed: %s",
608
		    elf_errmsg(-1));
609
610
	if (ish.sh_size == 0)
611
		return;
612
613
	if (ish.sh_entsize == 0)
614
		ish.sh_entsize = 4;
615
616
	ws = id->d_buf;
617
618
	/* We only support COMDAT section. */
619
#ifndef GRP_COMDAT
620
#define	GRP_COMDAT 0x1
621
#endif
622
	if ((*ws & GRP_COMDAT) == 0)
623
		return;
624
625
	if ((s->buf = malloc(ish.sh_size)) == NULL)
626
		err(EXIT_FAILURE, "malloc failed");
627
628
	s->sz = ish.sh_size;
629
630
	wd = s->buf;
631
632
	/* Copy the flag word as-is. */
633
	*wd = *ws;
634
635
	/* Update the section indices. */
636
	n = ish.sh_size / ish.sh_entsize;
637
	for(i = 1, j = 1; (uint64_t)i < n; i++) {
638
		if (ws[i] != SHN_UNDEF && ws[i] < ishnum &&
639
		    ecp->secndx[ws[i]] != 0)
640
			wd[j++] = ecp->secndx[ws[i]];
641
		else
642
			s->sz -= 4;
643
	}
644
645
	s->nocopy = 1;
646
}
647
574
/*
648
/*
575
 * Filter relocation entries, only keep those entries whose
649
 * Filter relocation entries, only keep those entries whose
576
 * symbol is in the keep list.
650
 * symbol is in the keep list.
Lines 1028-1035 copy_shdr(struct elfcopy *ecp, struct section *s, const char *name, int copy, Link Here
1028
				osh.sh_flags |= SHF_WRITE;
1102
				osh.sh_flags |= SHF_WRITE;
1029
			if (sec_flags & SF_CODE)
1103
			if (sec_flags & SF_CODE)
1030
				osh.sh_flags |= SHF_EXECINSTR;
1104
				osh.sh_flags |= SHF_EXECINSTR;
1031
		} else
1105
		} else {
1032
			osh.sh_flags = ish.sh_flags;
1106
			osh.sh_flags = ish.sh_flags;
1107
			if (ish.sh_type == SHT_REL || ish.sh_type == SHT_RELA)
1108
				osh.sh_flags |= SHF_INFO_LINK;
1109
		}
1033
	}
1110
	}
1034
1111
1035
	if (name == NULL)
1112
	if (name == NULL)
(-)b/contrib/elftoolchain/elfcopy/symbols.c (-7 / +85 lines)
Lines 77-83 static int is_weak_symbol(unsigned char st_info); Link Here
77
static int	lookup_exact_string(hash_head *hash, const char *buf,
77
static int	lookup_exact_string(hash_head *hash, const char *buf,
78
		    const char *s);
78
		    const char *s);
79
static int	generate_symbols(struct elfcopy *ecp);
79
static int	generate_symbols(struct elfcopy *ecp);
80
static void	mark_symbols(struct elfcopy *ecp, size_t sc);
80
static void	mark_reloc_symbols(struct elfcopy *ecp, size_t sc);
81
static void	mark_section_group_symbols(struct elfcopy *ecp, size_t sc);
81
static int	match_wildcard(const char *name, const char *pattern);
82
static int	match_wildcard(const char *name, const char *pattern);
82
uint32_t	str_hash(const char *s);
83
uint32_t	str_hash(const char *s);
83
84
Lines 160-165 is_needed_symbol(struct elfcopy *ecp, int i, GElf_Sym *s) Link Here
160
	if (BIT_ISSET(ecp->v_rel, i))
161
	if (BIT_ISSET(ecp->v_rel, i))
161
		return (1);
162
		return (1);
162
163
164
	/* Symbols refered by COMDAT sections are needed. */
165
	if (BIT_ISSET(ecp->v_grp, i))
166
		return (1);
167
163
	/*
168
	/*
164
	 * For relocatable files (.o files), global and weak symbols
169
	 * For relocatable files (.o files), global and weak symbols
165
	 * are needed.
170
	 * are needed.
Lines 207-213 is_remove_symbol(struct elfcopy *ecp, size_t sc, int i, GElf_Sym *s, Link Here
207
		return (1);
212
		return (1);
208
213
209
	if (ecp->v_rel == NULL)
214
	if (ecp->v_rel == NULL)
210
		mark_symbols(ecp, sc);
215
		mark_reloc_symbols(ecp, sc);
216
217
	if (ecp->v_grp == NULL)
218
		mark_section_group_symbols(ecp, sc);
211
219
212
	if (is_needed_symbol(ecp, i, s))
220
	if (is_needed_symbol(ecp, i, s))
213
		return (0);
221
		return (0);
Lines 233-239 is_remove_symbol(struct elfcopy *ecp, size_t sc, int i, GElf_Sym *s, Link Here
233
 * Mark symbols refered by relocation entries.
241
 * Mark symbols refered by relocation entries.
234
 */
242
 */
235
static void
243
static void
236
mark_symbols(struct elfcopy *ecp, size_t sc)
244
mark_reloc_symbols(struct elfcopy *ecp, size_t sc)
237
{
245
{
238
	const char	*name;
246
	const char	*name;
239
	Elf_Data	*d;
247
	Elf_Data	*d;
Lines 311-316 mark_symbols(struct elfcopy *ecp, size_t sc) Link Here
311
		    elf_errmsg(elferr));
319
		    elf_errmsg(elferr));
312
}
320
}
313
321
322
static void
323
mark_section_group_symbols(struct elfcopy *ecp, size_t sc)
324
{
325
	const char	*name;
326
	Elf_Scn		*s;
327
	GElf_Shdr	 sh;
328
	size_t		 indx;
329
	int		 elferr;
330
331
	ecp->v_grp = calloc((sc + 7) / 8, 1);
332
	if (ecp->v_grp == NULL)
333
		err(EXIT_FAILURE, "calloc failed");
334
335
	if (elf_getshstrndx(ecp->ein, &indx) == 0)
336
		errx(EXIT_FAILURE, "elf_getshstrndx failed: %s",
337
		    elf_errmsg(-1));
338
339
	s = NULL;
340
	while ((s = elf_nextscn(ecp->ein, s)) != NULL) {
341
		if (gelf_getshdr(s, &sh) != &sh)
342
			errx(EXIT_FAILURE, "elf_getshdr failed: %s",
343
			    elf_errmsg(-1));
344
345
		if (sh.sh_type != SHT_GROUP)
346
			continue;
347
348
		if ((name = elf_strptr(ecp->ein, indx, sh.sh_name)) == NULL)
349
			errx(EXIT_FAILURE, "elf_strptr failed: %s",
350
			    elf_errmsg(-1));
351
		if (is_remove_section(ecp, name))
352
			continue;
353
354
		if (sh.sh_info > 0 && sh.sh_info < sc)
355
			BIT_SET(ecp->v_grp, sh.sh_info);
356
		else if (sh.sh_info != 0)
357
			warnx("invalid symbox index");
358
	}
359
	elferr = elf_errno();
360
	if (elferr != 0)
361
		errx(EXIT_FAILURE, "elf_nextscn failed: %s",
362
		    elf_errmsg(elferr));
363
}
364
314
static int
365
static int
315
generate_symbols(struct elfcopy *ecp)
366
generate_symbols(struct elfcopy *ecp)
316
{
367
{
Lines 351-356 generate_symbols(struct elfcopy *ecp) Link Here
351
	ecp->symtab->buf = sy_buf;
402
	ecp->symtab->buf = sy_buf;
352
	ecp->strtab->buf = st_buf;
403
	ecp->strtab->buf = st_buf;
353
404
405
	gsym = NULL;
406
354
	/*
407
	/*
355
	 * Create bit vector v_secsym, which is used to mark sections
408
	 * Create bit vector v_secsym, which is used to mark sections
356
	 * that already have corresponding STT_SECTION symbols.
409
	 * that already have corresponding STT_SECTION symbols.
Lines 384-390 generate_symbols(struct elfcopy *ecp) Link Here
384
	/* Symbol table should exist if this function is called. */
437
	/* Symbol table should exist if this function is called. */
385
	if (symndx == 0) {
438
	if (symndx == 0) {
386
		warnx("can't find .strtab section");
439
		warnx("can't find .strtab section");
387
		return (0);
440
		goto clean;
388
	}
441
	}
389
442
390
	/* Locate .symtab of input object. */
443
	/* Locate .symtab of input object. */
Lines 413-419 generate_symbols(struct elfcopy *ecp) Link Here
413
	 * output object, it is used by update_reloc() later to update
466
	 * output object, it is used by update_reloc() later to update
414
	 * relocation information.
467
	 * relocation information.
415
	 */
468
	 */
416
	gsym = NULL;
417
	sc = ish.sh_size / ish.sh_entsize;
469
	sc = ish.sh_size / ish.sh_entsize;
418
	if (sc > 0) {
470
	if (sc > 0) {
419
		ecp->symndx = calloc(sc, sizeof(*ecp->symndx));
471
		ecp->symndx = calloc(sc, sizeof(*ecp->symndx));
Lines 427-433 generate_symbols(struct elfcopy *ecp) Link Here
427
			if (elferr != 0)
479
			if (elferr != 0)
428
				errx(EXIT_FAILURE, "elf_getdata failed: %s",
480
				errx(EXIT_FAILURE, "elf_getdata failed: %s",
429
				    elf_errmsg(elferr));
481
				    elf_errmsg(elferr));
430
			return (0);
482
			goto clean;
431
		}
483
		}
432
	} else
484
	} else
433
		return (0);
485
		return (0);
Lines 523-529 generate_symbols(struct elfcopy *ecp) Link Here
523
	 * check if that only local symbol is the reserved symbol.
575
	 * check if that only local symbol is the reserved symbol.
524
	 */
576
	 */
525
	if (sy_buf->nls <= 1 && sy_buf->ngs == 0)
577
	if (sy_buf->nls <= 1 && sy_buf->ngs == 0)
526
		return (0);
578
		goto clean;
527
579
528
	/*
580
	/*
529
	 * Create STT_SECTION symbols for sections that do not already
581
	 * Create STT_SECTION symbols for sections that do not already
Lines 550-555 generate_symbols(struct elfcopy *ecp) Link Here
550
			sym.st_value = s->vma;
602
			sym.st_value = s->vma;
551
			sym.st_size  = 0;
603
			sym.st_size  = 0;
552
			sym.st_info  = GELF_ST_INFO(STB_LOCAL, STT_SECTION);
604
			sym.st_info  = GELF_ST_INFO(STB_LOCAL, STT_SECTION);
605
			sym.st_other = STV_DEFAULT;
553
			/*
606
			/*
554
			 * Don't let add_to_symtab() touch sym.st_shndx.
607
			 * Don't let add_to_symtab() touch sym.st_shndx.
555
			 * In this case, we know the index already.
608
			 * In this case, we know the index already.
Lines 583-588 generate_symbols(struct elfcopy *ecp) Link Here
583
	}
636
	}
584
637
585
	return (1);
638
	return (1);
639
640
clean:
641
	free(gsym);
642
	free_symtab(ecp);
643
644
	return (0);
586
}
645
}
587
646
588
void
647
void
Lines 624-630 create_symtab(struct elfcopy *ecp) Link Here
624
	if (((ecp->flags & SYMTAB_INTACT) == 0) && !generate_symbols(ecp)) {
683
	if (((ecp->flags & SYMTAB_INTACT) == 0) && !generate_symbols(ecp)) {
625
		TAILQ_REMOVE(&ecp->v_sec, ecp->symtab, sec_list);
684
		TAILQ_REMOVE(&ecp->v_sec, ecp->symtab, sec_list);
626
		TAILQ_REMOVE(&ecp->v_sec, ecp->strtab, sec_list);
685
		TAILQ_REMOVE(&ecp->v_sec, ecp->strtab, sec_list);
686
		free(ecp->symtab->buf);
627
		free(ecp->symtab);
687
		free(ecp->symtab);
688
		free(ecp->strtab->buf);
628
		free(ecp->strtab);
689
		free(ecp->strtab);
629
		ecp->symtab = NULL;
690
		ecp->symtab = NULL;
630
		ecp->strtab = NULL;
691
		ecp->strtab = NULL;
Lines 697-702 free_symtab(struct elfcopy *ecp) Link Here
697
			}
758
			}
698
		}
759
		}
699
	}
760
	}
761
762
	if (ecp->symndx != NULL) {
763
		free(ecp->symndx);
764
		ecp->symndx = NULL;
765
	}
766
	if (ecp->v_rel != NULL) {
767
		free(ecp->v_rel);
768
		ecp->v_rel = NULL;
769
	}
770
	if (ecp->v_grp != NULL) {
771
		free(ecp->v_grp);
772
		ecp->v_grp = NULL;
773
	}
774
	if (ecp->v_secsym != NULL) {
775
		free(ecp->v_secsym);
776
		ecp->v_secsym = NULL;
777
	}
700
}
778
}
701
779
702
void
780
void
(-)b/contrib/elftoolchain/libdwarf/libdwarf_reloc.c (+1 lines)
Lines 75-80 _dwarf_get_reloc_size(Dwarf_Debug dbg, Dwarf_Unsigned rel_type) Link Here
75
			return (4);
75
			return (4);
76
		break;
76
		break;
77
	case EM_386:
77
	case EM_386:
78
	case EM_IAMCU:
78
		if (rel_type == R_386_32)
79
		if (rel_type == R_386_32)
79
			return (4);
80
			return (4);
80
		break;
81
		break;
(-)b/contrib/elftoolchain/libelftc/libelftc_dem_gnu3.c (-46 / +424 lines)
Lines 50-56 ELFTC_VCSID("$Id: libelftc_dem_gnu3.c 3194 2015-05-05 17:55:16Z emaste $"); Link Here
50
50
51
enum type_qualifier {
51
enum type_qualifier {
52
	TYPE_PTR, TYPE_REF, TYPE_CMX, TYPE_IMG, TYPE_EXT, TYPE_RST, TYPE_VAT,
52
	TYPE_PTR, TYPE_REF, TYPE_CMX, TYPE_IMG, TYPE_EXT, TYPE_RST, TYPE_VAT,
53
	TYPE_CST
53
	TYPE_CST, TYPE_VEC
54
};
54
};
55
55
56
struct vector_type_qualifier {
56
struct vector_type_qualifier {
Lines 84-89 struct cpp_demangle_data { Link Here
84
	int			 func_type;
84
	int			 func_type;
85
	const char		*cur;		/* current mangled name ptr */
85
	const char		*cur;		/* current mangled name ptr */
86
	const char		*last_sname;	/* last source name */
86
	const char		*last_sname;	/* last source name */
87
	int			 push_head;
87
};
88
};
88
89
89
#define	CPP_DEMANGLE_TRY_LIMIT	128
90
#define	CPP_DEMANGLE_TRY_LIMIT	128
Lines 112-117 static int cpp_demangle_read_array(struct cpp_demangle_data *); Link Here
112
static int	cpp_demangle_read_encoding(struct cpp_demangle_data *);
113
static int	cpp_demangle_read_encoding(struct cpp_demangle_data *);
113
static int	cpp_demangle_read_expr_primary(struct cpp_demangle_data *);
114
static int	cpp_demangle_read_expr_primary(struct cpp_demangle_data *);
114
static int	cpp_demangle_read_expression(struct cpp_demangle_data *);
115
static int	cpp_demangle_read_expression(struct cpp_demangle_data *);
116
static int	cpp_demangle_read_expression_flat(struct cpp_demangle_data *,
117
		    char **);
115
static int	cpp_demangle_read_expression_binary(struct cpp_demangle_data *,
118
static int	cpp_demangle_read_expression_binary(struct cpp_demangle_data *,
116
		    const char *, size_t);
119
		    const char *, size_t);
117
static int	cpp_demangle_read_expression_unary(struct cpp_demangle_data *,
120
static int	cpp_demangle_read_expression_unary(struct cpp_demangle_data *,
Lines 123-130 static int cpp_demangle_read_function(struct cpp_demangle_data *, int *, Link Here
123
static int	cpp_demangle_local_source_name(struct cpp_demangle_data *ddata);
126
static int	cpp_demangle_local_source_name(struct cpp_demangle_data *ddata);
124
static int	cpp_demangle_read_local_name(struct cpp_demangle_data *);
127
static int	cpp_demangle_read_local_name(struct cpp_demangle_data *);
125
static int	cpp_demangle_read_name(struct cpp_demangle_data *);
128
static int	cpp_demangle_read_name(struct cpp_demangle_data *);
129
static int	cpp_demangle_read_name_flat(struct cpp_demangle_data *,
130
		    char**);
126
static int	cpp_demangle_read_nested_name(struct cpp_demangle_data *);
131
static int	cpp_demangle_read_nested_name(struct cpp_demangle_data *);
127
static int	cpp_demangle_read_number(struct cpp_demangle_data *, long *);
132
static int	cpp_demangle_read_number(struct cpp_demangle_data *, long *);
133
static int	cpp_demangle_read_number_as_string(struct cpp_demangle_data *,
134
		    char **);
128
static int	cpp_demangle_read_nv_offset(struct cpp_demangle_data *);
135
static int	cpp_demangle_read_nv_offset(struct cpp_demangle_data *);
129
static int	cpp_demangle_read_offset(struct cpp_demangle_data *);
136
static int	cpp_demangle_read_offset(struct cpp_demangle_data *);
130
static int	cpp_demangle_read_offset_number(struct cpp_demangle_data *);
137
static int	cpp_demangle_read_offset_number(struct cpp_demangle_data *);
Lines 138-143 static int cpp_demangle_read_tmpl_arg(struct cpp_demangle_data *); Link Here
138
static int	cpp_demangle_read_tmpl_args(struct cpp_demangle_data *);
145
static int	cpp_demangle_read_tmpl_args(struct cpp_demangle_data *);
139
static int	cpp_demangle_read_tmpl_param(struct cpp_demangle_data *);
146
static int	cpp_demangle_read_tmpl_param(struct cpp_demangle_data *);
140
static int	cpp_demangle_read_type(struct cpp_demangle_data *, int);
147
static int	cpp_demangle_read_type(struct cpp_demangle_data *, int);
148
static int	cpp_demangle_read_type_flat(struct cpp_demangle_data *,
149
		    char **);
141
static int	cpp_demangle_read_uqname(struct cpp_demangle_data *);
150
static int	cpp_demangle_read_uqname(struct cpp_demangle_data *);
142
static int	cpp_demangle_read_v_offset(struct cpp_demangle_data *);
151
static int	cpp_demangle_read_v_offset(struct cpp_demangle_data *);
143
static char	*decode_fp_to_double(const char *, size_t);
152
static char	*decode_fp_to_double(const char *, size_t);
Lines 156-163 static int vector_type_qualifier_init(struct vector_type_qualifier *); Link Here
156
static int	vector_type_qualifier_push(struct vector_type_qualifier *,
165
static int	vector_type_qualifier_push(struct vector_type_qualifier *,
157
		    enum type_qualifier);
166
		    enum type_qualifier);
158
167
159
static int cpp_demangle_gnu3_push_head;
160
161
/**
168
/**
162
 * @brief Decode the input string by IA-64 C++ ABI style.
169
 * @brief Decode the input string by IA-64 C++ ABI style.
163
 *
170
 *
Lines 190-196 cpp_demangle_gnu3(const char *org) Link Here
190
	if (!cpp_demangle_data_init(&ddata, org + 2))
197
	if (!cpp_demangle_data_init(&ddata, org + 2))
191
		return (NULL);
198
		return (NULL);
192
199
193
	cpp_demangle_gnu3_push_head = 0;
194
	rtn = NULL;
200
	rtn = NULL;
195
201
196
	if (!cpp_demangle_read_encoding(&ddata))
202
	if (!cpp_demangle_read_encoding(&ddata))
Lines 277-282 cpp_demangle_data_init(struct cpp_demangle_data *d, const char *cur) Link Here
277
	d->func_type = 0;
283
	d->func_type = 0;
278
	d->cur = cur;
284
	d->cur = cur;
279
	d->last_sname = NULL;
285
	d->last_sname = NULL;
286
	d->push_head = 0;
280
287
281
	return (1);
288
	return (1);
282
289
Lines 309-315 cpp_demangle_push_fp(struct cpp_demangle_data *ddata, Link Here
309
	fp = ddata->cur;
316
	fp = ddata->cur;
310
	while (*ddata->cur != 'E')
317
	while (*ddata->cur != 'E')
311
		++ddata->cur;
318
		++ddata->cur;
312
	++ddata->cur;
313
319
314
	if ((f = decoder(fp, ddata->cur - fp)) == NULL)
320
	if ((f = decoder(fp, ddata->cur - fp)) == NULL)
315
		return (0);
321
		return (0);
Lines 320-325 cpp_demangle_push_fp(struct cpp_demangle_data *ddata, Link Here
320
326
321
	free(f);
327
	free(f);
322
328
329
	++ddata->cur;
330
323
	return (rtn);
331
	return (rtn);
324
}
332
}
325
333
Lines 331-337 cpp_demangle_push_str(struct cpp_demangle_data *ddata, const char *str, Link Here
331
	if (ddata == NULL || str == NULL || len == 0)
339
	if (ddata == NULL || str == NULL || len == 0)
332
		return (0);
340
		return (0);
333
341
334
	if (cpp_demangle_gnu3_push_head > 0)
342
	if (ddata->push_head > 0)
335
		return (vector_str_push(&ddata->output_tmp, str, len));
343
		return (vector_str_push(&ddata->output_tmp, str, len));
336
344
337
	return (vector_str_push(&ddata->output, str, len));
345
	return (vector_str_push(&ddata->output, str, len));
Lines 403-409 cpp_demangle_push_type_qualifier(struct cpp_demangle_data *ddata, Link Here
403
			if (type_str != NULL) {
411
			if (type_str != NULL) {
404
				if (!vector_str_push(&subst_v, "*", 1))
412
				if (!vector_str_push(&subst_v, "*", 1))
405
					goto clean;
413
					goto clean;
406
				if (!cpp_demangle_push_subst_v(ddata, &subst_v))
414
				if (!cpp_demangle_push_subst_v(ddata,
415
				    &subst_v))
407
					goto clean;
416
					goto clean;
408
			}
417
			}
409
			break;
418
			break;
Lines 414-420 cpp_demangle_push_type_qualifier(struct cpp_demangle_data *ddata, Link Here
414
			if (type_str != NULL) {
423
			if (type_str != NULL) {
415
				if (!vector_str_push(&subst_v, "&", 1))
424
				if (!vector_str_push(&subst_v, "&", 1))
416
					goto clean;
425
					goto clean;
417
				if (!cpp_demangle_push_subst_v(ddata, &subst_v))
426
				if (!cpp_demangle_push_subst_v(ddata,
427
				    &subst_v))
418
					goto clean;
428
					goto clean;
419
			}
429
			}
420
			break;
430
			break;
Lines 425-431 cpp_demangle_push_type_qualifier(struct cpp_demangle_data *ddata, Link Here
425
			if (type_str != NULL) {
435
			if (type_str != NULL) {
426
				if (!vector_str_push(&subst_v, " complex", 8))
436
				if (!vector_str_push(&subst_v, " complex", 8))
427
					goto clean;
437
					goto clean;
428
				if (!cpp_demangle_push_subst_v(ddata, &subst_v))
438
				if (!cpp_demangle_push_subst_v(ddata,
439
				    &subst_v))
429
					goto clean;
440
					goto clean;
430
			}
441
			}
431
			break;
442
			break;
Lines 434-456 cpp_demangle_push_type_qualifier(struct cpp_demangle_data *ddata, Link Here
434
			if (!cpp_demangle_push_str(ddata, " imaginary", 10))
445
			if (!cpp_demangle_push_str(ddata, " imaginary", 10))
435
				goto clean;
446
				goto clean;
436
			if (type_str != NULL) {
447
			if (type_str != NULL) {
437
				if (!vector_str_push(&subst_v, " imaginary", 10))
448
				if (!vector_str_push(&subst_v, " imaginary",
449
				    10))
438
					goto clean;
450
					goto clean;
439
				if (!cpp_demangle_push_subst_v(ddata, &subst_v))
451
				if (!cpp_demangle_push_subst_v(ddata,
452
				    &subst_v))
440
					goto clean;
453
					goto clean;
441
			}
454
			}
442
			break;
455
			break;
443
456
444
		case TYPE_EXT:
457
		case TYPE_EXT:
445
			if (e_idx > v->ext_name.size - 1)
458
			if (v->ext_name.size == 0 ||
459
			    e_idx > v->ext_name.size - 1)
446
				goto clean;
460
				goto clean;
447
			if ((e_len = strlen(v->ext_name.container[e_idx])) == 0)
461
			if ((e_len = strlen(v->ext_name.container[e_idx])) ==
462
			    0)
448
				goto clean;
463
				goto clean;
449
			if ((buf = malloc(sizeof(char) * (e_len + 1))) == NULL)
464
			if ((buf = malloc(e_len + 2)) == NULL)
450
				goto clean;
465
				goto clean;
451
466
			snprintf(buf, e_len + 2, " %s",
452
			memcpy(buf, " ", 1);
467
			    v->ext_name.container[e_idx]);
453
			memcpy(buf + 1, v->ext_name.container[e_idx], e_len);
454
468
455
			if (!cpp_demangle_push_str(ddata, buf, e_len + 1)) {
469
			if (!cpp_demangle_push_str(ddata, buf, e_len + 1)) {
456
				free(buf);
470
				free(buf);
Lines 463-469 cpp_demangle_push_type_qualifier(struct cpp_demangle_data *ddata, Link Here
463
					free(buf);
477
					free(buf);
464
					goto clean;
478
					goto clean;
465
				}
479
				}
466
				if (!cpp_demangle_push_subst_v(ddata, &subst_v)) {
480
				if (!cpp_demangle_push_subst_v(ddata,
481
				    &subst_v)) {
467
					free(buf);
482
					free(buf);
468
					goto clean;
483
					goto clean;
469
				}
484
				}
Lines 478-484 cpp_demangle_push_type_qualifier(struct cpp_demangle_data *ddata, Link Here
478
			if (type_str != NULL) {
493
			if (type_str != NULL) {
479
				if (!vector_str_push(&subst_v, " restrict", 9))
494
				if (!vector_str_push(&subst_v, " restrict", 9))
480
					goto clean;
495
					goto clean;
481
				if (!cpp_demangle_push_subst_v(ddata, &subst_v))
496
				if (!cpp_demangle_push_subst_v(ddata,
497
				    &subst_v))
482
					goto clean;
498
					goto clean;
483
			}
499
			}
484
			break;
500
			break;
Lines 489-495 cpp_demangle_push_type_qualifier(struct cpp_demangle_data *ddata, Link Here
489
			if (type_str != NULL) {
505
			if (type_str != NULL) {
490
				if (!vector_str_push(&subst_v, " volatile", 9))
506
				if (!vector_str_push(&subst_v, " volatile", 9))
491
					goto clean;
507
					goto clean;
492
				if (!cpp_demangle_push_subst_v(ddata, &subst_v))
508
				if (!cpp_demangle_push_subst_v(ddata,
509
				    &subst_v))
493
					goto clean;
510
					goto clean;
494
			}
511
			}
495
			break;
512
			break;
Lines 500-510 cpp_demangle_push_type_qualifier(struct cpp_demangle_data *ddata, Link Here
500
			if (type_str != NULL) {
517
			if (type_str != NULL) {
501
				if (!vector_str_push(&subst_v, " const", 6))
518
				if (!vector_str_push(&subst_v, " const", 6))
502
					goto clean;
519
					goto clean;
503
				if (!cpp_demangle_push_subst_v(ddata, &subst_v))
520
				if (!cpp_demangle_push_subst_v(ddata,
521
				    &subst_v))
504
					goto clean;
522
					goto clean;
505
			}
523
			}
506
			break;
524
			break;
507
525
526
		case TYPE_VEC:
527
			if (v->ext_name.size == 0 ||
528
			    e_idx > v->ext_name.size - 1)
529
				goto clean;
530
			if ((e_len = strlen(v->ext_name.container[e_idx])) ==
531
			    0)
532
				goto clean;
533
			if ((buf = malloc(e_len + 12)) == NULL)
534
				goto clean;
535
			snprintf(buf, e_len + 12, " __vector(%s)",
536
			    v->ext_name.container[e_idx]);
537
			if (!cpp_demangle_push_str(ddata, buf, e_len + 11)) {
538
				free(buf);
539
				goto clean;
540
			}
541
			if (type_str != NULL) {
542
				if (!vector_str_push(&subst_v, buf,
543
				    e_len + 11)) {
544
					free(buf);
545
					goto clean;
546
				}
547
				if (!cpp_demangle_push_subst_v(ddata,
548
				    &subst_v)) {
549
					free(buf);
550
					goto clean;
551
				}
552
			}
553
			free(buf);
554
			++e_idx;
555
			break;
508
		};
556
		};
509
		--idx;
557
		--idx;
510
	}
558
	}
Lines 655-664 cpp_demangle_read_expr_primary(struct cpp_demangle_data *ddata) Link Here
655
703
656
	switch (*ddata->cur) {
704
	switch (*ddata->cur) {
657
	case 'b':
705
	case 'b':
706
		if (*(ddata->cur + 2) != 'E')
707
			return (0);
658
		switch (*(++ddata->cur)) {
708
		switch (*(++ddata->cur)) {
659
		case '0':
709
		case '0':
710
			ddata->cur += 2;
660
			return (cpp_demangle_push_str(ddata, "false", 5));
711
			return (cpp_demangle_push_str(ddata, "false", 5));
661
		case '1':
712
		case '1':
713
			ddata->cur += 2;
662
			return (cpp_demangle_push_str(ddata, "true", 4));
714
			return (cpp_demangle_push_str(ddata, "true", 4));
663
		default:
715
		default:
664
			return (0);
716
			return (0);
Lines 707-713 cpp_demangle_read_expr_primary(struct cpp_demangle_data *ddata) Link Here
707
			++ddata->cur;
759
			++ddata->cur;
708
		}
760
		}
709
		++ddata->cur;
761
		++ddata->cur;
710
		return (cpp_demangle_push_str(ddata, num, ddata->cur - num));
762
		return (cpp_demangle_push_str(ddata, num,
763
		    ddata->cur - num - 1));
711
764
712
	default:
765
	default:
713
		return (0);
766
		return (0);
Lines 999-1004 cpp_demangle_read_expression(struct cpp_demangle_data *ddata) Link Here
999
}
1052
}
1000
1053
1001
static int
1054
static int
1055
cpp_demangle_read_expression_flat(struct cpp_demangle_data *ddata, char **str)
1056
{
1057
	struct vector_str *output;
1058
	size_t i, p_idx, idx, exp_len;
1059
	char *exp;
1060
1061
	output = ddata->push_head > 0 ? &ddata->output_tmp :
1062
	    &ddata->output;
1063
1064
	p_idx = output->size;
1065
1066
	if (!cpp_demangle_read_expression(ddata))
1067
		return (0);
1068
1069
	if ((exp = vector_str_substr(output, p_idx, output->size - 1,
1070
	    &exp_len)) == NULL)
1071
		return (0);
1072
1073
	idx = output->size;
1074
	for (i = p_idx; i < idx; ++i) {
1075
		if (!vector_str_pop(output)) {
1076
			free(exp);
1077
			return (0);
1078
		}
1079
	}
1080
1081
	*str = exp;
1082
1083
	return (1);
1084
}
1085
1086
static int
1002
cpp_demangle_read_expression_binary(struct cpp_demangle_data *ddata,
1087
cpp_demangle_read_expression_binary(struct cpp_demangle_data *ddata,
1003
    const char *name, size_t len)
1088
    const char *name, size_t len)
1004
{
1089
{
Lines 1127-1138 cpp_demangle_read_function(struct cpp_demangle_data *ddata, int *ext_c, Link Here
1127
static int
1212
static int
1128
cpp_demangle_read_encoding(struct cpp_demangle_data *ddata)
1213
cpp_demangle_read_encoding(struct cpp_demangle_data *ddata)
1129
{
1214
{
1215
	char *name, *type, *num_str;
1216
	long offset;
1217
	int rtn;
1130
1218
1131
	if (ddata == NULL || *ddata->cur == '\0')
1219
	if (ddata == NULL || *ddata->cur == '\0')
1132
		return (0);
1220
		return (0);
1133
1221
1134
	/* special name */
1222
	/* special name */
1135
	switch (SIMPLE_HASH(*ddata->cur, *(ddata->cur + 1))) {
1223
	switch (SIMPLE_HASH(*ddata->cur, *(ddata->cur + 1))) {
1224
	case SIMPLE_HASH('G', 'A'):
1225
		if (!cpp_demangle_push_str(ddata, "hidden alias for ", 17))
1226
			return (0);
1227
		ddata->cur += 2;
1228
		if (*ddata->cur == '\0')
1229
			return (0);
1230
		return (cpp_demangle_read_encoding(ddata));
1231
1232
	case SIMPLE_HASH('G', 'R'):
1233
		if (!cpp_demangle_push_str(ddata, "reference temporary #", 21))
1234
			return (0);
1235
		ddata->cur += 2;
1236
		if (*ddata->cur == '\0')
1237
			return (0);
1238
		if (!cpp_demangle_read_name_flat(ddata, &name))
1239
			return (0);
1240
		rtn = 0;
1241
		if (!cpp_demangle_read_number_as_string(ddata, &num_str))
1242
			goto clean1;
1243
		if (!cpp_demangle_push_str(ddata, num_str, strlen(num_str)))
1244
			goto clean2;
1245
		if (!cpp_demangle_push_str(ddata, " for ", 5))
1246
			goto clean2;
1247
		if (!cpp_demangle_push_str(ddata, name, strlen(name)))
1248
			goto clean2;
1249
		rtn = 1;
1250
	clean2:
1251
		free(num_str);
1252
	clean1:
1253
		free(name);
1254
		return (rtn);
1255
1256
	case SIMPLE_HASH('G', 'T'):
1257
		ddata->cur += 2;
1258
		if (*ddata->cur == '\0')
1259
			return (0);
1260
		switch (*ddata->cur) {
1261
		case 'n':
1262
			if (!cpp_demangle_push_str(ddata,
1263
			    "non-transaction clone for ", 26))
1264
				return (0);
1265
		case 't':
1266
		default:
1267
			if (!cpp_demangle_push_str(ddata,
1268
			    "transaction clone for ", 22))
1269
				return (0);
1270
		}
1271
		++ddata->cur;
1272
		return (cpp_demangle_read_encoding(ddata));
1273
1136
	case SIMPLE_HASH('G', 'V'):
1274
	case SIMPLE_HASH('G', 'V'):
1137
		/* sentry object for 1 time init */
1275
		/* sentry object for 1 time init */
1138
		if (!cpp_demangle_push_str(ddata, "guard variable for ", 20))
1276
		if (!cpp_demangle_push_str(ddata, "guard variable for ", 20))
Lines 1154-1167 cpp_demangle_read_encoding(struct cpp_demangle_data *ddata) Link Here
1154
			return (0);
1292
			return (0);
1155
		return (cpp_demangle_read_encoding(ddata));
1293
		return (cpp_demangle_read_encoding(ddata));
1156
1294
1295
	case SIMPLE_HASH('T', 'C'):
1296
		/* construction vtable */
1297
		if (!cpp_demangle_push_str(ddata, "construction vtable for ",
1298
		    24))
1299
			return (0);
1300
		ddata->cur += 2;
1301
		if (*ddata->cur == '\0')
1302
			return (0);
1303
		if (!cpp_demangle_read_type_flat(ddata, &type))
1304
			return (0);
1305
		rtn = 0;
1306
		if (!cpp_demangle_read_number(ddata, &offset))
1307
			goto clean3;
1308
		if (*ddata->cur++ != '_')
1309
			goto clean3;
1310
		if (!cpp_demangle_read_type(ddata, 0))
1311
			goto clean3;
1312
		if (!cpp_demangle_push_str(ddata, "-in-", 4))
1313
			goto clean3;
1314
		if (!cpp_demangle_push_str(ddata, type, strlen(type)))
1315
			goto clean3;
1316
		rtn = 1;
1317
	clean3:
1318
		free(type);
1319
		return (rtn);
1320
1157
	case SIMPLE_HASH('T', 'D'):
1321
	case SIMPLE_HASH('T', 'D'):
1158
		/* typeinfo common proxy */
1322
		/* typeinfo common proxy */
1159
		break;
1323
		break;
1160
1324
1325
	case SIMPLE_HASH('T', 'F'):
1326
		/* typeinfo fn */
1327
		if (!cpp_demangle_push_str(ddata, "typeinfo fn for ", 16))
1328
			return (0);
1329
		ddata->cur += 2;
1330
		if (*ddata->cur == '\0')
1331
			return (0);
1332
		return (cpp_demangle_read_type(ddata, 0));
1333
1161
	case SIMPLE_HASH('T', 'h'):
1334
	case SIMPLE_HASH('T', 'h'):
1162
		/* virtual function non-virtual override thunk */
1335
		/* virtual function non-virtual override thunk */
1163
		if (cpp_demangle_push_str(ddata,
1336
		if (!cpp_demangle_push_str(ddata,
1164
		    "virtual function non-virtual override ", 38) == 0)
1337
		    "virtual function non-virtual override ", 38))
1165
			return (0);
1338
			return (0);
1166
		ddata->cur += 2;
1339
		ddata->cur += 2;
1167
		if (*ddata->cur == '\0')
1340
		if (*ddata->cur == '\0')
Lines 1170-1193 cpp_demangle_read_encoding(struct cpp_demangle_data *ddata) Link Here
1170
			return (0);
1343
			return (0);
1171
		return (cpp_demangle_read_encoding(ddata));
1344
		return (cpp_demangle_read_encoding(ddata));
1172
1345
1346
	case SIMPLE_HASH('T', 'H'):
1347
		/* TLS init function */
1348
		if (!cpp_demangle_push_str(ddata, "TLS init function for ",
1349
		    22))
1350
			return (0);
1351
		ddata->cur += 2;
1352
		if (*ddata->cur == '\0')
1353
			return (0);
1354
		break;
1355
1173
	case SIMPLE_HASH('T', 'I'):
1356
	case SIMPLE_HASH('T', 'I'):
1174
		/* typeinfo structure */
1357
		/* typeinfo structure */
1175
		/* FALLTHROUGH */
1358
		if (!cpp_demangle_push_str(ddata, "typeinfo for ", 13))
1359
			return (0);
1360
		ddata->cur += 2;
1361
		if (*ddata->cur == '\0')
1362
			return (0);
1363
		return (cpp_demangle_read_type(ddata, 0));
1364
1365
	case SIMPLE_HASH('T', 'J'):
1366
		/* java class */
1367
		if (!cpp_demangle_push_str(ddata, "java Class for ", 15))
1368
			return (0);
1369
		ddata->cur += 2;
1370
		if (*ddata->cur == '\0')
1371
			return (0);
1372
		return (cpp_demangle_read_type(ddata, 0));
1373
1176
	case SIMPLE_HASH('T', 'S'):
1374
	case SIMPLE_HASH('T', 'S'):
1177
		/* RTTI name (NTBS) */
1375
		/* RTTI name (NTBS) */
1178
		if (!cpp_demangle_push_str(ddata, "typeinfo for ", 14))
1376
		if (!cpp_demangle_push_str(ddata, "typeinfo name for ", 18))
1179
			return (0);
1377
			return (0);
1180
		ddata->cur += 2;
1378
		ddata->cur += 2;
1181
		if (*ddata->cur == '\0')
1379
		if (*ddata->cur == '\0')
1182
			return (0);
1380
			return (0);
1183
		return (cpp_demangle_read_type(ddata, 1));
1381
		return (cpp_demangle_read_type(ddata, 0));
1184
1382
1185
	case SIMPLE_HASH('T', 'T'):
1383
	case SIMPLE_HASH('T', 'T'):
1186
		/* VTT table */
1384
		/* VTT table */
1187
		if (!cpp_demangle_push_str(ddata, "VTT for ", 8))
1385
		if (!cpp_demangle_push_str(ddata, "VTT for ", 8))
1188
			return (0);
1386
			return (0);
1189
		ddata->cur += 2;
1387
		ddata->cur += 2;
1190
		return (cpp_demangle_read_type(ddata, 1));
1388
		if (*ddata->cur == '\0')
1389
			return (0);
1390
		return (cpp_demangle_read_type(ddata, 0));
1191
1391
1192
	case SIMPLE_HASH('T', 'v'):
1392
	case SIMPLE_HASH('T', 'v'):
1193
		/* virtual function virtual override thunk */
1393
		/* virtual function virtual override thunk */
Lines 1208-1214 cpp_demangle_read_encoding(struct cpp_demangle_data *ddata) Link Here
1208
		ddata->cur += 2;
1408
		ddata->cur += 2;
1209
		if (*ddata->cur == '\0')
1409
		if (*ddata->cur == '\0')
1210
			return (0);
1410
			return (0);
1211
		return (cpp_demangle_read_type(ddata, 1));
1411
		return (cpp_demangle_read_type(ddata, 0));
1412
1413
	case SIMPLE_HASH('T', 'W'):
1414
		/* TLS wrapper function */
1415
		if (!cpp_demangle_push_str(ddata, "TLS wrapper function for ",
1416
		    25))
1417
			return (0);
1418
		ddata->cur += 2;
1419
		if (*ddata->cur == '\0')
1420
			return (0);
1421
		break;
1212
	};
1422
	};
1213
1423
1214
	return (cpp_demangle_read_name(ddata));
1424
	return (cpp_demangle_read_name(ddata));
Lines 1270-1277 cpp_demangle_read_name(struct cpp_demangle_data *ddata) Link Here
1270
	if (ddata == NULL || *ddata->cur == '\0')
1480
	if (ddata == NULL || *ddata->cur == '\0')
1271
		return (0);
1481
		return (0);
1272
1482
1273
	output = cpp_demangle_gnu3_push_head > 0 ?
1483
	output = ddata->push_head > 0 ? &ddata->output_tmp : &ddata->output;
1274
	    &ddata->output_tmp : &ddata->output;
1275
1484
1276
	subst_str = NULL;
1485
	subst_str = NULL;
1277
1486
Lines 1327-1332 clean: Link Here
1327
}
1536
}
1328
1537
1329
static int
1538
static int
1539
cpp_demangle_read_name_flat(struct cpp_demangle_data *ddata, char **str)
1540
{
1541
	struct vector_str *output;
1542
	size_t i, p_idx, idx, name_len;
1543
	char *name;
1544
1545
	output = ddata->push_head > 0 ? &ddata->output_tmp :
1546
	    &ddata->output;
1547
1548
	p_idx = output->size;
1549
1550
	if (!cpp_demangle_read_name(ddata))
1551
		return (0);
1552
1553
	if ((name = vector_str_substr(output, p_idx, output->size - 1,
1554
	    &name_len)) == NULL)
1555
		return (0);
1556
1557
	idx = output->size;
1558
	for (i = p_idx; i < idx; ++i) {
1559
		if (!vector_str_pop(output)) {
1560
			free(name);
1561
			return (0);
1562
		}
1563
	}
1564
1565
	*str = name;
1566
1567
	return (1);
1568
}
1569
1570
static int
1330
cpp_demangle_read_nested_name(struct cpp_demangle_data *ddata)
1571
cpp_demangle_read_nested_name(struct cpp_demangle_data *ddata)
1331
{
1572
{
1332
	struct vector_str *output, v;
1573
	struct vector_str *output, v;
Lines 1355-1362 cpp_demangle_read_nested_name(struct cpp_demangle_data *ddata) Link Here
1355
		++ddata->cur;
1596
		++ddata->cur;
1356
	}
1597
	}
1357
1598
1358
	output = cpp_demangle_gnu3_push_head > 0 ?
1599
	output = ddata->push_head > 0 ? &ddata->output_tmp : &ddata->output;
1359
	    &ddata->output_tmp : &ddata->output;
1360
	if (!vector_str_init(&v))
1600
	if (!vector_str_init(&v))
1361
		return (0);
1601
		return (0);
1362
1602
Lines 1453-1458 cpp_demangle_read_number(struct cpp_demangle_data *ddata, long *rtn) Link Here
1453
}
1693
}
1454
1694
1455
static int
1695
static int
1696
cpp_demangle_read_number_as_string(struct cpp_demangle_data *ddata, char **str)
1697
{
1698
	long n;
1699
1700
	if (!cpp_demangle_read_number(ddata, &n)) {
1701
		*str = NULL;
1702
		return (0);
1703
	}
1704
1705
	if (asprintf(str, "%ld", n) < 0) {
1706
		*str = NULL;
1707
		return (0);
1708
	}
1709
1710
	return (1);
1711
}
1712
1713
static int
1456
cpp_demangle_read_nv_offset(struct cpp_demangle_data *ddata)
1714
cpp_demangle_read_nv_offset(struct cpp_demangle_data *ddata)
1457
{
1715
{
1458
1716
Lines 1581-1589 static int Link Here
1581
cpp_demangle_read_sname(struct cpp_demangle_data *ddata)
1839
cpp_demangle_read_sname(struct cpp_demangle_data *ddata)
1582
{
1840
{
1583
	long len;
1841
	long len;
1842
	int err;
1584
1843
1585
	if (ddata == NULL || cpp_demangle_read_number(ddata, &len) == 0 ||
1844
	if (ddata == NULL || cpp_demangle_read_number(ddata, &len) == 0 ||
1586
	    len <= 0 || cpp_demangle_push_str(ddata, ddata->cur, len) == 0)
1845
	    len <= 0)
1846
		return (0);
1847
1848
	if (len == 12 && (memcmp("_GLOBAL__N_1", ddata->cur, 12) == 0))
1849
		err = cpp_demangle_push_str(ddata, "(anonymous namespace)", 21);
1850
	else
1851
		err = cpp_demangle_push_str(ddata, ddata->cur, len);
1852
1853
	if (err == 0)
1587
		return (0);
1854
		return (0);
1588
1855
1589
	assert(ddata->output.size > 0);
1856
	assert(ddata->output.size > 0);
Lines 1732-1739 cpp_demangle_read_subst_std(struct cpp_demangle_data *ddata) Link Here
1732
1999
1733
	ddata->cur += 2;
2000
	ddata->cur += 2;
1734
2001
1735
	output = cpp_demangle_gnu3_push_head > 0 ?
2002
	output = ddata->push_head > 0 ? &ddata->output_tmp : &ddata->output;
1736
	    &ddata->output_tmp : &ddata->output;
1737
2003
1738
	p_idx = output->size;
2004
	p_idx = output->size;
1739
	if (!cpp_demangle_read_uqname(ddata))
2005
	if (!cpp_demangle_read_uqname(ddata))
Lines 1783-1790 cpp_demangle_read_subst_stdtmpl(struct cpp_demangle_data *ddata, Link Here
1783
	if (ddata == NULL || str == NULL || len == 0)
2049
	if (ddata == NULL || str == NULL || len == 0)
1784
		return (0);
2050
		return (0);
1785
2051
1786
	output = cpp_demangle_gnu3_push_head > 0 ? &ddata->output_tmp :
2052
	output = ddata->push_head > 0 ? &ddata->output_tmp : &ddata->output;
1787
	    &ddata->output;
1788
2053
1789
	p_idx = output->size;
2054
	p_idx = output->size;
1790
	substr = NULL;
2055
	substr = NULL;
Lines 1852-1859 cpp_demangle_read_tmpl_args(struct cpp_demangle_data *ddata) Link Here
1852
		return (0);
2117
		return (0);
1853
2118
1854
	limit = 0;
2119
	limit = 0;
1855
	v = cpp_demangle_gnu3_push_head > 0 ?
2120
	v = ddata->push_head > 0 ? &ddata->output_tmp : &ddata->output;
1856
	    &ddata->output_tmp : &ddata->output;
1857
	for (;;) {
2121
	for (;;) {
1858
		idx = v->size;
2122
		idx = v->size;
1859
		if (!cpp_demangle_read_tmpl_arg(ddata))
2123
		if (!cpp_demangle_read_tmpl_arg(ddata))
Lines 1936-1949 cpp_demangle_read_type(struct cpp_demangle_data *ddata, int delimit) Link Here
1936
	size_t p_idx, type_str_len;
2200
	size_t p_idx, type_str_len;
1937
	int extern_c, is_builtin;
2201
	int extern_c, is_builtin;
1938
	long len;
2202
	long len;
1939
	char *type_str;
2203
	char *type_str, *exp_str, *num_str;
1940
2204
1941
	if (ddata == NULL)
2205
	if (ddata == NULL)
1942
		return (0);
2206
		return (0);
1943
2207
1944
	output = &ddata->output;
2208
	output = &ddata->output;
1945
	if (!strncmp(ddata->output.container[ddata->output.size - 1], ">", 1)) {
2209
	if (!strncmp(ddata->output.container[ddata->output.size - 1], ">", 1)) {
1946
		cpp_demangle_gnu3_push_head++;
2210
		ddata->push_head++;
1947
		output = &ddata->output_tmp;
2211
		output = &ddata->output_tmp;
1948
	} else if (delimit == 1) {
2212
	} else if (delimit == 1) {
1949
		if (ddata->paren == false) {
2213
		if (ddata->paren == false) {
Lines 1978-1984 cpp_demangle_read_type(struct cpp_demangle_data *ddata, int delimit) Link Here
1978
	extern_c = 0;
2242
	extern_c = 0;
1979
	is_builtin = 1;
2243
	is_builtin = 1;
1980
	p_idx = output->size;
2244
	p_idx = output->size;
1981
	type_str = NULL;
2245
	type_str = exp_str = num_str = NULL;
1982
again:
2246
again:
1983
	/* builtin type */
2247
	/* builtin type */
1984
	switch (*ddata->cur) {
2248
	switch (*ddata->cur) {
Lines 2024-2029 again: Link Here
2024
		++ddata->cur;
2288
		++ddata->cur;
2025
		goto rtn;
2289
		goto rtn;
2026
2290
2291
	case 'D':
2292
		++ddata->cur;
2293
		switch (*ddata->cur) {
2294
		case 'd':
2295
			/* IEEE 754r decimal floating point (64 bits) */
2296
			if (!cpp_demangle_push_str(ddata, "decimal64", 9))
2297
				goto clean;
2298
			++ddata->cur;
2299
			break;
2300
		case 'e':
2301
			/* IEEE 754r decimal floating point (128 bits) */
2302
			if (!cpp_demangle_push_str(ddata, "decimal128", 10))
2303
				goto clean;
2304
			++ddata->cur;
2305
			break;
2306
		case 'f':
2307
			/* IEEE 754r decimal floating point (32 bits) */
2308
			if (!cpp_demangle_push_str(ddata, "decimal32", 9))
2309
				goto clean;
2310
			++ddata->cur;
2311
			break;
2312
		case 'h':
2313
			/* IEEE 754r half-precision floating point (16 bits) */
2314
			if (!cpp_demangle_push_str(ddata, "half", 4))
2315
				goto clean;
2316
			++ddata->cur;
2317
			break;
2318
		case 'i':
2319
			/* char32_t */
2320
			if (!cpp_demangle_push_str(ddata, "char32_t", 8))
2321
				goto clean;
2322
			++ddata->cur;
2323
			break;
2324
		case 'n':
2325
			/* std::nullptr_t (i.e., decltype(nullptr)) */
2326
			if (!cpp_demangle_push_str(ddata, "decltype(nullptr)",
2327
			    17))
2328
				goto clean;
2329
			++ddata->cur;
2330
			break;
2331
		case 's':
2332
			/* char16_t */
2333
			if (!cpp_demangle_push_str(ddata, "char16_t", 8))
2334
				goto clean;
2335
			++ddata->cur;
2336
			break;
2337
		case 'v':
2338
			/* gcc vector_size extension. */
2339
			++ddata->cur;
2340
			if (*ddata->cur == '_') {
2341
				++ddata->cur;
2342
				if (!cpp_demangle_read_expression_flat(ddata,
2343
				    &exp_str))
2344
					goto clean;
2345
				if (!vector_str_push(&v.ext_name, exp_str,
2346
				    strlen(exp_str)))
2347
					goto clean;
2348
			} else {
2349
				if (!cpp_demangle_read_number_as_string(ddata,
2350
				    &num_str))
2351
					goto clean;
2352
				if (!vector_str_push(&v.ext_name, num_str,
2353
				    strlen(num_str)))
2354
					goto clean;
2355
			}
2356
			if (*ddata->cur != '_')
2357
				goto clean;
2358
			++ddata->cur;
2359
			if (!vector_type_qualifier_push(&v, TYPE_VEC))
2360
				goto clean;
2361
			goto again;
2362
		default:
2363
			goto clean;
2364
		}
2365
		goto rtn;
2366
2027
	case 'e':
2367
	case 'e':
2028
		/* long double */
2368
		/* long double */
2029
		if (!cpp_demangle_push_str(ddata, "long double", 11))
2369
		if (!cpp_demangle_push_str(ddata, "long double", 11))
Lines 2118-2124 again: Link Here
2118
2458
2119
	case 'o':
2459
	case 'o':
2120
		/* unsigned __int128 */
2460
		/* unsigned __int128 */
2121
		if (!cpp_demangle_push_str(ddata, "unsigned _;int128", 17))
2461
		if (!cpp_demangle_push_str(ddata, "unsigned __int128", 17))
2122
			goto clean;
2462
			goto clean;
2123
		++ddata->cur;
2463
		++ddata->cur;
2124
		goto rtn;
2464
		goto rtn;
Lines 2189-2194 again: Link Here
2189
		if (!vector_str_push(&v.ext_name, ddata->cur, len))
2529
		if (!vector_str_push(&v.ext_name, ddata->cur, len))
2190
			return (0);
2530
			return (0);
2191
		ddata->cur += len;
2531
		ddata->cur += len;
2532
		if (!vector_type_qualifier_push(&v, TYPE_EXT))
2533
			goto clean;
2192
		goto again;
2534
		goto again;
2193
2535
2194
	case 'v':
2536
	case 'v':
Lines 2253-2266 rtn: Link Here
2253
		goto clean;
2595
		goto clean;
2254
2596
2255
	free(type_str);
2597
	free(type_str);
2598
	free(exp_str);
2599
	free(num_str);
2256
	vector_type_qualifier_dest(&v);
2600
	vector_type_qualifier_dest(&v);
2257
2601
2258
	if (cpp_demangle_gnu3_push_head > 0) {
2602
	if (ddata->push_head > 0) {
2259
		if (*ddata->cur == 'I' && cpp_demangle_read_tmpl_args(ddata)
2603
		if (*ddata->cur == 'I' && cpp_demangle_read_tmpl_args(ddata)
2260
		    == 0)
2604
		    == 0)
2261
			return (0);
2605
			return (0);
2262
2606
2263
		if (--cpp_demangle_gnu3_push_head > 0)
2607
		if (--ddata->push_head > 0)
2264
			return (1);
2608
			return (1);
2265
2609
2266
		if (!vector_str_push(&ddata->output_tmp, " ", 1))
2610
		if (!vector_str_push(&ddata->output_tmp, " ", 1))
Lines 2284-2294 rtn: Link Here
2284
	return (1);
2628
	return (1);
2285
clean:
2629
clean:
2286
	free(type_str);
2630
	free(type_str);
2631
	free(exp_str);
2632
	free(num_str);
2287
	vector_type_qualifier_dest(&v);
2633
	vector_type_qualifier_dest(&v);
2288
2634
2289
	return (0);
2635
	return (0);
2290
}
2636
}
2291
2637
2638
static int
2639
cpp_demangle_read_type_flat(struct cpp_demangle_data *ddata, char **str)
2640
{
2641
	struct vector_str *output;
2642
	size_t i, p_idx, idx, type_len;
2643
	char *type;
2644
2645
	output = ddata->push_head > 0 ? &ddata->output_tmp :
2646
	    &ddata->output;
2647
2648
	p_idx = output->size;
2649
2650
	if (!cpp_demangle_read_type(ddata, 0))
2651
		return (0);
2652
2653
	if ((type = vector_str_substr(output, p_idx, output->size - 1,
2654
	    &type_len)) == NULL)
2655
		return (0);
2656
2657
	idx = output->size;
2658
	for (i = p_idx; i < idx; ++i) {
2659
		if (!vector_str_pop(output)) {
2660
			free(type);
2661
			return (0);
2662
		}
2663
	}
2664
2665
	*str = type;
2666
2667
	return (1);
2668
}
2669
2292
/*
2670
/*
2293
 * read unqualified-name, unqualified name are operator-name, ctor-dtor-name,
2671
 * read unqualified-name, unqualified name are operator-name, ctor-dtor-name,
2294
 * source-name
2672
 * source-name
(-)b/contrib/elftoolchain/libelftc/os.Linux.mk (-1 / +1 lines)
Lines 1-3 Link Here
1
# $Id: os.Linux.mk 994 2010-06-13 10:39:19Z jkoshy $
1
# $Id: os.Linux.mk 994 2010-06-13 10:39:19Z jkoshy $
2
2
3
CFLAGS+=	-Wall
3
CFLAGS+=	-Wall -D_GNU_SOURCE
(-)b/contrib/elftoolchain/readelf/readelf.1 (-1 / +1 lines)
Lines 90-96 sections in the ELF object. Link Here
90
.It Fl e | Fl -headers
90
.It Fl e | Fl -headers
91
Print all program, file and section headers in the ELF object.
91
Print all program, file and section headers in the ELF object.
92
.It Fl g | Fl -section-groups
92
.It Fl g | Fl -section-groups
93
This option is recognized, but is ignored.
93
Print the contents of the section groups in the ELF object.
94
.It Fl h | Fl -file-header
94
.It Fl h | Fl -file-header
95
Print the file header of the ELF object.
95
Print the file header of the ELF object.
96
.It Fl l | Fl -program-headers
96
.It Fl l | Fl -program-headers
(-)b/contrib/elftoolchain/readelf/readelf.c (-4 / +65 lines)
Lines 1-5 Link Here
1
/*-
1
/*-
2
 * Copyright (c) 2009-2014 Kai Wang
2
 * Copyright (c) 2009-2015 Kai Wang
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
Lines 302-307 static void dump_gnu_hash(struct readelf *re, struct section *s); Link Here
302
static void dump_hash(struct readelf *re);
302
static void dump_hash(struct readelf *re);
303
static void dump_phdr(struct readelf *re);
303
static void dump_phdr(struct readelf *re);
304
static void dump_ppc_attributes(uint8_t *p, uint8_t *pe);
304
static void dump_ppc_attributes(uint8_t *p, uint8_t *pe);
305
static void dump_section_groups(struct readelf *re);
305
static void dump_symtab(struct readelf *re, int i);
306
static void dump_symtab(struct readelf *re, int i);
306
static void dump_symtabs(struct readelf *re);
307
static void dump_symtabs(struct readelf *re);
307
static uint8_t *dump_unknown_tag(uint64_t tag, uint8_t *p);
308
static uint8_t *dump_unknown_tag(uint64_t tag, uint8_t *p);
Lines 445-450 elf_machine(unsigned int mach) Link Here
445
	case EM_SPARC: return "Sun SPARC";
446
	case EM_SPARC: return "Sun SPARC";
446
	case EM_386: return "Intel i386";
447
	case EM_386: return "Intel i386";
447
	case EM_68K: return "Motorola 68000";
448
	case EM_68K: return "Motorola 68000";
449
	case EM_IAMCU: return "Intel MCU";
448
	case EM_88K: return "Motorola 88000";
450
	case EM_88K: return "Motorola 88000";
449
	case EM_860: return "Intel i860";
451
	case EM_860: return "Intel i860";
450
	case EM_MIPS: return "MIPS R3000 Big-Endian only";
452
	case EM_MIPS: return "MIPS R3000 Big-Endian only";
Lines 1050-1055 r_type(unsigned int mach, unsigned int type) Link Here
1050
	switch(mach) {
1052
	switch(mach) {
1051
	case EM_NONE: return "";
1053
	case EM_NONE: return "";
1052
	case EM_386:
1054
	case EM_386:
1055
	case EM_IAMCU:
1053
		switch(type) {
1056
		switch(type) {
1054
		case 0: return "R_386_NONE";
1057
		case 0: return "R_386_NONE";
1055
		case 1: return "R_386_32";
1058
		case 1: return "R_386_32";
Lines 2381-2386 dwarf_reg(unsigned int mach, unsigned int reg) Link Here
2381
2384
2382
	switch (mach) {
2385
	switch (mach) {
2383
	case EM_386:
2386
	case EM_386:
2387
	case EM_IAMCU:
2384
		switch (reg) {
2388
		switch (reg) {
2385
		case 0: return "eax";
2389
		case 0: return "eax";
2386
		case 1: return "ecx";
2390
		case 1: return "ecx";
Lines 4047-4052 dump_liblist(struct readelf *re) Link Here
4047
4051
4048
#undef Elf_Lib
4052
#undef Elf_Lib
4049
4053
4054
static void
4055
dump_section_groups(struct readelf *re)
4056
{
4057
	struct section *s;
4058
	const char *symname;
4059
	Elf_Data *d;
4060
	uint32_t *w;
4061
	int i, j, elferr;
4062
	size_t n;
4063
4064
	for (i = 0; (size_t) i < re->shnum; i++) {
4065
		s = &re->sl[i];
4066
		if (s->type != SHT_GROUP)
4067
			continue;
4068
		(void) elf_errno();
4069
		if ((d = elf_getdata(s->scn, NULL)) == NULL) {
4070
			elferr = elf_errno();
4071
			if (elferr != 0)
4072
				warnx("elf_getdata failed: %s",
4073
				    elf_errmsg(elferr));
4074
			continue;
4075
		}
4076
		if (d->d_size <= 0)
4077
			continue;
4078
4079
		w = d->d_buf;
4080
4081
		/* We only support COMDAT section. */
4082
#ifndef GRP_COMDAT
4083
#define	GRP_COMDAT 0x1
4084
#endif
4085
		if ((*w++ & GRP_COMDAT) == 0)
4086
			return;
4087
4088
		if (s->entsize == 0)
4089
			s->entsize = 4;
4090
4091
		symname = get_symbol_name(re, s->link, s->info);
4092
		n = s->sz / s->entsize;
4093
		if (n-- < 1)
4094
			return;
4095
4096
		printf("\nCOMDAT group section [%5d] `%s' [%s] contains %ju"
4097
		    " sections:\n", i, s->name, symname, (uintmax_t)n);
4098
		printf("   %-10.10s %s\n", "[Index]", "Name");
4099
		for (j = 0; (size_t) j < n; j++, w++) {
4100
			if (*w >= re->shnum) {
4101
				warnx("invalid section index: %u", *w);
4102
				continue;
4103
			}
4104
			printf("   [%5u]   %s\n", *w, re->sl[*w].name);
4105
		}
4106
	}
4107
}
4108
4050
static uint8_t *
4109
static uint8_t *
4051
dump_unknown_tag(uint64_t tag, uint8_t *p)
4110
dump_unknown_tag(uint64_t tag, uint8_t *p)
4052
{
4111
{
Lines 6838-6843 dump_elf(struct readelf *re) Link Here
6838
		dump_phdr(re);
6897
		dump_phdr(re);
6839
	if (re->options & RE_SS)
6898
	if (re->options & RE_SS)
6840
		dump_shdr(re);
6899
		dump_shdr(re);
6900
	if (re->options & RE_G)
6901
		dump_section_groups(re);
6841
	if (re->options & RE_D)
6902
	if (re->options & RE_D)
6842
		dump_dynamic(re);
6903
		dump_dynamic(re);
6843
	if (re->options & RE_R)
6904
	if (re->options & RE_R)
Lines 7311-7317 Usage: %s [options] file...\n\ Link Here
7311
  -c | --archive-index     Print the archive symbol table for archives.\n\
7372
  -c | --archive-index     Print the archive symbol table for archives.\n\
7312
  -d | --dynamic           Print the contents of SHT_DYNAMIC sections.\n\
7373
  -d | --dynamic           Print the contents of SHT_DYNAMIC sections.\n\
7313
  -e | --headers           Print all headers in the object.\n\
7374
  -e | --headers           Print all headers in the object.\n\
7314
  -g | --section-groups    (accepted, but ignored)\n\
7375
  -g | --section-groups    Print the contents of the section groups.\n\
7315
  -h | --file-header       Print the file header for the object.\n\
7376
  -h | --file-header       Print the file header for the object.\n\
7316
  -l | --program-headers   Print the PHDR table for the object.\n\
7377
  -l | --program-headers   Print the PHDR table for the object.\n\
7317
  -n | --notes             Print the contents of SHT_NOTE sections.\n\
7378
  -n | --notes             Print the contents of SHT_NOTE sections.\n\
Lines 7365-7372 main(int argc, char **argv) Link Here
7365
			re->options |= RE_AA;
7426
			re->options |= RE_AA;
7366
			break;
7427
			break;
7367
		case 'a':
7428
		case 'a':
7368
			re->options |= RE_AA | RE_D | RE_H | RE_II | RE_L |
7429
			re->options |= RE_AA | RE_D | RE_G | RE_H | RE_II |
7369
			    RE_R | RE_SS | RE_S | RE_VV;
7430
			    RE_L | RE_R | RE_SS | RE_S | RE_VV;
7370
			break;
7431
			break;
7371
		case 'c':
7432
		case 'c':
7372
			re->options |= RE_C;
7433
			re->options |= RE_C;
(-)b/lib/libelftc/elftc_version.c (-1 / +1 lines)
Lines 6-10 Link Here
6
const char *
6
const char *
7
elftc_version(void)
7
elftc_version(void)
8
{
8
{
9
	return "elftoolchain r3197M";
9
	return "elftoolchain r3223M";
10
}
10
}

Return to bug 198611