public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [GOLD][PATCH] Do not scan merged sections for stubs.
@ 2010-02-06  1:17 Doug Kwan (關振德)
  2010-02-06  1:58 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Doug Kwan (關振德) @ 2010-02-06  1:17 UTC (permalink / raw)
  To: Ian Lance Taylor, binutils

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

Hi,

    This patch fixes a problem that caused the crash in PR 11247.   I
also moved the code a bit so that the logic to determine what sections
to scan for stubs is shared by
Arm_relobj::section_needs_reloc_stub_scanning and
Arm_relobj::section_needs_cortex_a8_stub_scanning.

-Doug

2010-02-05  Doug Kwan  <dougkwan@google.com>

	PR 11247
	* arm.cc (Arm_relobj::section_is_scannable): New method.
	(Arm_relobj::section_needs_reloc_stub_scanning): Use it.
	(Arm_relobj::section_needs_cortex_a8_stub_scanning): Same.

[-- Attachment #2: patch-scannable.txt --]
[-- Type: text/plain, Size: 4750 bytes --]

Index: gold/arm.cc
===================================================================
RCS file: /cvs/src/src/gold/arm.cc,v
retrieving revision 1.76
diff -u -u -p -r1.76 arm.cc
--- gold/arm.cc	4 Feb 2010 03:32:18 -0000	1.76
+++ gold/arm.cc	6 Feb 2010 00:52:43 -0000
@@ -1580,6 +1580,11 @@ class Arm_relobj : public Sized_relobj<3
 				    const Relobj::Output_sections&,
 				    const Symbol_table *, const unsigned char*);
 
+  // Whether a section is a scannable text section.
+  bool
+  section_is_scannable(const elfcpp::Shdr<32, big_endian>&, unsigned int,
+		       const Output_section*, const Symbol_table *);
+
   // Whether a section needs to be scanned for the Cortex-A8 erratum.
   bool
   section_needs_cortex_a8_stub_scanning(const elfcpp::Shdr<32, big_endian>&,
@@ -5447,6 +5452,44 @@ Arm_output_section<big_endian>::fix_exid
 
 // Arm_relobj methods.
 
+// Determine if an input section is scannable for stub processing.  SHDR is
+// the header of the section and SHNDX is the section index.  OS is the output
+// section for the input section and SYMTAB is the global symbol table used to
+// look up ICF information.
+
+template<bool big_endian>
+bool
+Arm_relobj<big_endian>::section_is_scannable(
+    const elfcpp::Shdr<32, big_endian>& shdr,
+    unsigned int shndx,
+    const Output_section* os,
+    const Symbol_table *symtab)
+{
+  // Skip any empty sections, unallocated sections or sections whose
+  // type are not SHT_PROGBITS.
+  if (shdr.get_sh_size() == 0
+      || (shdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0
+      || shdr.get_sh_type() != elfcpp::SHT_PROGBITS)
+    return false;
+
+  // Skip any discarded or ICF'ed sections.
+  if (os == NULL || symtab->is_section_folded(this, shndx))
+    return false;
+
+  // If this requires special offset handling, check to see if it is
+  // a relaxed section.  If this is not, then it is a merged section that
+  // we cannot handle.
+  if (this->output_section_offset(shndx) == static_cast<uint64_t>(-1))
+    {
+      const Output_relaxed_input_section* poris =
+	os->find_relaxed_input_section(this, shndx);
+      if (poris == NULL)
+	return false;
+    }
+
+  return true;
+}
+
 // Determine if we want to scan the SHNDX-th section for relocation stubs.
 // This is a helper for Arm_relobj::scan_sections_for_stubs() below.
 
@@ -5467,26 +5510,6 @@ Arm_relobj<big_endian>::section_needs_re
   if (sh_size == 0)
     return false;
 
-  // Ignore reloc section with bad info.  This error will be
-  // reported in the final link.
-  unsigned int index = this->adjust_shndx(shdr.get_sh_info());
-  if (index >= this->shnum())
-    return false;
-
-  // This relocation section is against a section which we
-  // discarded or if the section is folded into another
-  // section due to ICF.
-  if (out_sections[index] == NULL || symtab->is_section_folded(this, index))
-    return false;
-
-  // Check the section to which relocations are applied.  Ignore relocations
-  // to unallocated sections or EXIDX sections.
-  const unsigned int shdr_size = elfcpp::Elf_sizes<32>::shdr_size;
-  const elfcpp::Shdr<32, big_endian> data_shdr(pshdrs + index * shdr_size);
-  if ((data_shdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0
-      || data_shdr.get_sh_type() == elfcpp::SHT_ARM_EXIDX)
-    return false;
-
   // Ignore reloc section with unexpected symbol table.  The
   // error will be reported in the final link.
   if (this->adjust_shndx(shdr.get_sh_link()) != this->symtab_shndx())
@@ -5503,7 +5526,16 @@ Arm_relobj<big_endian>::section_needs_re
   if (reloc_size != shdr.get_sh_entsize() || sh_size % reloc_size != 0)
     return false;
 
-  return true;
+  // Ignore reloc section with bad info.  This error will be
+  // reported in the final link.
+  unsigned int index = this->adjust_shndx(shdr.get_sh_info());
+  if (index >= this->shnum())
+    return false;
+
+  const unsigned int shdr_size = elfcpp::Elf_sizes<32>::shdr_size;
+  const elfcpp::Shdr<32, big_endian> text_shdr(pshdrs + index * shdr_size);
+  return this->section_is_scannable(text_shdr, index,
+				   out_sections[index], symtab);
 }
 
 // Determine if we want to scan the SHNDX-th section for non-relocation stubs.
@@ -5517,15 +5549,9 @@ Arm_relobj<big_endian>::section_needs_co
     Output_section* os,
     const Symbol_table* symtab)
 {
-  // We only scan non-empty code sections.
-  if ((shdr.get_sh_flags() & elfcpp::SHF_EXECINSTR) == 0
-      || shdr.get_sh_size() == 0)
+  if (!this->section_is_scannable(shdr, shndx, os, symtab))
     return false;
 
-  // Ignore discarded or ICF'ed sections.
-  if (os == NULL || symtab->is_section_folded(this, shndx))
-    return false;
-  
   // Find output address of section.
   Arm_address address = os->output_address(this, shndx, 0);
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [GOLD][PATCH] Do not scan merged sections for stubs.
  2010-02-06  1:17 [GOLD][PATCH] Do not scan merged sections for stubs Doug Kwan (關振德)
@ 2010-02-06  1:58 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2010-02-06  1:58 UTC (permalink / raw)
  To: Doug Kwan (關振德); +Cc: binutils

"Doug Kwan (關振德)" <dougkwan@google.com> writes:

> 2010-02-05  Doug Kwan  <dougkwan@google.com>
>
> 	PR 11247
> 	* arm.cc (Arm_relobj::section_is_scannable): New method.
> 	(Arm_relobj::section_needs_reloc_stub_scanning): Use it.
> 	(Arm_relobj::section_needs_cortex_a8_stub_scanning): Same.

> +  // If this requires special offset handling, check to see if it is
> +  // a relaxed section.  If this is not, then it is a merged section that
> +  // we cannot handle.
> +  if (this->output_section_offset(shndx) == static_cast<uint64_t>(-1))

Change this to this->is_output_section_offset_invalid(shndx).

This is OK with that change.

Thanks.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-02-06  1:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-06  1:17 [GOLD][PATCH] Do not scan merged sections for stubs Doug Kwan (關振德)
2010-02-06  1:58 ` 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).