This is the mail archive of the cygwin mailing list for the Cygwin 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]

RE: cannot perform PE operations on non PE output file 'bootsect'.

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'.

"  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 @@
 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] $@"

Can't think of a witty .sigline today....

Attachment: Makefile.diff
Description: Binary data

Unsubscribe info:
Problem reports:

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