Project

General

Profile

Bug #3776 » patch-gcc-fix.diff

Adjust ml_size too. - Pedro Giffuni, 2013-06-29 07:26 PM

View differences:

tools/ctf/cvt/ctf.c (working copy)
52 52
#define	CTF_BUF_CHUNK_SIZE	(64 * 1024)
53 53
#define	RES_BUF_CHUNK_SIZE	(64 * 1024)
54 54

  
55
static int ntypes=0;		/* The number of types. */
56

  
55 57
struct ctf_buf {
56 58
	strtab_t ctb_strtab;	/* string table */
57 59
	caddr_t ctb_base;	/* pointer to base of buffer */
......
1044 1046
					(*mpp)->ml_type = tdarr[ctm->ctm_type];
1045 1047
					(*mpp)->ml_offset = ctm->ctm_offset;
1046 1048
					(*mpp)->ml_size = 0;
1049
					if (ctm->ctm_type > ntypes) {
1050
						parseterminate("Invalid member type ctm_type=%d",
1051
						    ctm->ctm_type);
1052
					}
1047 1053
				}
1048 1054
			} else {
1049 1055
				for (i = 0, mpp = &tdp->t_members; i < vlen;
......
1060 1066
					(*mpp)->ml_offset =
1061 1067
					    (int)CTF_LMEM_OFFSET(ctlm);
1062 1068
					(*mpp)->ml_size = 0;
1069
					if (ctlm->ctlm_type > ntypes) {
1070
						parseterminate("Invalid lmember type ctlm_type=%d",
1071
						    ctlm->ctlm_type);
1072
					}
1063 1073
				}
1064 1074
			}
