This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC][PATCH v2 0/4] readelf and libbfd: Add Extended Numbering Support for ELF corefiles


I committed this patch to add support for PN_XNUM to gold.  Gold never
reads the number of program segments, so this just adds support for
writing out the right value in the unlikely event that gold ever
generates an executable with more than 0xffff segments.

Ian


elfcpp/ChangeLog:

2010-01-19  Ian Lance Taylor  <iant@google.com>

	* elfcpp.h (PN_XNUM): Define.

gold/ChangeLog:

2010-01-19  Ian Lance Taylor  <iant@google.com>

	* output.cc (Output_section_headers::do_sized_write): Write large
	segment count to sh_info field.
	(Output_file_header::do_sized_write): For large segment count,
	write PN_XNUM to e_phnum field.


Index: elfcpp/elfcpp.h
===================================================================
RCS file: /cvs/src/src/elfcpp/elfcpp.h,v
retrieving revision 1.28
diff -p -u -r1.28 elfcpp.h
--- elfcpp/elfcpp.h	3 Nov 2009 15:12:03 -0000	1.28
+++ elfcpp/elfcpp.h	19 Jan 2010 17:53:28 -0000
@@ -302,6 +302,15 @@ enum EM
   // Old MN10200 objects used 0xdead (EM_MN10200 is correct).
 };
 
+// A special value found in the Ehdr e_phnum field.
+
+enum
+{
+  // Number of program segments stored in sh_info field of first
+  // section headre.
+  PN_XNUM = 0xffff
+};
+
 // Special section indices.
 
 enum
Index: gold/output.cc
===================================================================
RCS file: /cvs/src/src/gold/output.cc,v
retrieving revision 1.115
diff -p -u -r1.115 output.cc
--- gold/output.cc	15 Jan 2010 04:58:34 -0000	1.115
+++ gold/output.cc	19 Jan 2010 17:53:28 -0000
@@ -213,7 +213,9 @@ Output_section_headers::do_sized_write(O
     else
       oshdr.put_sh_link(shstrndx);
 
-    oshdr.put_sh_info(0);
+    size_t segment_count = this->segment_list_->size();
+    oshdr.put_sh_info(segment_count >= elfcpp::PN_XNUM ? segment_count : 0);
+
     oshdr.put_sh_addralign(0);
     oshdr.put_sh_entsize(0);
   }
@@ -470,8 +472,11 @@ Output_file_header::do_sized_write(Outpu
   else
     {
       oehdr.put_e_phentsize(elfcpp::Elf_sizes<size>::phdr_size);
-      oehdr.put_e_phnum(this->segment_header_->data_size()
-			/ elfcpp::Elf_sizes<size>::phdr_size);
+      size_t phnum = (this->segment_header_->data_size()
+		      / elfcpp::Elf_sizes<size>::phdr_size);
+      if (phnum > elfcpp::PN_XNUM)
+	phnum = elfcpp::PN_XNUM;
+      oehdr.put_e_phnum(phnum);
     }
 
   oehdr.put_e_shentsize(elfcpp::Elf_sizes<size>::shdr_size);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]