Revise sleb128 and uleb128 reader

This patch catches and reports errors when reading leb128 values,
addressing a FIXME in read_leb128.

	* dwarf.h (read_leb128): Update prototype.
	(report_leb_status): New inline function.
	(SKIP_ULEB, SKIP_SLEB, READ_ULEB, READ_SLEB): Define.
	* dwarf.c: Use above macros throughout file.  Formatting.
	(read_leb128): Reorder params.  Add status return param.
	Don't stop reading until finding terminator or end of data.
	Detect loss of significant bits.  Sign extend only on
	terminating byte.
	(read_sleb128, read_uleb128): Delete functions.
	(SKIP_ULEB, SKIP_SLEB, READ_ULEB, READ_SLEB): Delete macros.
	(read_and_print_leb128): Rewrite.
	(process_extended_line_op): Return a size_t.  Use size_t vars.
	Adjust to suit new macros.  Add proper name size to "data" when
	processing DW_LNE_define_file.
	(process_abbrev_section): Adjust to suit new macros.
	(decode_location_expression, skip_attr_bytes): Likewise.
	(get_type_signedness): Likewise.
	(read_and_display_attr_value): Likewise.  Consolidate block code.
	(process_debug_info): Adjust to suit new macros.
	(display_formatted_table, display_debug_lines_raw): Likewise.
	(display_debug_lines_decoded): Likewise.  Properly check for end
	of DW_LNS_extended_op.
	(display_debug_macinfo): Adjust to suit new macros.
	(get_line_filename_and_dirname, display_debug_macro): Likewise.
	(display_view_pair_list): Likewise.  Don't back off when hitting
	end of data.
	(display_loc_list): Adjust to suit new macros.
	(display_loclists_list, display_loc_list_dwo): Likewise.
	(display_debug_rnglists_list, read_cie): Likewise.
	(display_debug_frames): Likewise.
	* readelf.c: Use new ULEB macros throughout file.
	(read_uleb128): Delete.
	(decode_arm_unwind_bytecode): Use read_leb128.
	(decode_tic6x_unwind_bytecode): Likewise.
	(display_tag_value): Adjust to suit new macros.
	(display_arc_attribute, display_arm_attribute): Likewise.
	(display_gnu_attribute, display_power_gnu_attribute): Likewise.
	(display_s390_gnu_attribute, display_sparc_gnu_attribute): Likewise.
	(display_mips_gnu_attribute, display_tic6x_attribute): Likewise.
	(display_msp430x_attribute, display_msp430_gnu_attribute): Likewise.
	(display_riscv_attribute, process_attributes): Likewise.
This commit is contained in:
Alan Modra 2019-12-23 18:01:34 +10:30
parent 27c1c4271a
commit cd30bcef4a
4 changed files with 798 additions and 1030 deletions

View File

