aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2022-03-23 12:31:29 +0100
committerJan Beulich <jbeulich@suse.com>2022-03-23 12:31:29 +0100
commite52a16f2aa20773f42c28bf91a568d0683e5767c (patch)
treee591957158986d497d4aa013a975cd55115767fb
parent64d23078e30e54e1bb095962540e4c6138edaf5a (diff)
downloadgdb-e52a16f2aa20773f42c28bf91a568d0683e5767c.zip
gdb-e52a16f2aa20773f42c28bf91a568d0683e5767c.tar.gz
gdb-e52a16f2aa20773f42c28bf91a568d0683e5767c.tar.bz2
x86: reject relocations involving registers
To prevent fatal or even internal errors, add a simple check to i386_validate_fix(), rejecting relocations when their target symbol is an equate of a register (or resolved to reg_section for any other reason).
-rw-r--r--gas/config/tc-i386.c11
-rw-r--r--gas/testsuite/gas/i386/inval-equ-2.l6
2 files changed, 17 insertions, 0 deletions
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 93eec1c..7617792 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -14188,6 +14188,17 @@ i386_cons_align (int ignore ATTRIBUTE_UNUSED)
int
i386_validate_fix (fixS *fixp)
{
+ if (fixp->fx_addsy && S_GET_SEGMENT(fixp->fx_addsy) == reg_section)
+ {
+ reloc_howto_type *howto;
+
+ howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
+ as_bad_where (fixp->fx_file, fixp->fx_line,
+ _("invalid %s relocation against register"),
+ howto ? howto->name : "<unknown>");
+ return 0;
+ }
+
#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
if (fixp->fx_r_type == BFD_RELOC_SIZE32
|| fixp->fx_r_type == BFD_RELOC_SIZE64)
diff --git a/gas/testsuite/gas/i386/inval-equ-2.l b/gas/testsuite/gas/i386/inval-equ-2.l
index 11f5e4e..839bc8d 100644
--- a/gas/testsuite/gas/i386/inval-equ-2.l
+++ b/gas/testsuite/gas/i386/inval-equ-2.l
@@ -1,4 +1,7 @@
.*: Assembler messages:
+.*:3: Error: .*
+.*:5: Error: .*
+.*:8: Error: .*
.*: Error: .*
.*: Error: .*
.*: Error: .*
@@ -15,6 +18,9 @@ GAS LISTING .*
[ ]*6[ ]+\.globl bar2
[ ]*7[ ]+\.set bar3,\(%eax\+1\)
[ ]*8[ ]+\?\?\?\? A1...... mov bar3,%eax
+.* Error: invalid .* relocation against register
+.* Error: invalid .* relocation against register
+.* Error: invalid .* relocation against register
.* Error: can't make global register symbol `bar1'
.* Error: can't make global register symbol `bar2'
.* Error: can't make global register symbol `bar3'