aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2017-02-03 19:18:37 +1030
committerAlan Modra <amodra@gmail.com>2017-02-03 20:07:46 +1030
commit2e5c40b65afa4c29b60e795bb8ba2cefddc2d6c6 (patch)
tree594a89ad6f16754d06b91684da908ee9c343f137
parentfcbac04dd1e3dcfc0cba170915ac28a8a1058239 (diff)
downloadgdb-2e5c40b65afa4c29b60e795bb8ba2cefddc2d6c6.zip
gdb-2e5c40b65afa4c29b60e795bb8ba2cefddc2d6c6.tar.gz
gdb-2e5c40b65afa4c29b60e795bb8ba2cefddc2d6c6.tar.bz2
[GOLD] PowerPC64 TOC indirect to TOC relative segfault
* powerpc.cc (Powerpc_relobj::make_toc_relative): Don't crash when no .toc section exists.
-rw-r--r--gold/ChangeLog5
-rw-r--r--gold/powerpc.cc6
2 files changed, 11 insertions, 0 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index 1be238c..f36dae7 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-03 Alan Modra <amodra@gmail.com>
+
+ * powerpc.cc (Powerpc_relobj::make_toc_relative): Don't crash
+ when no .toc section exists.
+
2017-01-23 Vladimir Radosavljevic <Vladimir.Radosavljevic@imgtec.com>
* mips.cc (Mips_output_data_plt::rel_plt): Remove const from return
diff --git a/gold/powerpc.cc b/gold/powerpc.cc
index a67c336..4abfcec 100644
--- a/gold/powerpc.cc
+++ b/gold/powerpc.cc
@@ -1986,6 +1986,12 @@ Powerpc_relobj<size, big_endian>::make_toc_relative(
if (size != 64)
return false;
+ // With -mcmodel=medium code it is quite possible to have
+ // toc-relative relocs referring to objects outside the TOC.
+ // Don't try to look at a non-existent TOC.
+ if (this->toc_shndx() == 0)
+ return false;
+
// Convert VALUE back to an address by adding got_base (see below),
// then to an offset in the TOC by subtracting the TOC output
// section address and the TOC output offset. Since this TOC output