diff options
author | Jan Beulich <jbeulich@suse.com> | 2021-06-16 08:55:20 +0200 |
---|---|---|
committer | Jan Beulich <jbeulich@suse.com> | 2021-06-16 08:55:20 +0200 |
commit | 4504a6346777d544a144683bd2a534b686fbac41 (patch) | |
tree | 65f18b24a6c7df5caaf8eec8bd7ba25f7f466875 /gas/read.c | |
parent | b80d4475804d5f3c4e9d996229e1569b7b3c8426 (diff) | |
download | gdb-4504a6346777d544a144683bd2a534b686fbac41.zip gdb-4504a6346777d544a144683bd2a534b686fbac41.tar.gz gdb-4504a6346777d544a144683bd2a534b686fbac41.tar.bz2 |
gas: fix overflow diagnostics
While the logic in fixup_segment() so far was off by 1 for fixups
dealing with quantities without known signedness, thus failing to report
an overflow when e.g. a byte-sized resulting value is -0x100, the logic
in emit_expr_with_reloc() reported an overflow even on large negative
values when the respective positive ones would not be warned
about, and when fixup_segment() wouldn't do so either. Such diagnostics
all ought to follow a similar pattern of what value range is acceptable.
(If expressions' X_unsigned was reliably set, emit_expr_with_reloc()'s
checking might make sense to tighten based on that flag.)
Note that with commit 80aab57939a0 ("Changes to let cons handle bignums
like general expressions") having added handling of nbytes >
sizeof(valueT) in the O_constant case, converting to O_big, the setting
to zero of "hibit" had become dead. With "hibit" no longer used, this
code now gets dropped altogether. But additionally a respective know()
gets inserted.
Diffstat (limited to 'gas/read.c')
-rw-r--r-- | gas/read.c | 11 |
1 files changed, 2 insertions, 9 deletions
@@ -4505,24 +4505,19 @@ emit_expr_with_reloc (expressionS *exp, valueT get; valueT use; valueT mask; - valueT hibit; valueT unmask; /* JF << of >= number of bits in the object is undefined. In particular SPARC (Sun 4) has problems. */ if (nbytes >= sizeof (valueT)) { + know (nbytes == sizeof (valueT)); mask = 0; - if (nbytes > sizeof (valueT)) - hibit = 0; - else - hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1); } else { /* Don't store these bits. */ mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); - hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1); } unmask = ~mask; /* Do store these bits. */ @@ -4534,9 +4529,7 @@ emit_expr_with_reloc (expressionS *exp, get = exp->X_add_number; use = get & unmask; - if ((get & mask) != 0 - && ((get & mask) != mask - || (get & hibit) == 0)) + if ((get & mask) != 0 && (-get & mask) != 0) { /* Leading bits contain both 0s & 1s. */ as_warn (_("value 0x%" BFD_VMA_FMT "x truncated to 0x%" BFD_VMA_FMT "x"), |