Bug 5233 - objcopy won't change section flags on zero file-size sections
Summary: objcopy won't change section flags on zero file-size sections
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.17
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-30 15:11 UTC by Andrew Stubbs
Modified: 2007-11-13 05:58 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Stubbs 2007-10-30 15:11:28 UTC
I have an elf file with a section that has an allocated length, but no content
in the file. In binutils 2.16.91.0.5 I used to be able to give it some contents
(of whatever is the default value) by changing the flags, but in 2.17.50.0.17 I
can no longer do so.

My target is SH, but I have no reason to think this is SH specific.


How to reproduce:

1. Create an example binary:

FILE: test.c
int main()
{
}
END-FILE

FILE: link.ld
SECTIONS
{
  .text           :
  {
    *(.text .stub .text.* .gnu.linkonce.t.*)
  } =0
  .post_text_reserve :
  {
    /* Reserve some space so we can drop something in here later */
    . += 0x160;
  }
}
END-FILE

  $ gcc test.c -T link.ld -nostdlib

This should create a binary with the following properties:

  $ objdump -ph a.out

a.out:     file format elf32-shl

Program Header:
    LOAD off    0x00000080 vaddr 0x00000000 paddr 0x00000000 align 2**7
         filesz 0x0000000c memsz 0x0000016c flags rwx

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         0000000c  00000000  00000000  00000080  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .post_text_reserve 00000160  0000000c  0000000c  0000008c  2**0
                  ALLOC
  2 .comment      00000043  00000000  00000000  0000008c  2**0
                  CONTENTS, READONLY



2. Run objcopy:

  $ objcopy a.out a2.out --set-section-flags
.post_text_reserve=contents,alloc,load,readonly,code
BFD: a2.out: section `.text' can't be allocated in segment 0
....../bin/sh4objcopy: a2.out: Bad value
BFD: a2.out: section `.text' can't be allocated in segment 0
....../bin/sh4objcopy: a2.out: Bad value
Comment 1 Andrew Stubbs 2007-10-30 15:14:18 UTC
For more detail, see here: http://sourceware.org/ml/binutils/2007-10/msg00382.html
Comment 2 H.J. Lu 2007-10-30 18:54:21 UTC
The bug was introduced by this patch

http://sourceware.org/ml/binutils/2006-12/msg00165.html

The linker check is correct. Otherwise, you will get a bogus binary

Elf file type is EXEC (Executable file)
Entry point 0x0
There are 1 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000200000 0xfffffffffffffffe 0x0000000000000000
                 0x0000000000000162 0x0000000000000162  RWE    200000

 Section to Segment mapping:
  Segment Sections...
   00     
Comment 3 H.J. Lu 2007-11-04 16:02:52 UTC
The Linux binutils 2.18.50.0.3 is released with this patch

http://sourceware.org/ml/binutils/2007-11/msg00003.html