public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* gold patch committed: Don't crash with -s -r
@ 2011-06-29 21:28 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2011-06-29 21:28 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 544 bytes --]

I haven't been able to recreate PR 12695.  However, while looking at it
I did see a possible linker crash with the somewhat unlikely combination
of -s -r.  This patch fixes the problem, by not trying to get the
section index of the .symtab section if there is no such section.
Committed to mainline.

Ian


2011-06-29  Ian Lance Taylor  <iant@google.com>

	PR gold/12695
	* layout.cc (Layout::symtab_section_shndx): New function.
	* layout.h (class Layout): Declare symtab_section_shndx.
	* output.cc (Output_section::write_header): Call it.



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2070 bytes --]

Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.207
diff -u -p -r1.207 layout.cc
--- layout.cc	29 Jun 2011 00:39:54 -0000	1.207
+++ layout.cc	29 Jun 2011 21:24:49 -0000
@@ -4536,6 +4536,17 @@ Layout::symtab_section_offset() const
   return 0;
 }
 
+// Return the section index of the normal symbol table.  It may have
+// been stripped by the -s/--strip-all option.
+
+unsigned int
+Layout::symtab_section_shndx() const
+{
+  if (this->symtab_section_ != NULL)
+    return this->symtab_section_->out_shndx();
+  return 0;
+}
+
 // Write out the Output_sections.  Most won't have anything to write,
 // since most of the data will come from input sections which are
 // handled elsewhere.  But some Output_sections do have Output_data.
Index: layout.h
===================================================================
RCS file: /cvs/src/src/gold/layout.h,v
retrieving revision 1.95
diff -u -p -r1.95 layout.h
--- layout.h	29 Jun 2011 00:39:54 -0000	1.95
+++ layout.h	29 Jun 2011 21:24:49 -0000
@@ -701,6 +701,10 @@ class Layout
   off_t
   symtab_section_offset() const;
 
+  // Return the section index of the normal symbol tabl.e
+  unsigned int
+  symtab_section_shndx() const;
+
   // Return the dynamic symbol table.
   Output_section*
   dynsym_section() const
Index: output.cc
===================================================================
RCS file: /cvs/src/src/gold/output.cc,v
retrieving revision 1.152
diff -u -p -r1.152 output.cc
--- output.cc	23 Jun 2011 00:46:13 -0000	1.152
+++ output.cc	29 Jun 2011 21:24:49 -0000
@@ -3390,7 +3390,7 @@ Output_section::write_header(const Layou
   if (this->link_section_ != NULL)
     oshdr->put_sh_link(this->link_section_->out_shndx());
   else if (this->should_link_to_symtab_)
-    oshdr->put_sh_link(layout->symtab_section()->out_shndx());
+    oshdr->put_sh_link(layout->symtab_section_shndx());
   else if (this->should_link_to_dynsym_)
     oshdr->put_sh_link(layout->dynsym_section()->out_shndx());
   else

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-06-29 21:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-29 21:28 gold patch committed: Don't crash with -s -r Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).