RISC-V/GAS: Improve handling of invalid relocs
authorAndrew Waterman <andrew@sifive.com>
Wed, 21 Dec 2016 20:47:13 +0000 (12:47 -0800)
committerPalmer Dabbelt <palmer@dabbelt.com>
Mon, 9 Jan 2017 17:18:36 +0000 (09:18 -0800)
TLS relocs against constants previously segfaulted, and illegal
symbol subtractions were silently ignored.

The previous behavior was to segfault.

gas/ChangeLog

2017-01-09  Andrew Waterman <andrew@sifive.com>

* config/tc-riscv.c (md_apply_fix): Report TLS relocations against
constants.  Report disallowed symbol subtractions.

gas/ChangeLog
gas/config/tc-riscv.c

index 88f68a1..4de9cf7 100644 (file)
@@ -1,3 +1,9 @@
+2017-01-09  Andrew Waterman <andrew@sifive.com>
+
+       * config/tc-riscv.c (append_insn): Don't eagerly apply relocations
+       against constants.
+       (md_apply_fix): Mark relocations against constants as "done."
+
 2017-01-09  Palmer Dabbelt <palmer@dabbelt.com>
            Kito Cheng <kito.cheng@gmail.com>
 
index b8da6ce..3f09101 100644 (file)
@@ -1889,7 +1889,11 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_RISCV_TLS_GD_HI20:
     case BFD_RELOC_RISCV_TLS_DTPREL32:
     case BFD_RELOC_RISCV_TLS_DTPREL64:
-      S_SET_THREAD_LOCAL (fixP->fx_addsy);
+      if (fixP->fx_addsy != NULL)
+       S_SET_THREAD_LOCAL (fixP->fx_addsy);
+      else
+       as_bad_where (fixP->fx_file, fixP->fx_line,
+                     _("TLS relocation against a constant"));
       break;
 
     case BFD_RELOC_64:
@@ -2045,6 +2049,10 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
        as_fatal (_("internal error: bad relocation #%d"), fixP->fx_r_type);
     }
 
+  if (fixP->fx_subsy != NULL)
+    as_bad_where (fixP->fx_file, fixP->fx_line,
+                 _("unsupported symbol subtraction"));
+
   /* Add an R_RISCV_RELAX reloc if the reloc is relaxable.  */
   if (relaxable && fixP->fx_tcbit && fixP->fx_addsy != NULL)
     {