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]

objcopy non-ELF to ELF executable


My http://sourceware.org/ml/binutils/2006-06/msg00293.html change
better supported SIZEOF_HEADERS but broke objcopy of non-ELF
executables to ELF format in so far as objcopy no longer created ELF
program headers.  Probably not that serious a bug since such
executables are unlikely to run even if they do have ELF program
headers.  However, it does cause objcopy to emit annoying warnings,
and an ELF executable without program headers can't have section LMAs
different from VMAs.

This patch cures this problem, and fixes a test that expected wrong
LMAs.  I haven't yet run regression tests on a full set of targets, so
won't apply this to the branch immediately.

bfd/
	PR 6789
	* elf.c (assign_file_positions_for_load_sections): Call
	_bfd_elf_map_sections_to_segments, not elf_modify_segment_map.
	(get_program_header_size): Protect against NULL info.
	(_bfd_elf_map_sections_to_segments): Likewise.
	* elf32-spu.c (spu_elf_additional_program_headers): Likewise.
ld/testsuite/
	* ld-elf/extract-symbol-1sec.d: Correct section lma.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.463
diff -u -p -r1.463 elf.c
--- bfd/elf.c	28 Sep 2008 13:30:35 -0000	1.463
+++ bfd/elf.c	29 Sep 2008 13:44:23 -0000
@@ -3380,7 +3380,7 @@ get_program_header_size (bfd *abfd, stru
       ++segs;
     }
 
-  if (info->relro)
+  if (info != NULL && info->relro)
     {
       /* We need a PT_GNU_RELRO segment.  */
       ++segs;
@@ -3762,8 +3762,13 @@ _bfd_elf_map_sections_to_segments (bfd *
 	    }
 
 	  /* Allow interested parties a chance to override our decision.  */
-	  if (last_hdr && info->callbacks->override_segment_assignment)
-	    new_segment = info->callbacks->override_segment_assignment (info, abfd, hdr, last_hdr, new_segment);
+	  if (last_hdr != NULL
+	      && info != NULL
+	      && info->callbacks->override_segment_assignment != NULL)
+	    new_segment
+	      = info->callbacks->override_segment_assignment (info, abfd, hdr,
+							      last_hdr,
+							      new_segment);
 
 	  if (! new_segment)
 	    {
@@ -3938,7 +3943,7 @@ _bfd_elf_map_sections_to_segments (bfd *
 	  pm = &m->next;
 	}
 
-      if (info->relro)
+      if (info != NULL && info->relro)
 	{
 	  for (m = mfirst; m != NULL; m = m->next)
 	    {
@@ -4122,7 +4127,7 @@ assign_file_positions_for_load_sections 
   unsigned int i, j;
 
   if (link_info == NULL
-      && !elf_modify_segment_map (abfd, link_info, FALSE))
+      && !_bfd_elf_map_sections_to_segments (abfd, link_info))
     return FALSE;
 
   alloc = 0;
Index: bfd/elf32-spu.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-spu.c,v
retrieving revision 1.51
diff -u -p -r1.51 elf32-spu.c
--- bfd/elf32-spu.c	4 Aug 2008 13:01:42 -0000	1.51
+++ bfd/elf32-spu.c	29 Sep 2008 13:44:30 -0000
@@ -4245,10 +4245,15 @@ spu_elf_post_process_headers (bfd *abfd,
 static int
 spu_elf_additional_program_headers (bfd *abfd, struct bfd_link_info *info)
 {
-  struct spu_link_hash_table *htab = spu_hash_table (info);
-  int extra = htab->num_overlays;
+  int extra = 0;
   asection *sec;
 
+  if (info != NULL)
+    {
+      struct spu_link_hash_table *htab = spu_hash_table (info);
+      extra = htab->num_overlays;
+    }
+
   if (extra)
     ++extra;
 
Index: ld/testsuite/ld-elf/extract-symbol-1sec.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/extract-symbol-1sec.d,v
retrieving revision 1.3
diff -u -p -r1.3 extract-symbol-1sec.d
--- ld/testsuite/ld-elf/extract-symbol-1sec.d	6 Aug 2008 00:42:17 -0000	1.3
+++ ld/testsuite/ld-elf/extract-symbol-1sec.d	29 Sep 2008 12:48:37 -0000
@@ -7,7 +7,7 @@
 #...
 Sections:
  *Idx +Name +Size +VMA +LMA .*
- *0 +\.foo +0+ +0+10000 +0+10000 .*
+ *0 +\.foo +0+ +0+10000 +0+ .*
  *CONTENTS, ALLOC, LOAD, CODE
- *1 +\.bar +0+ +0+20000 +0+20000 .*
+ *1 +\.bar +0+ +0+20000 +0+10000 .*
  *ALLOC, READONLY, CODE

-- 
Alan Modra
Australia Development Lab, IBM


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