Bug 468017

Summary: output from objcopy is too large (2 GB)
Product: [Fedora] Fedora Reporter: Dan Horák <dan>
Component: binutilsAssignee: Nick Clifton <nickc>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: medium    
Version: rawhideCC: bhinson, jakub, jan.kratochvil, nickc
Target Milestone: ---   
Target Release: ---   
Hardware: s390x   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-10-29 12:02:58 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 467765    
Attachments:
Description Flags
using RHEL5 gcc + binutils
none
using Fedora 9 gcc + binutils
none
using Fedora 9 gcc + recent binutils built from upstream sources none

Description Dan Horák 2008-10-22 12:58:57 UTC
This two commands run on s390x build of Fedora 9
gcc -O2 -o fba0.exec -nostdlib -Wl,-Ttext,0 fba0.o
objcopy -O binary fba0.exec fba0.bin
will produce a 2 GB large file from fba0.o file.

Version-Release number of selected component (if applicable):
gcc (GCC) 4.3.0 20080428 (Red Hat 4.3.0-8)
package binutils-2.18.50.0.6-2.s390x
  GNU ld version 2.18.50.0.6-2 20080403
  GNU objcopy version 2.18.50.0.6-2 20080403

current upstream
  GNU ld (Linux/GNU Binutils) 2.19.50.0.1.20081007
  GNU objcopy (Linux/GNU Binutils) 2.19.50.0.1.20081007

using gcc/ld/objcopy from RHEL5 gives correct output
gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-14)
GNU ld version 2.17.50.0.6-5.el5 20061020
GNU objcopy 2.17.50.0.6-5.el5 20061020

It looks to me that something is wrong with the fba0.exec file produced on Fedora, because when I take objcopy from RHEL5, it creates the same 2 GB large file.

Steps to Reproduce:
0. gcc  -Wall -O3 -DS390_TOOLS_RELEASE=1.7.0 -I../include -D__ASSEMBLY__ -DVERSION=1 -DRELEASE=7 -DPATCHLEVEL=0 -c -o fba0.o fba0.S
1. gcc -O2 -o fba0.exec -nostdlib -Wl,-Ttext,0 fba0.o
2. objcopy -O binary fba0.exec fba0.bin

Fedora for s390x lives at https://s390.koji.fedoraproject.org/koji/index

Comment 1 Dan Horák 2008-10-22 13:00:23 UTC
Created attachment 321142 [details]
using RHEL5 gcc + binutils

Comment 2 Dan Horák 2008-10-22 13:01:16 UTC
Created attachment 321143 [details]
using Fedora 9 gcc + binutils

Comment 3 Dan Horák 2008-10-22 13:02:18 UTC
Created attachment 321144 [details]
using Fedora 9 gcc + recent binutils built from upstream sources

Comment 4 Nick Clifton 2008-10-28 11:56:28 UTC
Hi Dan,

  This is happening because of a "feature" in the linker.  An extra section is being added to the executable file, and the presence of this section (starting at address 0x800000e8) is causing the conversion to the binary format to grow to the 2Gb size you noted.  Run "objdump -h fba0.exec" to see this section:

  fba0.exec:     file format elf64-s390

  Sections:
  Idx Name          Size      VMA               LMA               File off  Algn
    0 .text         000000e8  0000000000000000  0000000000000000  00001000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
    1 .note.gnu.build-id 00000024  00000000800000e8  00000000800000e8  000010e8  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA

The presence of this section is not the linker's fault though.  It is being requested by gcc.  If you add the "-v" option to the command line in step 1 of your "Steps to Reproduce" you will see lots of output including an invocation of the collect2 program (a wrapper around the linker) in which the "--build-id" option is present.  It is this option which is responsible for the creation of the .note.gnu.build-id section.

To prevent this section from being created, and so restore normal sized binaries, add --build-id=none to the linker command line.  Ie step 1 should read:

  1. gcc -O2 -o fba0.exec -nostdlib -Wl,-Ttext,0 fba0.o -Wl,--build-id=none

I hope that this helps.

Cheers
  Nick Clifton

Comment 5 Dan Horák 2008-10-29 07:12:11 UTC
Thanks for the explanation, Nick.

I have just found another method - process only the .text section with objcopy
objcopy -O binary -j .text fba0.exec fba0.bin