]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[build] Do not use "objcopy -O binary" for objects with relocation records
authorMichael Brown <mcb30@ipxe.org>
Mon, 21 Mar 2016 17:33:45 +0000 (17:33 +0000)
committerMichael Brown <mcb30@ipxe.org>
Mon, 21 Mar 2016 17:49:58 +0000 (17:49 +0000)
The mbr.bin and usbdisk.bin standalone blobs are currently generated
using "objcopy -O binary", which does not process relocation records.

For the i386 build, this does not matter since the section start
address is zero and so the ".rel" relocation records are effectively
no-ops anyway.

For the x86_64 build, the ".rela" relocation records are not no-ops,
since the addend is included as part of the relocation record (rather
than inline).  Using "objcopy -O binary" will silently discard the
relocation records, with the result that all symbols are effectively
given a value of zero.

Fix by using "ld --oformat binary" instead of "objcopy -O binary" to
generate mbr.bin and usbdisk.bin.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/Makefile.pcbios

index 18a6f7597477fb58666c329e25498514a0efe67f..f8c2253520deaf88a6ba42d049cb1a0719951c5e 100644 (file)
@@ -12,6 +12,10 @@ LDSCRIPT     = arch/x86/scripts/pcbios.lds
 #
 LDFLAGS                += -N --no-check-sections
 
+# Prefix always starts at address zero
+#
+LDFLAGS                += --section-start=.prefix=0
+
 # Media types.
 #
 MEDIA          += rom
@@ -103,13 +107,13 @@ NON_AUTO_MEDIA    += fd0
 
 # Special target for building Master Boot Record binary
 $(BIN)/mbr.bin : $(BIN)/mbr.o
-       $(QM)$(ECHO) "  [OBJCOPY] $@"
-       $(Q)$(OBJCOPY) -O binary $< $@
+       $(QM)$(ECHO) "  [LD] $@"
+       $(Q)$(LD) $(LDFLAGS) -o $@ --oformat binary -e 0 $<
 
 # rule to make a USB disk image
 $(BIN)/usbdisk.bin : $(BIN)/usbdisk.o
-       $(QM)$(ECHO) "  [OBJCOPY] $@"
-       $(Q)$(OBJCOPY) -O binary $< $@
+       $(QM)$(ECHO) "  [LD] $@"
+       $(Q)$(LD) $(LDFLAGS) -o $@ --oformat binary -e 0 $<
 
 NON_AUTO_MEDIA += usb
 %usb: $(BIN)/usbdisk.bin %hd