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] Fix objcopy of a separate debug info


Hi,

$ echo 'main(){}' >debug.c
$ gcc -o debug debug.c
$ strip --only-keep-debug debug
$ objcopy debug /dev/null
BFD: /dev/null: section .note.ABI-tag lma 0x400200 overlaps previous sections
BFD: /dev/null: section .note.gnu.build-id lma 0x400220 overlaps previous sections

(Fedora 9)
gcc-4.3.0-8.x86_64
binutils-2.18.50.0.6-2.x86_64 or binutils CVS HEAD

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .interp           NOBITS           0000000000400200  00000200
       000000000000001c  0000000000000000   A       0     0     1
  [ 2] .note.ABI-tag     NOTE             000000000040021c  00000200
       0000000000000020  0000000000000000   A       0     0     4
  [ 3] .note.gnu.build-i NOTE             000000000040023c  00000220
       0000000000000024  0000000000000000   A       0     0     4

It also causes the same problem for a GDB testcase, the fix difference:
 Running ../.././gdb/testsuite/gdb.base/sepsymtab.exp ...
-UNSUPPORTED: gdb.base/sepsymtab.exp: cannot produce separate debug info files
+PASS: gdb.base/sepsymtab.exp: info sym main

After the attached fix I found no regressions on binutils and gdb testsuites
and it builds glibc and kernel the same/working.

There is no comment as I think it is really right to shift rather the memory
address part (vma/p_vaddr/p_memsz) than the file part (lma/p_paddr/p_filesz)
which may be smaller (bss) and not satisfy the p_memsz requirements.
off+p_filesz could be probably shifted less according to lma (not vma) as long
as the p_memsz and p_filesz shift would be kept congruent the segment
alignment.  OTOH it faces a problem the segment alignment is already being
violated in the separate debug info files (and they should have it probably
cleared) but it does not hurt anyone as no one needs to memory-map the separate
debug info file.  IMO there would be better adjust_vma and adjust_lma
separately but it is currently not done so.



Regards,
Jan
2008-05-28  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* elf.c (assign_file_positions_for_load_sections): Adjust pre-section
	gaps based on VMA and P_VADDR instead of LMA and P_PADDR addresses.
	Remove the sections overlap check.

2008-05-28  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* binutils-all/objcopy.exp: Call KEEP_DEBUG_SYMBOLS_AND_TEST_COPY.
	(keep_debug_symbols_and_test_copy): New function.
	(test5, test6): New variables.

--- bfd/elf.c	24 May 2008 16:14:59 -0000	1.446
+++ bfd/elf.c	27 May 2008 23:36:19 -0000
@@ -4371,12 +4371,12 @@ assign_file_positions_for_load_sections 
 		      && ((this_hdr->sh_flags & SHF_TLS) == 0
 			  || p->p_type == PT_TLS))))
 	    {
-	      bfd_signed_vma adjust = sec->lma - (p->p_paddr + p->p_memsz);
+	      bfd_signed_vma adjust = sec->vma - (p->p_vaddr + p->p_memsz);
 
 	      if (adjust < 0)
 		{
 		  (*_bfd_error_handler)
-		    (_("%B: section %A lma 0x%lx overlaps previous sections"),
+		    (_("%B: section %A vma 0x%lx overlaps previous sections"),
 		     abfd, sec, (unsigned long) sec->lma);
 		  adjust = 0;
 		}
--- binutils/testsuite/binutils-all/objcopy.exp	28 Aug 2007 13:21:53 -0000	1.48
+++ binutils/testsuite/binutils-all/objcopy.exp	27 May 2008 23:36:20 -0000
@@ -681,10 +681,40 @@ proc strip_executable_with_saving_a_symb
     pass $test
 }
 
+# Test keeping only debug symbols of an executable
+
+proc keep_debug_symbols_and_test_copy { prog1 flags1 test1 prog2 flags2 test2 } {
+    global NM
+    global NMFLAGS
+
+    remote_download build tmpdir/copyprog tmpdir/striprog
+    if [is_remote host] {
+	set copyfile [remote_download host tmpdir/striprog]
+    } else {
+	set copyfile tmpdir/striprog
+    }
+
+    set exec_output [binutils_run $prog1 "$flags1 ${copyfile}"]
+    if ![string match "" $exec_output] {
+	fail $test1
+	return
+    }
+    pass $test1
+
+    set exec_output [binutils_run $prog2 "$flags2 ${copyfile}"]
+    if ![string match "" $exec_output] {
+	fail $test2
+	return
+    }
+    pass $test2
+}
+
 set test1 "simple objcopy of executable"
 set test2 "run objcopy of executable"
 set test3 "run stripped executable"
 set test4 "run stripped executable with saving a symbol"
+set test5 "keep only debug data"
+set test6 "simple objcopy of debug data"
 
 switch [copy_setup] {
     "1" {
@@ -695,17 +725,23 @@ switch [copy_setup] {
 	untested $test2
 	untested $test3
 	untested $test4
+	untested $test5
+	untested $test6
     }
     "3" {
 	copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" ""
 	unsupported $test2
 	unsupported $test3
 	unsupported $test4
+	unsupported $test5
+	unsupported $test6
     }
     "0" {
 	copy_executable "$OBJCOPY" "$OBJCOPYFLAGS" "$test1" "$test2"
 	strip_executable "$STRIP" "$STRIPFLAGS" "$test3"
 	strip_executable_with_saving_a_symbol "$STRIP" "-K main -K _main $STRIPFLAGS" "$test4"
+	keep_debug_symbols_and_test_copy "$STRIP" "--only-keep-debug $STRIPFLAGS" "$test5" \
+					 "$OBJCOPY" "$OBJCOPYFLAGS" "$test6"
     }
 }
 

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