From: Kevin O'Connor Date: Sun, 6 Jul 2008 13:56:14 +0000 (-0400) Subject: Relinking rom32.o twice seems flaky - make third link stage. X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=seabios.git;a=commitdiff_plain;h=d28997715307a0c44d727f8099b4ac88bf95b1ef Relinking rom32.o twice seems flaky - make third link stage. Sigh - ld seems to move things around when relinking files. So, separate out the link stages so that everything is incremental. Also, improve diagnostics of checkrom.py tool. --- diff --git a/Makefile b/Makefile index 70b0a3e..caf3fcc 100644 --- a/Makefile +++ b/Makefile @@ -91,20 +91,20 @@ $(OUT)romlayout16.o: romlayout.S $(OUT)blob.16.s $(TABLEASM) $(OUT)romlayout32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@) -$(OUT)rom32.notreloc.o: $(OUT)romlayout32.o $(OUT)rombios32.lds +$(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds @echo " Linking (no relocs) $@" - $(Q)ld -r -T $(OUT)rombios32.lds $< -o $@.raw - $(Q)objcopy --prefix-symbols=_code32_ $@.raw $@ + $(Q)ld -r -T $(OUT)rombios32.lds $< -o $@ -$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.notreloc.o $(OUT)rombios16.lds +$(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds @echo " Linking $@" - $(Q)ld -T $(OUT)rombios16.lds -R $(OUT)rom32.notreloc.o $< -o $@ + $(Q)objcopy --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o + $(Q)ld -T $(OUT)rombios16.lds -R $(OUT)rom32.rename.o $< -o $@ -$(OUT)rom32.o: $(OUT)rom16.o $(OUT)romlayout32.o $(OUT)rombios32.lds +$(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios.lds @echo " Linking $@" - $(Q)ld -T $(OUT)rombios32.lds $(OUT)rom16.o $(OUT)romlayout32.o -o $@ + $(Q)ld -T $(OUT)rombios.lds $(OUT)rom16.o $(OUT)rom32.o -o $@ -$(OUT)bios.bin.elf: $(OUT)rom32.o +$(OUT)bios.bin.elf: $(OUT)rom.o @echo " Prepping $@" $(Q)nm $< | ./tools/checkrom.py $(Q)strip $< -o $@ diff --git a/src/rombios.lds.S b/src/rombios.lds.S new file mode 100644 index 0000000..16347f6 --- /dev/null +++ b/src/rombios.lds.S @@ -0,0 +1,29 @@ +// Linker definitions for merging 16 and 32 bit code +// +// Copyright (C) 2008 Kevin O'Connor +// +// This file may be distributed under the terms of the GNU GPLv3 license. + +#include "config.h" + +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") +OUTPUT_ARCH("i386") +ENTRY(post32); +SECTIONS +{ + .text code32_start : { + *(.text) + + . = code16_start ; + final_code16_start = . ; + *(.text16) + + . = code16_fixed_start ; + final_code16_fixed_start = . ; + *(.text16.fixed.addr) + } + + .bss __bss_start : { + *(.bss) + } +} diff --git a/src/rombios16.lds.S b/src/rombios16.lds.S index 4609c1c..43fcdef 100644 --- a/src/rombios16.lds.S +++ b/src/rombios16.lds.S @@ -10,13 +10,21 @@ OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") OUTPUT_ARCH("i386") SECTIONS { - .text16 ( _code32_code16_start - BUILD_BIOS_ADDR ) : { + . = ( _code32_code32_end - BUILD_BIOS_ADDR ) ; + code16_start = . ; + .text16 : { *(.text) *(.rodata*) *(.data) } + freespace1_start = . ; + code16_end = . ; - .text16.fixed.addr BUILD_START_FIXED : { + . = BUILD_START_FIXED ; + code16_fixed_start = . ; + freespace1_end = . ; + .text16.fixed.addr : { *(.text.fixed.addr) } + code16_fixed_end = . ; } diff --git a/src/rombios32.lds.S b/src/rombios32.lds.S index 095703f..6b66f03 100644 --- a/src/rombios32.lds.S +++ b/src/rombios32.lds.S @@ -1,4 +1,4 @@ -// Linker definitions for 16 and 32 bit code +// Linker definitions for 32 bit code // // Copyright (C) 2008 Kevin O'Connor // @@ -8,37 +8,25 @@ OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") OUTPUT_ARCH("i386") -ENTRY(post32); SECTIONS { - .text BUILD_BIOS_ADDR : { - code32_start = . ; + . = BUILD_BIOS_ADDR ; + code32_start = . ; + .text : { *(.text) - - . = ALIGN(16) ; code32_rodata = . ; *(.rodata*) - - . = ALIGN(16) ; code32_data = . ; *(.data) - code32_end = . ; - . = ALIGN(16) ; - code16_start = . ; - *(.text16) - code16_end = . ; - freespace1_start = . ; - - . = BUILD_START_FIXED ; - freespace1_end = . ; - *(.text16.fixed.addr) } + code32_end = . ; - .bss BUILD_BSS_ADDR : { - __bss_start = . ; + . = BUILD_BSS_ADDR ; + __bss_start = . ; + .bss : { *(.bss) *(COMMON) - __bss_end = . ; } + __bss_end = . ; } diff --git a/tools/checkrom.py b/tools/checkrom.py index 032783b..139ba9d 100755 --- a/tools/checkrom.py +++ b/tools/checkrom.py @@ -17,20 +17,25 @@ def main(): except: pass - c16s = syms['code16_start'] - c32s = syms['_code32_code16_start'] - if c16s != c32s: - print "Error! 16bit code moved during linking (0x%x vs 0x%x)" % ( - c32s, c16s) + c16s = syms['code16_start'] + 0xf0000 + c32s = syms['final_code16_start'] + f16s = syms['code16_fixed_start'] + 0xf0000 + f32s = syms['final_code16_fixed_start'] + if c16s != c32s or f16s != f32s: + print ("Error! 16bit code moved during linking" + " (0x%x vs 0x%x, 0x%x vs 0x%x)" % ( + c32s, c16s, f16s, f32s)) sys.exit(1) size16 = syms['code16_end'] - syms['code16_start'] size32 = syms['code32_end'] - syms['code32_start'] sizefree = syms['freespace1_end'] - syms['freespace1_start'] + tablefree = syms['freespace2_end'] - syms['freespace2_start'] print "16bit C-code size: %d" % size16 print "32bit C-code size: %d" % size32 print "Total C-code size: %d" % (size16+size32) print "Free C-code space: %d" % sizefree + print "BIOS table space: %d" % tablefree if __name__ == '__main__': main()