Bug 11953 - objcopy is broken
Summary: objcopy is broken
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.21
: P2 normal
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
: 11954 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-08-28 00:59 UTC by H.J. Lu
Modified: 2010-08-30 06:07 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2010-08-28 11:01:15


Attachments
A testcase (771.41 KB, application/octet-stream)
2010-08-28 01:01 UTC, H.J. Lu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2010-08-28 00:59:42 UTC
On Linux/x86, I got

./objcopy  DivasP.orig DivasP
BFD: DivasP: section .note.ABI-tag lma 0x8049094 adjusted to 0x804a094
BFD: DivasP: section .init lma 0x80490b4 adjusted to 0x804a0b4
BFD: DivasP: section .text lma 0x80490f0 adjusted to 0x804a0e5
BFD: DivasP: section .fini lma 0x81a8c9c adjusted to 0x81a9c91
BFD: DivasP: section .rodata lma 0x81a8cc0 adjusted to 0x81a9cad
BFD: DivasP: section __libc_subinit lma 0x81f0f6c adjusted to 0x81f1f57
BFD: DivasP: section __libc_subfreeres lma 0x81f0f78 adjusted to 0x81f1f63
BFD: DivasP: section __libc_atexit lma 0x81f0f98 adjusted to 0x81f1f83
BFD: DivasP: section `__libc_subfreeres' can't be allocated in segment 0
LOAD: .note.ABI-tag .init .text .fini .rodata __libc_subinit __libc_subfreeres
__libc_atexit
BFD: DivasP: section `__libc_atexit' can't be allocated in segment 0
LOAD: .note.ABI-tag .init .text .fini .rodata __libc_subinit __libc_subfreeres
__libc_atexit
Comment 1 H.J. Lu 2010-08-28 01:01:06 UTC
Created attachment 4954 [details]
A testcase

This is caused by

