Mail Archives: cygwin/2006/11/13/20:22:40
------=_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 -