1065 1075

  
......
1173 1183
{
1174 1184
	tdata_t *td = tdata_new();
1175 1185
	tdesc_t **tdarr;
1176
	int ntypes = count_types(h, buf);
1177 1186
	int idx, i;
1178 1187

  
1188
	ntypes = count_types(h, buf);
1189

  
1179 1190
	/* shudder */
1180 1191
	tdarr = xcalloc(sizeof (tdesc_t *) * (ntypes + 1));
1181 1192
	tdarr[0] = NULL;
tools/ctf/cvt/ctftools.h (working copy)
159 159
/* Auxiliary structure for structure/union tdesc_t */
160 160
typedef struct mlist {
161 161
	int	ml_offset;	/* Offset from start of structure (in bits) */
162
	int	ml_size;	/* Member size (in bits) */
162
	uint_t	ml_size;	/* Member size (in bits) */
163 163
	char	*ml_name;	/* Member name */
164 164
	struct	tdesc *ml_type;	/* Member type */
165 165
	struct	mlist *ml_next;	/* Next member */
tools/ctf/cvt/dwarf.c (working copy)
674 674
		tdesc_t *dimtdp;
675 675
		int flags;
676 676

  
677
		/* Check for bogus gcc DW_AT_byte_size attribute */
678
		if (uval == (unsigned)-1) {
679
			printf("dwarf.c:%s() working around bogus DW_AT_byte_size = 0xffffffff\n",
680
			    __func__);
681
			uval = 0;
682
		}
683
		
677 684
		tdp->t_size = uval;
678 685

  
679 686
		/*
......
760 767
	tdp->t_type = ENUM;
761 768

  
762 769
	(void) die_unsigned(dw, die, DW_AT_byte_size, &uval, DW_ATTR_REQ);
770
	/* Check for bogus gcc DW_AT_byte_size attribute */
771
	if (uval == (unsigned)-1) {
772
		printf("dwarf.c:%s() working around bogus DW_AT_byte_size = 0xffffffff\n",
773
		    __func__); 
774
		uval = 0;
775
	}
763 776
	tdp->t_size = uval;
764 777

  
765 778
	if ((mem = die_child(dw, die)) != NULL) {
......
873 886
die_sou_create(dwarf_t *dw, Dwarf_Die str, Dwarf_Off off, tdesc_t *tdp,
874 887
    int type, const char *typename)
875 888
{
876
	Dwarf_Unsigned sz, bitsz, bitoff;
889
	Dwarf_Unsigned sz, bitsz, bitoff, maxsz=0;
877 890
	Dwarf_Die mem;
878 891
	mlist_t *ml, **mlastp;
879 892
	iidesc_t *ii;
......
929 942
			ml->ml_name = NULL;
930 943

  
931 944
		ml->ml_type = die_lookup_pass1(dw, mem, DW_AT_type);
945
		debug(3, "die_sou_create(): ml_type = %p t_id = %d\n", ml->ml_type,
946
		    ml->ml_type->t_id);
932 947

  
933 948
		if (die_mem_offset(dw, mem, DW_AT_data_member_location,
934 949
		    &mloff, 0)) {
......
956 971

  
957 972
		*mlastp = ml;
958 973
		mlastp = &ml->ml_next;
974

  
975
		/* work out the size of the largest member to work around a gcc bug */
976
		if (maxsz < ml->ml_size) {
977
		    maxsz = ml->ml_size;
978
		}
959 979
	} while ((mem = die_sibling(dw, mem)) != NULL);
960 980

  
981
	/* See if we got a bogus DW_AT_byte_size.  GCC will sometimes
982
	 * emit this.
983
	 */
984
	if (sz == (unsigned)-1) {
985
		 printf("dwarf.c:%s() working around bogus DW_AT_byte_size = 0xffffffff\n",
986
		     __func__);
987
		 tdp->t_size = maxsz / 8;  /* maxsz is in bits, t_size is bytes */
988
	}
989

  
961 990
	/*
962 991
	 * GCC will attempt to eliminate unused types, thus decreasing the
963 992
	 * size of the emitted dwarf.  That is, if you declare a foo_t in your
......
1054 1083
		}
1055 1084

  
1056 1085
		if (ml->ml_size != 0 && mt->t_type == INTRINSIC &&
1057
		    mt->t_intr->intr_nbits != ml->ml_size) {
1086
		    mt->t_intr->intr_nbits != (int)ml->ml_size) {
1058 1087
			/*
1059 1088
			 * This member is a bitfield, and needs to reference
1060 1089
			 * an intrinsic type with the same width.  If the
......
1370 1399
	 */
1371 1400
	(void) die_unsigned(dw, base, DW_AT_byte_size, &sz, DW_ATTR_REQ);
1372 1401

  
1402
	/* Check for bogus gcc DW_AT_byte_size attribute */
1403
	if (sz == (unsigned)-1) {
1404
		printf("dwarf.c:%s() working around bogus DW_AT_byte_size = 0xffffffff\n",
1405
		    __func__);
1406
		sz = 0;
1407
	}
1408

  
1373 1409
	if (tdp->t_name == NULL)
1374 1410
		terminate("die %llu: base type without name\n", off);
1375 1411

  
tools/ctf/cvt/st_parse.c (working copy)
952 952

  
953 953
		itdp = find_intrinsic(tdp);
954 954
		if (itdp->t_type == INTRINSIC) {
955
			if (mlp->ml_size != itdp->t_intr->intr_nbits) {
955
			if ((int)mlp->ml_size != itdp->t_intr->intr_nbits) {
956 956
				parse_debug(4, cp, "making %d bit intrinsic "
957 957
				    "from %s", mlp->ml_size, tdesc_name(itdp));
958 958
				mlp->ml_type = bitintrinsic(itdp, mlp->ml_size);
......
1173 1173
	while (tdp) {
1174 1174
		switch (tdp->t_type) {
1175 1175
		case INTRINSIC:
1176
			if (ml->ml_size != tdp->t_intr->intr_nbits) {
1176
			if ((int)ml->ml_size != tdp->t_intr->intr_nbits) {
1177 1177
				debug(3, "making %d bit intrinsic from %s",
1178 1178
				    ml->ml_size, tdesc_name(tdp));
1179 1179
				ml->ml_type = bitintrinsic(tdp, ml->ml_size);
(3-3/3)