mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-21 04:42:53 +08:00
b9b204b311
There is a tiny error left in dwarf.c:read_leb128 after Nick fixed the signed overflow problem in code I wrote. It's to do with sleb128 values that have unnecessary excess bytes. For example, -1 is represented as 0x7f, the most efficient encoding, but also as 0xff,0x7f or 0xff,0xff,0x7f and so on. None of these sequences overflow any size signed value, but read_leb128 will report an overflow given enough excess bytes. This patch fixes that problem, and since the proper test for signed values with excess bytes can easily be adapted to also test a sleb byte with just some bits that overflow the result, I changed the code to not use signed right shifts. (The C standard ISO/IEC 9899:1999 6.5.7 says signed right shifts of negative values have an implementation defined value. A long time ago I even used a C compiler for a certain microprocessor that always did unsigned right shifts. Mind you, it is very unlikely to be compiling binutils with such a compiler.) bfd/ * wasm-module.c: Guard include of limits.h. (CHAR_BIT): Provide backup define. (wasm_read_leb128): Use CHAR_BIT to size "result" in bits. Correct signed overflow checking. opcodes/ * wasm32-dis.c: Include limits.h. (CHAR_BIT): Provide backup define. (wasm_read_leb128): Use CHAR_BIT to size "result" in bits. Correct signed overflow checking. binutils/ * dwarf.c: Include limits.h. (CHAR_BIT): Provide backup define. (read_leb128): Use CHAR_BIT to size "result" in bits. Correct signed overflow checking. * testsuite/binutils-all/pr26548.s, * testsuite/binutils-all/pr26548.d, * testsuite/binutils-all/pr26548e.d: New tests. * testsuite/binutils-all/readelf.exp: Run them. (readelf_test): Drop unused "xfails" parameter. Update all uses.
41 lines
836 B
ArmAsm
41 lines
836 B
ArmAsm
.section .debug_abbrev
|
|
1:
|
|
.uleb128 1
|
|
# DW_TAG_variable
|
|
.uleb128 0x34
|
|
# no children
|
|
.byte 0
|
|
# DW_AT_const_value
|
|
.uleb128 0x1c
|
|
# DW_FORM_sdata
|
|
.uleb128 0x0d
|
|
.byte 0,0
|
|
.byte 0
|
|
|
|
.section .debug_info
|
|
.4byte 9f-0f
|
|
0:
|
|
.2byte 4
|
|
.4byte 1b
|
|
.byte 8
|
|
.ifndef ERROR
|
|
.uleb128 1
|
|
.sleb128 0x7fffffffffffffff
|
|
.uleb128 1
|
|
.sleb128 -0x8000000000000000
|
|
.uleb128 1
|
|
# silly excess byte encoding of -1, no warning
|
|
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f
|
|
.uleb128 1
|
|
# silly excess byte encoding of 1, no warning
|
|
.byte 0x81,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0
|
|
.else
|
|
.uleb128 1
|
|
# encode +0x8000000000000000, readelf warning
|
|
.byte 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x01
|
|
.uleb128 1
|
|
# encode -0x8000000000000001, readelf warning
|
|
.byte 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3e
|
|
.endif
|
|
9:
|