]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[build] Avoid use of "ld --oformat binary"
authorMichael Brown <mcb30@ipxe.org>
Tue, 2 Jan 2018 20:26:40 +0000 (21:26 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 2 Jan 2018 20:26:40 +0000 (21:26 +0100)
Using "ld --oformat binary" for mbr.bin and usbdisk.bin seems to cause
segmentation faults on some versions of binutils (observed on Fedora
27).  Work around this problem by using ld to create an intermediate
ELF object, followed by objcopy (via the existing %.tmp -> %.bin rule)
to create the final binary.

Note that we cannot simply use a single-stage "objcopy -O binary"
since this will not process the relocation records for x86_64: see
commit 1afcccd ("[build] Do not use "objcopy -O binary" for objects
with relocation records").

Reported-by: Brent S <bts@square-r00t.net>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/Makefile.pcbios
src/arch/x86/prefix/mbr.S

index df08e018205714e187f3a878a44711f8985977e7..c44eefc1fa1f91e46ca9f9a1ae7d9dad039098ff 100644 (file)
@@ -106,14 +106,14 @@ NON_AUTO_MEDIA    += fd0
        $(Q)sync
 
 # Special target for building Master Boot Record binary
-$(BIN)/mbr.bin : $(BIN)/mbr.o
+$(BIN)/mbr.tmp : $(BIN)/mbr.o
        $(QM)$(ECHO) "  [LD] $@"
-       $(Q)$(LD) $(LDFLAGS) -o $@ --oformat binary -e 0 $<
+       $(Q)$(LD) $(LDFLAGS) -o $@ -e mbr $<
 
 # rule to make a USB disk image
-$(BIN)/usbdisk.bin : $(BIN)/usbdisk.o
+$(BIN)/usbdisk.tmp : $(BIN)/usbdisk.o
        $(QM)$(ECHO) "  [LD] $@"
-       $(Q)$(LD) $(LDFLAGS) -o $@ --oformat binary -e 0 $<
+       $(Q)$(LD) $(LDFLAGS) -o $@ -e mbr $<
 
 NON_AUTO_MEDIA += usb
 %usb: $(BIN)/usbdisk.bin %hd
index a1e237de823dd64ec184a59d484b995270ec7a63..032c0e775f12021ad6772c2198084e6fa0cb53f7 100644 (file)
@@ -6,6 +6,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
        .code16
        .org 0
 
+       .globl mbr
 mbr:
        movw    $exec_sector, %bp
        jmp     find_active_partition