From 46fb6d5aa27d7129f472729a4f7ab8aa103aa674 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Mon, 21 Mar 2022 15:13:35 +0100 Subject: [PATCH] x86: don't suppress overflow diagnostics in x32 mode Unlike in 64-bit mode, where values wrap at the 64-bit boundary anyway, there's no wrapping at the 32-bit boundary here, and hence overflow detection shouldn't be suppressed just because rela relocations are going to be used. The extra check against NO_RELOC is actually a result of an ilp32 test otherwise failing. But thinking about it, reporting overflows for not-really-relocations (typically because of earlier errors) makes little sense in general. Perhaps this should even be extended to non- 64-bit modes. --- gas/config/tc-i386.c | 3 ++- gas/testsuite/gas/i386/ilp32/reloc64.l | 13 +++++++++++++ gas/testsuite/gas/i386/ilp32/reloc64.s | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c index 83975c3f99f..afb8b706bda 100644 --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -12769,7 +12769,8 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) #endif else if (use_rela_relocations) { - fixP->fx_no_overflow = 1; + if (!disallow_64bit_reloc || fixP->fx_r_type == NO_RELOC) + fixP->fx_no_overflow = 1; /* Remember value for tc_gen_reloc. */ fixP->fx_addnumber = value; value = 0; diff --git a/gas/testsuite/gas/i386/ilp32/reloc64.l b/gas/testsuite/gas/i386/ilp32/reloc64.l index 7a1808e4e96..9643e677782 100644 --- a/gas/testsuite/gas/i386/ilp32/reloc64.l +++ b/gas/testsuite/gas/i386/ilp32/reloc64.l @@ -52,3 +52,16 @@ .*:176: Error: .* .*:177: Error: .* .*:189: Error: .* +.*:192: Error: .* too large for field of 4 bytes at .* +.*:193: Error: .* too large for field of 4 bytes at .* +.*:194: Error: .* too large for field of 4 bytes at .* +.*:195: Error: .* too large for field of 4 bytes at .* +.*:196: Error: .* too large for field of 2 bytes at .* +.*:196: Error: .* too large for field of 1 byte at .* +.*:197: Error: .* too large for field of 2 bytes at .* +.*:197: Error: .* too large for field of 1 byte at .* +.*:200: Error: .* too large for field of 4 bytes at .* +.*:201: Error: .* too large for field of 2 bytes at .* +.*:202: Error: .* too large for field of 2 bytes at .* +.*:203: Error: .* too large for field of 1 byte at .* +.*:204: Error: .* too large for field of 1 byte at .* diff --git a/gas/testsuite/gas/i386/ilp32/reloc64.s b/gas/testsuite/gas/i386/ilp32/reloc64.s index 3ab25eff6c0..9f5990a300a 100644 --- a/gas/testsuite/gas/i386/ilp32/reloc64.s +++ b/gas/testsuite/gas/i386/ilp32/reloc64.s @@ -187,3 +187,18 @@ bad .byte xtrn@tpoff .long xtrn@got - 4 .long xtrn@got + 4 bad .long xtrn@plt - . + + .text +bad add $x+0x123456789, %rax +bad add $x+0x123456789, %eax +bad add x+0x123456789, %eax +bad add x+0x123456789(%eax), %eax +bad enter $x+0x123456789, $x+0x123456789 +bad enter $x+0x12345, $x+0x123 + + .data +bad .long x+0x123456789 +bad .word x+0x123456789 +bad .word x+0x12345 +bad .byte x+0x123456789 +bad .byte x+0x123 -- 2.30.2