@ -1,3 +1,47 @@
2019-12-23 Alan Modra <amodra@gmail.com>
* dwarf.h (read_leb128): Update prototype.
(report_leb_status): New inline function.
(SKIP_ULEB, SKIP_SLEB, READ_ULEB, READ_SLEB): Define.
* dwarf.c: Use above macros throughout file. Formatting.
(read_leb128): Reorder params. Add status return param.
Don't stop reading until finding terminator or end of data.
Detect loss of significant bits. Sign extend only on
terminating byte.
(read_sleb128, read_uleb128): Delete functions.
(SKIP_ULEB, SKIP_SLEB, READ_ULEB, READ_SLEB): Delete macros.
(read_and_print_leb128): Rewrite.
(process_extended_line_op): Return a size_t. Use size_t vars.
Adjust to suit new macros. Add proper name size to "data" when
processing DW_LNE_define_file.
(process_abbrev_section): Adjust to suit new macros.
(decode_location_expression, skip_attr_bytes): Likewise.
(get_type_signedness): Likewise.
(read_and_display_attr_value): Likewise. Consolidate block code.
(process_debug_info): Adjust to suit new macros.
(display_formatted_table, display_debug_lines_raw): Likewise.
(display_debug_lines_decoded): Likewise. Properly check for end
of DW_LNS_extended_op.
(display_debug_macinfo): Adjust to suit new macros.
(get_line_filename_and_dirname, display_debug_macro): Likewise.
(display_view_pair_list): Likewise. Don't back off when hitting
end of data.
(display_loc_list): Adjust to suit new macros.
(display_loclists_list, display_loc_list_dwo): Likewise.
(display_debug_rnglists_list, read_cie): Likewise.
(display_debug_frames): Likewise.
* readelf.c: Use new ULEB macros throughout file.
(read_uleb128): Delete.
(decode_arm_unwind_bytecode): Use read_leb128.
(decode_tic6x_unwind_bytecode): Likewise.
(display_tag_value): Adjust to suit new macros.
(display_arc_attribute, display_arm_attribute): Likewise.
(display_gnu_attribute, display_power_gnu_attribute): Likewise.
(display_s390_gnu_attribute, display_sparc_gnu_attribute): Likewise.
(display_mips_gnu_attribute, display_tic6x_attribute): Likewise.
(display_msp430x_attribute, display_msp430_gnu_attribute): Likewise.
(display_riscv_attribute, process_attributes): Likewise.
2019-12-17 Alan Modra <amodra@gmail.com> 2019-12-17 Alan Modra <amodra@gmail.com>
* objdump.c (compare_section): New static var. * objdump.c (compare_section): New static var.

File diff suppressed because it is too large Load Diff

View File

@ -248,9 +248,65 @@ extern void * xcalloc2 (size_t, size_t);
extern void * xcmalloc (size_t, size_t); extern void * xcmalloc (size_t, size_t);
extern void * xcrealloc (void *, size_t, size_t); extern void * xcrealloc (void *, size_t, size_t);
extern dwarf_vma read_leb128 (unsigned char *, unsigned int *, bfd_boolean, const unsigned char * const);
/* A callback into the client. Returns TRUE if there is a /* A callback into the client. Returns TRUE if there is a
relocation against the given debug section at the given relocation against the given debug section at the given
offset. */ offset. */
extern bfd_boolean reloc_at (struct dwarf_section *, dwarf_vma); extern bfd_boolean reloc_at (struct dwarf_section *, dwarf_vma);
extern dwarf_vma read_leb128 (unsigned char *, const unsigned char *const,
bfd_boolean, unsigned int *, int *);
static inline void
report_leb_status (int status)
{
if ((status & 1) != 0)
error (_("LEB end of data\n"));
else if ((status & 2) != 0)
error (_("LEB value too large\n"));
}
#define SKIP_ULEB(start, end) \
do \
{ \
unsigned int _len; \
read_leb128 (start, end, FALSE, &_len, NULL); \
start += _len; \
} while (0)
#define SKIP_SLEB(start, end) \
do \
{ \
unsigned int _len; \
read_leb128 (start, end, TRUE, &_len, NULL); \
start += _len; \
} while (0)
#define READ_ULEB(var, start, end) \
do \
{ \
dwarf_vma _val; \
unsigned int _len; \
int _status; \
\
_val = read_leb128 (start, end, FALSE, &_len, &_status); \
start += _len; \
(var) = _val; \
if ((var) != _val) \
_status |= 2; \
report_leb_status (_status); \
} while (0)
#define READ_SLEB(var, start, end) \
do \
{ \
dwarf_signed_vma _val; \
unsigned int _len; \
int _status; \
\
_val = read_leb128 (start, end, TRUE, &_len, &_status); \
start += _len; \
(var) = _val; \
if ((var) != _val) \
_status |= 2; \
report_leb_status (_status); \
} while (0)

View File

