From e666304ec603bb3249f80bac97200f2b4520ab0f Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Fri, 3 Feb 2017 19:18:37 +1030 Subject: [PATCH] [GOLD] PowerPC64 TOC indirect to TOC relative segfault * powerpc.cc (Powerpc_relobj::make_toc_relative): Don't crash when no .toc section exists. --- gold/ChangeLog | 5 +++++ gold/powerpc.cc | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/gold/ChangeLog b/gold/ChangeLog index c50e1f89332..56fe9669dbf 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,8 @@ +2017-02-03 Alan Modra + + * powerpc.cc (Powerpc_relobj::make_toc_relative): Don't crash + when no .toc section exists. + 2017-01-31 Cary Coutant PR gold/21090 diff --git a/gold/powerpc.cc b/gold/powerpc.cc index a67c33618bd..4abfcec16d6 100644 --- a/gold/powerpc.cc +++ b/gold/powerpc.cc @@ -1986,6 +1986,12 @@ Powerpc_relobj::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