http://sourceware.org/ml/binutils/2010-04/msg00305.html
Comment 2 Jeff Chua 2010-08-28 01:08:59 UTC
*** Bug 11954 has been marked as a duplicate of this bug. ***
Comment 3 Alan Modra 2010-08-28 10:47:32 UTC
What toolchain produced DivaP?  I'm asking because the headers are not
consistent.  If you look at section header offsets and program header offsets,
you'll see that .note.ABI-tag is part of the first PT_LOAD header.  The header
p_paddr and p_offset along with the section sh_offset gives .note.ABI-tag a
section lma of 0x8049094.  However, the PT_NOTE header also contains
.note.ABI-tag, but the PT_NOTE p_paddr says the section lma should be 0x8048094.
Comment 4 Jeff Chua 2010-08-28 11:41:15 UTC
(In reply to comment #3)
> What toolchain produced DivaP?  I'm asking because the headers are not
> consistent.

I don't know. This binary comes from the vendor. There could be other binaries
that has this problem, so this is one example where I don't have the source code
to recompile. But why does strip from binutils-2.20.51.0.8 works?

Thanks,
Jeff


Comment 5 H.J. Lu 2010-08-28 13:32:49 UTC
(In reply to comment #3)
> What toolchain produced DivaP?  I'm asking because the headers are not
> consistent.  If you look at section header offsets and program header offsets,
> you'll see that .note.ABI-tag is part of the first PT_LOAD header.  The header
> p_paddr and p_offset along with the section sh_offset gives .note.ABI-tag a
> section lma of 0x8049094.  However, the PT_NOTE header also contains
> .note.ABI-tag, but the PT_NOTE p_paddr says the section lma should be 0x8048094.
> 

I got

There are 19 section headers, starting at offset 0x1afa6c:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .init             PROGBITS        080480b4 0010b4 000031 00  AX  0   0  4
  [ 2] .text             PROGBITS        080480f0 0010f0 15fbac 00  AX  0   0 16
  [ 3] .fini             PROGBITS        081a7c9c 160c9c 00001c 00  AX  0   0  4
  [ 4] .rodata           PROGBITS        081a7cc0 160cc0 0482aa 00   A  0   0 32
  [ 5] __libc_subinit    PROGBITS        081eff6c 1a8f6c 00000c 00   A  0   0  4
  [ 6] __libc_subfreeres PROGBITS        081eff78 1a8f78 000020 00   A  0   0  4
  [ 7] __libc_atexit     PROGBITS        081eff98 1a8f98 000004 00   A  0   0  4
  [ 8] .data             PROGBITS        081f0fa0 1a8fa0 0025b0 00  WA  0   0 32
  [ 9] .eh_frame         PROGBITS        081f3550 1ab550 000220 00  WA  0   0  4
  [10] .ctors            PROGBITS        081f3770 1ab770 000008 00  WA  0   0  4
  [11] .dtors            PROGBITS        081f3778 1ab778 000008 00  WA  0   0  4
  [12] .got              PROGBITS        081f3780 1ab780 000010 04  WA  0   0  4
  [13] .bss              NOBITS          081f37a0 1ab790 01c288 00  WA  0   0 32
  [14] .comment          PROGBITS        00000000 1ab790 002b32 00      0   0  1
  [15] .note.ABI-tag     NOTE            08048094 001094 000020 00   A  0   0  4
  [16] .note             NOTE            0820fa28 1ae2c2 0016bc 00      0   0  1
  [17] .gnu.warning.llse PROGBITS        0820fa40 1af980 00003f 00      0   0 32
  [18] .shstrtab         STRTAB          00000000 1af9bf 0000ad 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

Elf file type is EXEC (Executable file)
Entry point 0x80480f0
There are 3 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000000 0x08047000 0x08048000 0x1a8f9c 0x1a8f9c R E 0x1000
  LOAD           0x1a8fa0 0x081f0fa0 0x081f0fa0 0x027f0 0x1ea88 RW  0x1000
  NOTE           0x001094 0x08048094 0x08048094 0x00020 0x00020 R   0x4

 Section to Segment mapping:
  Segment Sections...
   00     .init .text .fini .rodata __libc_subinit __libc_subfreeres
__libc_atexit .note.ABI-tag 
   01     .data .eh_frame .ctors .dtors .got .bss 
   02     .note.ABI-tag 

There are

  [15] .note.ABI-tag     NOTE            08048094 001094 000020 00   A  0   0  4

and

  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000000 0x08047000 0x08048000 0x1a8f9c 0x1a8f9c R E 0x1000
  LOAD           0x1a8fa0 0x081f0fa0 0x081f0fa0 0x027f0 0x1ea88 RW  0x1000
  NOTE           0x001094 0x08048094 0x08048094 0x00020 0x00020 R   0x4

LMA is the BFD thing. The only problem is VirtAddr != PhysAddr. But
ELF spec says

--
p_paddr
    On systems for which physical addressing is relevant, this member
is reserved for the segment's physical address. Because System V ignores
physical addressing for application programs, this member has unspecified
contents for executable files and shared objects.
---

We can ignore it.
Comment 6 H.J. Lu 2010-08-28 13:36:21 UTC
We can use LVM as long as we don't derive it from p_paddr
when there is a conflict since this field has unspecified
contents. 
Comment 7 Alan Modra 2010-08-28 13:43:44 UTC
(In reply to comment #4)
Can you at least tell me the vendor?

Why does strip from binutils-2.20.51.0.8 work?  Because it has a different set
of bugs to the latest binutils.  Sometimes a fix for one bug is wrong,
introducing a new bug.  Sometimes a fix isn't wrong itself but exposes another
bug, which is what happened in this case.

Patch at
http://sourceware.org/ml/binutils/2010-08/msg00360.html
Comment 8 Jeff Chua 2010-08-28 16:13:39 UTC
(In reply to comment #7)
> (In reply to comment #4)
> Can you at least tell me the vendor?

Dialogic.


> Patch at
> http://sourceware.org/ml/binutils/2010-08/msg00360.html

Applied the patch. Strip now works!

HJ, Alan ... thank you so much!!!

Jeff
Comment 9 Sourceware Commits 2010-08-30 06:01:48 UTC
Subject: Bug 11953

CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2010-08-30 06:01:23

Modified files:
	bfd            : ChangeLog elf.c 

Log message:
	PR binutils/11953
	* elf.c (copy_elf_program_header): Calculate map->header_size
	from lowest_section, not first_section.  Validate program
	header p_paddr against section lma.  Find lowest_section in
	second loop over headers.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5120&r2=1.5121
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf.c.diff?cvsroot=src&r1=1.517&r2=1.518

Comment 10 Alan Modra 2010-08-30 06:07:41 UTC
Fixed.