delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/11/13/20:22:40

X-Spam-Check-By: sourceware.org
From: "Dave Korn" <dave DOT korn AT artimi DOT com>
To: "'Salvatore D'Angelo'" <koala DOT gnu AT tiscali DOT it>, <cygwin AT cygwin DOT com>
Subject: RE: cannot perform PE operations on non PE output file 'bootsect'.
Date: Tue, 14 Nov 2006 01:22:09 -0000
Message-ID: <011101c7078b$4e305f30$a501a8c0@CAM.ARTIMI.COM>
MIME-Version: 1.0
X-Mailer: Microsoft Office Outlook 11
In-Reply-To: <45590DE6.4040106@tiscali.it>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

------=_NextPart_000_0112_01C7078B.4E305F30
Content-Type: text/plain;
	charset="iso-8859-15"
Content-Transfer-Encoding: 7bit

On 14 November 2006 00:29, Salvatore D'Angelo wrote:

> Hi all,
> 
> I have a problem compiling the bootsect.S file above using the Makefile.
> Basically the project create a boot sector on floppy that print "Hello
> World" at compuer boot.
> On Linux it works fine but in cygwin I go the following link problem:
> 
> *ld: cannot perform PE operations on non PE output file 'bootsect'.

http://sourceware.org/bugzilla/show_bug.cgi?id=2757

"  This is a known problem with the linker.  It cannot link PE files and
convert to BINARY format at the same time.  You will need to link to a PE
format file first and then use OBJCOPY to convert it to BINARY format
afterwards.  "

  You don't get this on Linux, because Linux uses ELF format object files, not
PE, which apparently ld handles fine.  The solution is as described: link it
first, then use objcopy to extract the text section and convert to binary
format.  So, you need a link command like:

ld -r -Ttext 0x0 -e _start -s -o bootsect.out bootsect.o

(we use a relocatable '-r' link because a final link would add the
__CTOR_LIST__ and __DTOR_LIST__ data in the text section; a relocatable link
will resolve any stray relocs for us without adding those tables), followed by
an objcopy like so:

objcopy -O binary -j .text bootsect.out bootsect

Try the following patch to your makefile: it adds an intermediate linked stage
called bootsect.out and then extracts the raw binary boot sector from that.

--- Makefile.orig	2006-11-14 01:19:30.214928700 +0000
+++ Makefile	2006-11-14 01:19:56.636803700 +0000
@@ -1,11 +1,15 @@
 AS=as
 LD=ld
+OBJCOPY=objcopy
 
 all: bootsect
 
-bootsect: bootsect.o
+bootsect: bootsect.out
+	@$(OBJCOPY) -O binary -j .text $< $@
+
+bootsect.out: bootsect.o
 	@echo "[LD] $@"
-	@$(LD) -Ttext 0x0 -s --oformat binary -o $@ $<
+	@$(LD) -Ttext 0x0 -e _start -s -o $@ $<
 
 bootsect.o: bootsect.S
 	@echo "[AS] $@"



    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

------=_NextPart_000_0112_01C7078B.4E305F30
Content-Type: application/octet-stream;
	name="Makefile.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="Makefile.diff"

--- Makefile.orig	2006-11-14 01:19:30.214928700 +0000
+++ Makefile	2006-11-14 01:19:56.636803700 +0000
@@ -1,11 +1,15 @@
 AS=3Das
 LD=3Dld
+OBJCOPY=3Dobjcopy
=20
 all: bootsect
=20
-bootsect: bootsect.o
+bootsect: bootsect.out
+	@$(OBJCOPY) -O binary -j .text $< $@
+
+bootsect.out: bootsect.o
 	@echo "[LD] $@"
-	@$(LD) -Ttext 0x0 -s --oformat binary -o $@ $<
+	@$(LD) -Ttext 0x0 -e _start -s -o $@ $<
=20
 bootsect.o: bootsect.S
 	@echo "[AS] $@"


------=_NextPart_000_0112_01C7078B.4E305F30
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
------=_NextPart_000_0112_01C7078B.4E305F30--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019