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]

PATCH: PR ld/4909: request for more helpful "can't allocate in segment" error message


When a section can't be allocated in segment, linker issues an error
message. But it doesn't provide enough information to tell what is
going on.  This patch prints out the segment map to help diagnose
the problem. Now I got

[hjl@gnu-14 linux]$ ./ld `cat run`  
./ld: .tmp_vmlinux1: section `.text' can't be allocated in segment 0
LOAD: .note.gnu.build-id .text .text.head __ex_table __mca_table
.data.patch.phys_stack_reg .IA_64.unwind_info .IA_64.unwind .rodata
.pci_fixup __ksymtab __ksymtab_gpl __ksymtab_gpl_future __kcrctab
__kcrctab_gpl __kcrctab_gpl_future __ksymtab_strings __param .opd
.init.text .init.data .init.ramfs .init.setup .initcall.init
.data.patch.vtop .data.patch.mckinley_e9 .machvec .con_initcall.init
.security_initcall.init .data.init_task .data.page_aligned
.data.read_mostly .data.cacheline_aligned 
./ld: final link failed: Bad value
[hjl@gnu-14 linux]$ 

We can tell there is an extra .note.gnu.build-id section instead of

[hjl@gnu-14 linux]$ ld `cat run`  
ld: .tmp_vmlinux1: section `.text' can't be allocated in segment 0
ld: final link failed: Bad value
[hjl@gnu-14 linux]$ 


H.J.
---
2007-08-09  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/4909
	* elf.c (print_segment_map): New function.
	(assign_file_positions_for_load_sections): Call print_segment_map
	when a section can't be allocated in segment.

--- bfd/elf.c.print	2007-08-09 06:56:01.000000000 -0700
+++ bfd/elf.c	2007-08-09 12:04:43.000000000 -0700
@@ -4073,6 +4073,32 @@ vma_page_aligned_bias (bfd_vma vma, ufil
   return ((vma - off) % maxpagesize);
 }
 
+static void
+print_segment_map (struct elf_segment_map *m)
+{
+  unsigned int j;
+  const char *pt = get_segment_type (m->p_type);
+  char buf[32];
+
+  if (pt == NULL)
+    {
+      if (m->p_type >= PT_LOPROC && m->p_type <= PT_HIPROC)
+	sprintf (buf, "LOPROC+%7.7x",
+		 (unsigned int) (m->p_type - PT_LOPROC));
+      else if (m->p_type >= PT_LOOS && m->p_type <= PT_HIOS)
+	sprintf (buf, "LOOS+%7.7x",
+		 (unsigned int) (m->p_type - PT_LOOS));
+      else
+	snprintf (buf, sizeof (buf), "%8.8x",
+		  (unsigned int) m->p_type);
+      pt = buf;
+    }
+  fprintf (stderr, "%s: ", pt);
+  for (j = 0; j < m->count; j++)
+    fprintf (stderr, "%s ", m->sections [j]->name);
+  putc ('\n',stderr);
+}
+
 /* Assign file positions to the sections based on the mapping from
    sections to segments.  This function also sets up some fields in
    the file header.  */
@@ -4460,6 +4486,7 @@ assign_file_positions_for_load_sections 
 		(*_bfd_error_handler)
 		  (_("%B: section `%A' can't be allocated in segment %d"),
 		   abfd, sec, j);
+		print_segment_map (m);
 		bfd_set_error (bfd_error_bad_value);
 		return FALSE;
 	      }


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