@ -749,17 +749,6 @@ find_section_in_set (Filedata * filedata, const char * name, unsigned int * set)
return find_section (filedata, name); return find_section (filedata, name);
} }
/* Read an unsigned LEB128 encoded value from DATA.
Set *LENGTH_RETURN to the number of bytes read. */
static inline unsigned long
read_uleb128 (unsigned char * data,
unsigned int * length_return,
const unsigned char * const end)
{
return read_leb128 (data, length_return, FALSE, end);
}
/* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI. /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI.
This OS has so many departures from the ELF standard that we test it at This OS has so many departures from the ELF standard that we test it at
many places. */ many places. */
@ -8782,7 +8771,7 @@ decode_arm_unwind_bytecode (Filedata * filedata,
} }
else else
{ {
offset = read_uleb128 (buf, &len, buf + i + 1); offset = read_leb128 (buf, buf + i + 1, FALSE, &len, NULL);
assert (len == i + 1); assert (len == i + 1);
offset = offset * 4 + 0x204; offset = offset * 4 + 0x204;
printf ("vsp = vsp + %ld", offset); printf ("vsp = vsp + %ld", offset);
@ -9001,7 +8990,7 @@ decode_tic6x_unwind_bytecode (Filedata * filedata,
return FALSE; return FALSE;
} }
offset = read_uleb128 (buf, &len, buf + i + 1); offset = read_leb128 (buf, buf + i + 1, FALSE, &len, NULL);
assert (len == i + 1); assert (len == i + 1);
offset = offset * 8 + 0x408; offset = offset * 8 + 0x408;
printf (_("sp = sp + %ld"), offset); printf (_("sp = sp + %ld"), offset);
@ -14492,10 +14481,7 @@ display_tag_value (signed int tag,
} }
else else
{ {
unsigned int len; READ_ULEB (val, p, end);
val = read_uleb128 (p, &len, end);
p += len;
printf ("%ld (0x%lx)\n", val, val); printf ("%ld (0x%lx)\n", val, val);
} }
@ -14510,17 +14496,14 @@ display_arc_attribute (unsigned char * p,
const unsigned char * const end) const unsigned char * const end)
{ {
unsigned int tag; unsigned int tag;
unsigned int len;
unsigned int val; unsigned int val;
tag = read_uleb128 (p, &len, end); READ_ULEB (tag, p, end);
p += len;
switch (tag) switch (tag)
{ {
case Tag_ARC_PCS_config: case Tag_ARC_PCS_config:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ARC_PCS_config: "); printf (" Tag_ARC_PCS_config: ");
switch (val) switch (val)
{ {
@ -14546,8 +14529,7 @@ display_arc_attribute (unsigned char * p,
break; break;
case Tag_ARC_CPU_base: case Tag_ARC_CPU_base:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ARC_CPU_base: "); printf (" Tag_ARC_CPU_base: ");
switch (val) switch (val)
{ {
@ -14571,8 +14553,7 @@ display_arc_attribute (unsigned char * p,
break; break;
case Tag_ARC_CPU_variation: case Tag_ARC_CPU_variation:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ARC_CPU_variation: "); printf (" Tag_ARC_CPU_variation: ");
switch (val) switch (val)
{ {
@ -14595,21 +14576,18 @@ display_arc_attribute (unsigned char * p,
break; break;
case Tag_ARC_ABI_rf16: case Tag_ARC_ABI_rf16:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no")); printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no"));
break; break;
case Tag_ARC_ABI_osver: case Tag_ARC_ABI_osver:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ARC_ABI_osver: v%d\n", val); printf (" Tag_ARC_ABI_osver: v%d\n", val);
break; break;
case Tag_ARC_ABI_pic: case Tag_ARC_ABI_pic:
case Tag_ARC_ABI_sda: case Tag_ARC_ABI_sda:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: " printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: "
: " Tag_ARC_ABI_pic: "); : " Tag_ARC_ABI_pic: ");
switch (val) switch (val)
@ -14630,28 +14608,24 @@ display_arc_attribute (unsigned char * p,
break; break;
case Tag_ARC_ABI_tls: case Tag_ARC_ABI_tls:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none"); printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none");
break; break;
case Tag_ARC_ABI_enumsize: case Tag_ARC_ABI_enumsize:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") : printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") :
_("smallest")); _("smallest"));
break; break;
case Tag_ARC_ABI_exceptions: case Tag_ARC_ABI_exceptions:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP") printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP")
: _("default")); : _("default"));
break; break;
case Tag_ARC_ABI_double_size: case Tag_ARC_ABI_double_size:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ARC_ABI_double_size: %d\n", val); printf (" Tag_ARC_ABI_double_size: %d\n", val);
break; break;
@ -14666,14 +14640,12 @@ display_arc_attribute (unsigned char * p,
break; break;
case Tag_ARC_ISA_mpy_option: case Tag_ARC_ISA_mpy_option:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ARC_ISA_mpy_option: %d\n", val); printf (" Tag_ARC_ISA_mpy_option: %d\n", val);
break; break;
case Tag_ARC_ATR_version: case Tag_ARC_ATR_version:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ARC_ATR_version: %d\n", val); printf (" Tag_ARC_ATR_version: %d\n", val);
break; break;
@ -14818,14 +14790,12 @@ display_arm_attribute (unsigned char * p,
const unsigned char * const end) const unsigned char * const end)
{ {
unsigned int tag; unsigned int tag;
unsigned int len;
unsigned int val; unsigned int val;
arm_attr_public_tag * attr; arm_attr_public_tag * attr;
unsigned i; unsigned i;
unsigned int type; unsigned int type;
tag = read_uleb128 (p, &len, end); READ_ULEB (tag, p, end);
p += len;
attr = NULL; attr = NULL;
for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++) for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
{ {
@ -14845,8 +14815,7 @@ display_arm_attribute (unsigned char * p,
switch (tag) switch (tag)
{ {
case 7: /* Tag_CPU_arch_profile. */ case 7: /* Tag_CPU_arch_profile. */
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
switch (val) switch (val)
{ {
case 0: printf (_("None\n")); break; case 0: printf (_("None\n")); break;
@ -14859,8 +14828,7 @@ display_arm_attribute (unsigned char * p,
break; break;
case 24: /* Tag_align_needed. */ case 24: /* Tag_align_needed. */
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
switch (val) switch (val)
{ {
case 0: printf (_("None\n")); break; case 0: printf (_("None\n")); break;
@ -14878,8 +14846,7 @@ display_arm_attribute (unsigned char * p,
break; break;
case 25: /* Tag_align_preserved. */ case 25: /* Tag_align_preserved. */
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
switch (val) switch (val)
{ {
case 0: printf (_("None\n")); break; case 0: printf (_("None\n")); break;
@ -14898,8 +14865,7 @@ display_arm_attribute (unsigned char * p,
case 32: /* Tag_compatibility. */ case 32: /* Tag_compatibility. */
{ {
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (_("flag = %d, vendor = "), val); printf (_("flag = %d, vendor = "), val);
if (p < end - 1) if (p < end - 1)
{ {
@ -14925,12 +14891,10 @@ display_arm_attribute (unsigned char * p,
break; break;
case 65: /* Tag_also_compatible_with. */ case 65: /* Tag_also_compatible_with. */
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
if (val == 6 /* Tag_CPU_arch. */) if (val == 6 /* Tag_CPU_arch. */)
{ {
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch)) if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch))
printf ("??? (%d)\n", val); printf ("??? (%d)\n", val);
else else
@ -14955,8 +14919,7 @@ display_arm_attribute (unsigned char * p,
default: default:
assert (attr->type & 0x80); assert (attr->type & 0x80);
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
type = attr->type & 0x7f; type = attr->type & 0x7f;
if (val >= type) if (val >= type)
printf ("??? (%d)\n", val); printf ("??? (%d)\n", val);
@ -14974,19 +14937,16 @@ display_gnu_attribute (unsigned char * p,
unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const), unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const),
const unsigned char * const end) const unsigned char * const end)
{ {
int tag; unsigned int tag;
unsigned int len;
unsigned int val; unsigned int val;
tag = read_uleb128 (p, &len, end); READ_ULEB (tag, p, end);
p += len;
/* Tag_compatibility is the only generic GNU attribute defined at /* Tag_compatibility is the only generic GNU attribute defined at
present. */ present. */
if (tag == 32) if (tag == 32)
{ {
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (_("flag = %d, vendor = "), val); printf (_("flag = %d, vendor = "), val);
if (p == end) if (p == end)
@ -15024,19 +14984,17 @@ display_power_gnu_attribute (unsigned char * p,
unsigned int tag, unsigned int tag,
const unsigned char * const end) const unsigned char * const end)
{ {
unsigned int len;
unsigned int val; unsigned int val;
if (tag == Tag_GNU_Power_ABI_FP) if (tag == Tag_GNU_Power_ABI_FP)
{ {
val = read_uleb128 (p, &len, end);
p += len;
printf (" Tag_GNU_Power_ABI_FP: "); printf (" Tag_GNU_Power_ABI_FP: ");
if (len == 0) if (p == end)
{ {
printf (_("<corrupt>\n")); printf (_("<corrupt>\n"));
return p; return p;
} }
READ_ULEB (val, p, end);
if (val > 15) if (val > 15)
printf ("(%#x), ", val); printf ("(%#x), ", val);
@ -15077,14 +15035,13 @@ display_power_gnu_attribute (unsigned char * p,
if (tag == Tag_GNU_Power_ABI_Vector) if (tag == Tag_GNU_Power_ABI_Vector)
{ {
val = read_uleb128 (p, &len, end);
p += len;
printf (" Tag_GNU_Power_ABI_Vector: "); printf (" Tag_GNU_Power_ABI_Vector: ");
if (len == 0) if (p == end)
{ {
printf (_("<corrupt>\n")); printf (_("<corrupt>\n"));
return p; return p;
} }
READ_ULEB (val, p, end);
if (val > 3) if (val > 3)
printf ("(%#x), ", val); printf ("(%#x), ", val);
@ -15109,14 +15066,13 @@ display_power_gnu_attribute (unsigned char * p,
if (tag == Tag_GNU_Power_ABI_Struct_Return) if (tag == Tag_GNU_Power_ABI_Struct_Return)
{ {
val = read_uleb128 (p, &len, end);
p += len;
printf (" Tag_GNU_Power_ABI_Struct_Return: "); printf (" Tag_GNU_Power_ABI_Struct_Return: ");
if (len == 0) if (p == end)
{ {
printf (_("<corrupt>\n")); printf (_("<corrupt>\n"));
return p; return p;
} }
READ_ULEB (val, p, end);
if (val > 2) if (val > 2)
printf ("(%#x), ", val); printf ("(%#x), ", val);
@ -15147,14 +15103,12 @@ display_s390_gnu_attribute (unsigned char * p,
unsigned int tag, unsigned int tag,
const unsigned char * const end) const unsigned char * const end)
{ {
unsigned int len; unsigned int val;
int val;
if (tag == Tag_GNU_S390_ABI_Vector) if (tag == Tag_GNU_S390_ABI_Vector)
{ {
val = read_uleb128 (p, &len, end);
p += len;
printf (" Tag_GNU_S390_ABI_Vector: "); printf (" Tag_GNU_S390_ABI_Vector: ");
READ_ULEB (val, p, end);
switch (val) switch (val)
{ {
@ -15262,21 +15216,18 @@ display_sparc_gnu_attribute (unsigned char * p,
unsigned int tag, unsigned int tag,
const unsigned char * const end) const unsigned char * const end)
{ {
unsigned int len; unsigned int val;
int val;
if (tag == Tag_GNU_Sparc_HWCAPS) if (tag == Tag_GNU_Sparc_HWCAPS)
{ {
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_GNU_Sparc_HWCAPS: "); printf (" Tag_GNU_Sparc_HWCAPS: ");
display_sparc_hwcaps (val); display_sparc_hwcaps (val);
return p; return p;
} }
if (tag == Tag_GNU_Sparc_HWCAPS2) if (tag == Tag_GNU_Sparc_HWCAPS2)
{ {
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_GNU_Sparc_HWCAPS2: "); printf (" Tag_GNU_Sparc_HWCAPS2: ");
display_sparc_hwcaps2 (val); display_sparc_hwcaps2 (val);
return p; return p;
@ -15330,26 +15281,20 @@ display_mips_gnu_attribute (unsigned char * p,
{ {
if (tag == Tag_GNU_MIPS_ABI_FP) if (tag == Tag_GNU_MIPS_ABI_FP)
{ {
unsigned int len;
unsigned int val; unsigned int val;
val = read_uleb128 (p, &len, end);
p += len;
printf (" Tag_GNU_MIPS_ABI_FP: "); printf (" Tag_GNU_MIPS_ABI_FP: ");
READ_ULEB (val, p, end);
print_mips_fp_abi_value (val); print_mips_fp_abi_value (val);
return p; return p;
} }
if (tag == Tag_GNU_MIPS_ABI_MSA) if (tag == Tag_GNU_MIPS_ABI_MSA)
{ {
unsigned int len;
unsigned int val; unsigned int val;
val = read_uleb128 (p, &len, end);
p += len;
printf (" Tag_GNU_MIPS_ABI_MSA: "); printf (" Tag_GNU_MIPS_ABI_MSA: ");
READ_ULEB (val, p, end);
switch (val) switch (val)
{ {
@ -15374,18 +15319,15 @@ display_tic6x_attribute (unsigned char * p,
const unsigned char * const end) const unsigned char * const end)
{ {
unsigned int tag; unsigned int tag;
unsigned int len; unsigned int val;
int val;
tag = read_uleb128 (p, &len, end); READ_ULEB (tag, p, end);
p += len;
switch (tag) switch (tag)
{ {
case Tag_ISA: case Tag_ISA:
val = read_uleb128 (p, &len, end);
p += len;
printf (" Tag_ISA: "); printf (" Tag_ISA: ");
READ_ULEB (val, p, end);
switch (val) switch (val)
{ {
@ -15417,9 +15359,8 @@ display_tic6x_attribute (unsigned char * p,
return p; return p;
case Tag_ABI_wchar_t: case Tag_ABI_wchar_t:
val = read_uleb128 (p, &len, end);
p += len;
printf (" Tag_ABI_wchar_t: "); printf (" Tag_ABI_wchar_t: ");
READ_ULEB (val, p, end);
switch (val) switch (val)
{ {
case 0: case 0:
@ -15438,9 +15379,8 @@ display_tic6x_attribute (unsigned char * p,
return p; return p;
case Tag_ABI_stack_align_needed: case Tag_ABI_stack_align_needed:
val = read_uleb128 (p, &len, end);
p += len;
printf (" Tag_ABI_stack_align_needed: "); printf (" Tag_ABI_stack_align_needed: ");
READ_ULEB (val, p, end);
switch (val) switch (val)
{ {
case 0: case 0:
@ -15456,8 +15396,7 @@ display_tic6x_attribute (unsigned char * p,
return p; return p;
case Tag_ABI_stack_align_preserved: case Tag_ABI_stack_align_preserved:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ABI_stack_align_preserved: "); printf (" Tag_ABI_stack_align_preserved: ");
switch (val) switch (val)
{ {
@ -15474,8 +15413,7 @@ display_tic6x_attribute (unsigned char * p,
return p; return p;
case Tag_ABI_DSBT: case Tag_ABI_DSBT:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ABI_DSBT: "); printf (" Tag_ABI_DSBT: ");
switch (val) switch (val)
{ {
@ -15492,8 +15430,7 @@ display_tic6x_attribute (unsigned char * p,
return p; return p;
case Tag_ABI_PID: case Tag_ABI_PID:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ABI_PID: "); printf (" Tag_ABI_PID: ");
switch (val) switch (val)
{ {
@ -15513,8 +15450,7 @@ display_tic6x_attribute (unsigned char * p,
return p; return p;
case Tag_ABI_PIC: case Tag_ABI_PIC:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ABI_PIC: "); printf (" Tag_ABI_PIC: ");
switch (val) switch (val)
{ {
@ -15531,8 +15467,7 @@ display_tic6x_attribute (unsigned char * p,
return p; return p;
case Tag_ABI_array_object_alignment: case Tag_ABI_array_object_alignment:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ABI_array_object_alignment: "); printf (" Tag_ABI_array_object_alignment: ");
switch (val) switch (val)
{ {
@ -15552,8 +15487,7 @@ display_tic6x_attribute (unsigned char * p,
return p; return p;
case Tag_ABI_array_object_align_expected: case Tag_ABI_array_object_align_expected:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ABI_array_object_align_expected: "); printf (" Tag_ABI_array_object_align_expected: ");
switch (val) switch (val)
{ {
@ -15574,8 +15508,7 @@ display_tic6x_attribute (unsigned char * p,
case Tag_ABI_compatibility: case Tag_ABI_compatibility:
{ {
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf (" Tag_ABI_compatibility: "); printf (" Tag_ABI_compatibility: ");
printf (_("flag = %d, vendor = "), val); printf (_("flag = %d, vendor = "), val);
if (p < end - 1) if (p < end - 1)
@ -15666,19 +15599,16 @@ static unsigned char *
display_msp430x_attribute (unsigned char * p, display_msp430x_attribute (unsigned char * p,
const unsigned char * const end) const unsigned char * const end)
{ {
unsigned int len;
unsigned int val; unsigned int val;
unsigned int tag; unsigned int tag;
tag = read_uleb128 (p, & len, end); READ_ULEB (tag, p, end);
p += len;
switch (tag) switch (tag)
{ {
case OFBA_MSPABI_Tag_ISA: case OFBA_MSPABI_Tag_ISA:
val = read_uleb128 (p, &len, end);
p += len;
printf (" Tag_ISA: "); printf (" Tag_ISA: ");
READ_ULEB (val, p, end);
switch (val) switch (val)
{ {
case 0: printf (_("None\n")); break; case 0: printf (_("None\n")); break;
@ -15689,9 +15619,8 @@ display_msp430x_attribute (unsigned char * p,
break; break;
case OFBA_MSPABI_Tag_Code_Model: case OFBA_MSPABI_Tag_Code_Model:
val = read_uleb128 (p, &len, end);
p += len;
printf (" Tag_Code_Model: "); printf (" Tag_Code_Model: ");
READ_ULEB (val, p, end);
switch (val) switch (val)
{ {
case 0: printf (_("None\n")); break; case 0: printf (_("None\n")); break;
@ -15702,9 +15631,8 @@ display_msp430x_attribute (unsigned char * p,
break; break;
case OFBA_MSPABI_Tag_Data_Model: case OFBA_MSPABI_Tag_Data_Model:
val = read_uleb128 (p, &len, end);
p += len;
printf (" Tag_Data_Model: "); printf (" Tag_Data_Model: ");
READ_ULEB (val, p, end);
switch (val) switch (val)
{ {
case 0: printf (_("None\n")); break; case 0: printf (_("None\n")); break;
@ -15737,8 +15665,7 @@ display_msp430x_attribute (unsigned char * p,
} }
else else
{ {
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
printf ("%d (0x%x)\n", val, val); printf ("%d (0x%x)\n", val, val);
} }
break; break;
@ -15755,12 +15682,10 @@ display_msp430_gnu_attribute (unsigned char * p,
{ {
if (tag == Tag_GNU_MSP430_Data_Region) if (tag == Tag_GNU_MSP430_Data_Region)
{ {
unsigned int len; unsigned int val;
int val;
val = read_uleb128 (p, &len, end);
p += len;
printf (" Tag_GNU_MSP430_Data_Region: "); printf (" Tag_GNU_MSP430_Data_Region: ");
READ_ULEB (val, p, end);
switch (val) switch (val)
{ {
@ -15771,7 +15696,7 @@ display_msp430_gnu_attribute (unsigned char * p,
printf (_("Lower Region Only\n")); printf (_("Lower Region Only\n"));
break; break;
default: default:
printf ("??? (%d)\n", val); printf ("??? (%u)\n", val);
} }
return p; return p;
} }
@ -15780,7 +15705,7 @@ display_msp430_gnu_attribute (unsigned char * p,
struct riscv_attr_tag_t { struct riscv_attr_tag_t {
const char *name; const char *name;
int tag; unsigned int tag;
}; };
static struct riscv_attr_tag_t riscv_attr_tag[] = static struct riscv_attr_tag_t riscv_attr_tag[] =
@ -15799,14 +15724,12 @@ static unsigned char *
display_riscv_attribute (unsigned char *p, display_riscv_attribute (unsigned char *p,
const unsigned char * const end) const unsigned char * const end)
{ {
unsigned int len; unsigned int val;
int val; unsigned int tag;
int tag;
struct riscv_attr_tag_t *attr = NULL; struct riscv_attr_tag_t *attr = NULL;
unsigned i; unsigned i;
tag = read_uleb128 (p, &len, end); READ_ULEB (tag, p, end);
p += len;
/* Find the name of attribute. */ /* Find the name of attribute. */
for (i = 0; i < ARRAY_SIZE (riscv_attr_tag); i++) for (i = 0; i < ARRAY_SIZE (riscv_attr_tag); i++)
@ -15828,13 +15751,11 @@ display_riscv_attribute (unsigned char *p,
case Tag_RISCV_priv_spec: case Tag_RISCV_priv_spec:
case Tag_RISCV_priv_spec_minor: case Tag_RISCV_priv_spec_minor:
case Tag_RISCV_priv_spec_revision: case Tag_RISCV_priv_spec_revision:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len; printf (_("%u\n"), val);
printf (_("%d\n"), val);
break; break;
case Tag_RISCV_unaligned_access: case Tag_RISCV_unaligned_access:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len;
switch (val) switch (val)
{ {
case 0: case 0:
@ -15846,9 +15767,8 @@ display_riscv_attribute (unsigned char *p,
} }
break; break;
case Tag_RISCV_stack_align: case Tag_RISCV_stack_align:
val = read_uleb128 (p, &len, end); READ_ULEB (val, p, end);
p += len; printf (_("%u-bytes\n"), val);
printf (_("%d-bytes\n"), val);
break; break;
case Tag_RISCV_arch: case Tag_RISCV_arch:
p = display_tag_value (-1, p, end); p = display_tag_value (-1, p, end);
@ -15967,7 +15887,7 @@ process_attributes (Filedata * filedata,
while (attr_len > 0 && p < contents + sect->sh_size) while (attr_len > 0 && p < contents + sect->sh_size)
{ {
int tag; int tag;
int val; unsigned int val;
bfd_vma size; bfd_vma size;
unsigned char * end; unsigned char * end;
@ -16018,10 +15938,7 @@ process_attributes (Filedata * filedata,
do_numlist: do_numlist:
for (;;) for (;;)
{ {
unsigned int j; READ_ULEB (val, p, end);
val = read_uleb128 (p, &j, end);
p += j;
if (val == 0) if (val == 0)
break; break;
printf (" %d", val); printf (" %d", val);