diff --git a/sys/boot/i386/Makefile.inc b/sys/boot/i386/Makefile.inc index d209b5f28bb1..312a374b9b9b 100644 --- a/sys/boot/i386/Makefile.inc +++ b/sys/boot/i386/Makefile.inc @@ -28,4 +28,9 @@ BTXLDR= ${BTXDIR}/btxldr/btxldr BTXKERN= ${BTXDIR}/btx/btx BTXCRT= ${BTXDIR}/lib/crt0.o +# compact binary with no padding between text, data, bss +LDSCRIPT= ${SRCTOP}/sys/boot/i386/boot.ldscript +LDFLAGS_BIN=-e start -Ttext ${ORG} -Wl,-T,${LDSCRIPT},-S,--oformat,binary +LD_FLAGS_BIN=-static -T ${LDSCRIPT} --gc-sections + .include "../Makefile.inc" diff --git a/sys/boot/i386/boot.ldscript b/sys/boot/i386/boot.ldscript new file mode 100644 index 000000000000..04ea39d47693 --- /dev/null +++ b/sys/boot/i386/boot.ldscript @@ -0,0 +1,11 @@ +/* $FreeBSD$ */ +/* Merge text, data and bss together almost no padding */ +OUTPUT_FORMAT("elf32-i386-freebsd") +OUTPUT_ARCH(i386) +ENTRY(_start) +SECTIONS { + . = 0x08048000 + SIZEOF_HEADERS; + .text : { *(.text) } =0x90909090 /* Pad with nops, if needed */ + .data : { *(.data) } _edata = .; + .bss : { *(.bss) } _end = .; +} diff --git a/sys/boot/i386/boot0/Makefile b/sys/boot/i386/boot0/Makefile index f5faef39338a..db761c2f2663 100644 --- a/sys/boot/i386/boot0/Makefile +++ b/sys/boot/i386/boot0/Makefile @@ -40,6 +40,7 @@ BOOT_BOOT0_TICKS?= 0xb6 # The base address that we the boot0 code to to run it. Don't change this # unless you are glutton for punishment. BOOT_BOOT0_ORG?= 0x600 +ORG=${BOOT_BOOT0_ORG} # Comm settings for boot0sio. # Bit(s) Description @@ -74,7 +75,7 @@ CFLAGS+=-DFLAGS=${BOOT_BOOT0_FLAGS} \ -DTICKS=${BOOT_BOOT0_TICKS} \ -DCOMSPEED=${BOOT_BOOT0_COMCONSOLE_SPEED} -LDFLAGS=-e start -Ttext ${BOOT_BOOT0_ORG} -Wl,-N,-S,--oformat,binary +LDFLAGS=${LDFLAGS_BIN} .include diff --git a/sys/boot/i386/boot2/Makefile b/sys/boot/i386/boot2/Makefile index aac799335f12..35665203695f 100644 --- a/sys/boot/i386/boot2/Makefile +++ b/sys/boot/i386/boot2/Makefile @@ -48,7 +48,7 @@ CFLAGS.gcc+= -mno-align-long-strings CFLAGS.clang+= -Oz ${CLANG_OPT_SMALL} -LD_FLAGS=-static -N --gc-sections +LD_FLAGS=${LD_FLAGS_BIN} # Pick up ../Makefile.inc early. .include diff --git a/sys/boot/i386/btx/btx/Makefile b/sys/boot/i386/btx/btx/Makefile index a07e00001d4f..11fd9c7d96a6 100644 --- a/sys/boot/i386/btx/btx/Makefile +++ b/sys/boot/i386/btx/btx/Makefile @@ -25,7 +25,7 @@ CFLAGS+=-DBTX_SERIAL -DSIOPRT=${BOOT_COMCONSOLE_PORT} \ ORG= 0x9000 -LDFLAGS=-e start -Ttext ${ORG} -Wl,-N,-S,--oformat,binary +LDFLAGS=${LDFLAGS_BIN} .include diff --git a/sys/boot/i386/btx/btxldr/Makefile b/sys/boot/i386/btx/btxldr/Makefile index bf7833dc5459..c785b60ffeb1 100644 --- a/sys/boot/i386/btx/btxldr/Makefile +++ b/sys/boot/i386/btx/btxldr/Makefile @@ -12,7 +12,8 @@ CFLAGS+=-I${.CURDIR}/../../common CFLAGS+=-DBTXLDR_VERBOSE .endif -LDFLAGS=-e start -Ttext ${LOADER_ADDRESS} -Wl,-N,-S,--oformat,binary +ORG=${LOADER_ADDRESS} +LDFLAGS=${LDFLAGS_BIN} .include diff --git a/sys/boot/i386/cdboot/Makefile b/sys/boot/i386/cdboot/Makefile index e9e046b68665..e2fec39d0e1f 100644 --- a/sys/boot/i386/cdboot/Makefile +++ b/sys/boot/i386/cdboot/Makefile @@ -10,7 +10,7 @@ CFLAGS+=-I${.CURDIR}/../common ORG= 0x7c00 -LDFLAGS=-e start -Ttext ${ORG} -Wl,-N,-S,--oformat,binary +LDFLAGS=${LDFLAGS_BIN} .include diff --git a/sys/boot/i386/gptboot/Makefile b/sys/boot/i386/gptboot/Makefile index b89a47272083..626a42a7bd81 100644 --- a/sys/boot/i386/gptboot/Makefile +++ b/sys/boot/i386/gptboot/Makefile @@ -47,7 +47,7 @@ LIBGELIBOOT= ${.OBJDIR}/../../geli/libgeliboot.a OPENCRYPTO_XTS= xform_aes_xts.o .endif -LD_FLAGS=-static -N --gc-sections +LD_FLAGS=${LD_FLAGS_BIN} LIBSTAND= ${.OBJDIR}/../../libstand32/libstand.a diff --git a/sys/boot/i386/gptzfsboot/Makefile b/sys/boot/i386/gptzfsboot/Makefile index cd4eef812475..e8d7d5187269 100644 --- a/sys/boot/i386/gptzfsboot/Makefile +++ b/sys/boot/i386/gptzfsboot/Makefile @@ -46,7 +46,7 @@ OPENCRYPTO_XTS= xform_aes_xts.o CFLAGS.gcc+= --param max-inline-insns-single=100 -LD_FLAGS=-static -N --gc-sections +LD_FLAGS=${LD_FLAGS_BIN} LIBSTAND= ${.OBJDIR}/../../libstand32/libstand.a diff --git a/sys/boot/i386/mbr/Makefile b/sys/boot/i386/mbr/Makefile index d1a652cbeaeb..ac10723059f6 100644 --- a/sys/boot/i386/mbr/Makefile +++ b/sys/boot/i386/mbr/Makefile @@ -12,6 +12,6 @@ BOOT_MBR_FLAGS?= 0x80 ORG= 0x600 AFLAGS+=--defsym FLAGS=${BOOT_MBR_FLAGS} -LDFLAGS=-e start -Ttext ${ORG} -Wl,-N,-S,--oformat,binary +LDFLAGS=${LDFLAGS_BIN} .include diff --git a/sys/boot/i386/pmbr/Makefile b/sys/boot/i386/pmbr/Makefile index cc12f4919ca8..243167a2177f 100644 --- a/sys/boot/i386/pmbr/Makefile +++ b/sys/boot/i386/pmbr/Makefile @@ -9,6 +9,6 @@ SRCS= ${PROG}.s ORG= 0x600 AFLAGS+=--defsym FLAGS=${BOOT_MBR_FLAGS} -LDFLAGS=-e start -Ttext ${ORG} -Wl,-N,-S,--oformat,binary +LDFLAGS=${LDFLAGS_BIN} .include diff --git a/sys/boot/i386/pxeldr/Makefile b/sys/boot/i386/pxeldr/Makefile index 8de21395f05a..5f2fc181283e 100644 --- a/sys/boot/i386/pxeldr/Makefile +++ b/sys/boot/i386/pxeldr/Makefile @@ -34,7 +34,7 @@ ${BOOT}: ${LDR} ${LOADER} dd if=${.TARGET}.tmp of=${.TARGET} obs=2k conv=osync status=none rm ${.TARGET}.tmp -LDFLAGS+=-e start -Ttext ${ORG} -Wl,-N,-S,--oformat,binary +LDFLAGS+=${LDFLAGS_BIN} CLEANFILES+= ${LOADER} diff --git a/sys/boot/i386/zfsboot/Makefile b/sys/boot/i386/zfsboot/Makefile index dadcecb915d1..e12a481387db 100644 --- a/sys/boot/i386/zfsboot/Makefile +++ b/sys/boot/i386/zfsboot/Makefile @@ -36,7 +36,7 @@ CFLAGS= -DBOOTPROG=\"zfsboot\" \ CFLAGS.gcc+= --param max-inline-insns-single=100 -LD_FLAGS=-static -N --gc-sections +LD_FLAGS=${LD_FLAGS_BIN} LIBSTAND= ${.OBJDIR}/../../libstand32/libstand.a diff --git a/sys/boot/pc98/Makefile.inc b/sys/boot/pc98/Makefile.inc index 76774b3b6b2a..829793d63bd3 100644 --- a/sys/boot/pc98/Makefile.inc +++ b/sys/boot/pc98/Makefile.inc @@ -21,4 +21,9 @@ BTXLDR= ${BTXDIR}/btxldr/btxldr BTXKERN= ${BTXDIR}/btx/btx BTXCRT= ${BTXDIR}/lib/crt0.o +# compact binary with no padding between text, data, bss +LDSCRIPT= ${SRCTOP}/sys/boot/i386/boot.ldscript +LDFLAGS_BIN=-e start -Ttext ${ORG} -Wl,-T,${LDSCRIPT},-S,--oformat,binary +LD_FLAGS_BIN=-static -T ${LDSCRIPT} --gc-sections + .include "../Makefile.inc" diff --git a/sys/boot/pc98/boot0/Makefile b/sys/boot/pc98/boot0/Makefile index fd92a5d9cd62..d348f6020e41 100644 --- a/sys/boot/pc98/boot0/Makefile +++ b/sys/boot/pc98/boot0/Makefile @@ -1,6 +1,6 @@ # $FreeBSD$ -PROG= ${BOOT}.out +PROG= ${BOOT} INTERNALPROG= FILES= ${BOOT} MAN= @@ -12,10 +12,8 @@ BOOT= boot0 # The base address that we the boot0 code to to run it. Don't change this # unless you are glutton for punishment. BOOT_BOOT0_ORG?= 0x0000 +ORG=${BOOT_BOOT0_ORG} -LDFLAGS=-e start -Ttext ${BOOT_BOOT0_ORG} -Wl,-N - -${BOOT}: ${BOOT}.out - ${OBJCOPY} -S -O binary ${BOOT}.out ${.TARGET} +LDFLAGS=${LDFLAGS_BIN} .include diff --git a/sys/boot/pc98/boot2/Makefile b/sys/boot/pc98/boot2/Makefile index 8d5e791dcb18..152ec4a1244e 100644 --- a/sys/boot/pc98/boot2/Makefile +++ b/sys/boot/pc98/boot2/Makefile @@ -52,7 +52,7 @@ CFLAGS.gcc+= -mno-align-long-strings CFLAGS.clang+= -Oz ${CLANG_OPT_SMALL} -LD_FLAGS=-static -N --gc-sections +LD_FLAGS=${LD_FLAGS_BIN} # Pick up ../Makefile.inc early. .include diff --git a/sys/boot/pc98/btx/btx/Makefile b/sys/boot/pc98/btx/btx/Makefile index 9046d351212f..275546068286 100644 --- a/sys/boot/pc98/btx/btx/Makefile +++ b/sys/boot/pc98/btx/btx/Makefile @@ -25,7 +25,7 @@ CFLAGS+=-DBTX_SERIAL -DSIOPRT=${BOOT_COMCONSOLE_PORT} \ ORG= 0x9000 -LDFLAGS=-e start -Ttext ${ORG} -Wl,-N,-S,--oformat,binary +LDFLAGS=${LDFLAGS_BIN} .include diff --git a/sys/boot/pc98/btx/btxldr/Makefile b/sys/boot/pc98/btx/btxldr/Makefile index b0c8996aa7ec..47e83a083056 100644 --- a/sys/boot/pc98/btx/btxldr/Makefile +++ b/sys/boot/pc98/btx/btxldr/Makefile @@ -12,7 +12,8 @@ CFLAGS+=-I${.CURDIR}/../../../i386/common CFLAGS+=-DBTXLDR_VERBOSE .endif -LDFLAGS=-e start -Ttext ${LOADER_ADDRESS} -Wl,-N,-S,--oformat,binary +ORG=${LOADER_ADDRESS} +LDFLAGS=${LDFLAGS_BIN} .include diff --git a/sys/boot/pc98/cdboot/Makefile b/sys/boot/pc98/cdboot/Makefile index 3b91c1285f0d..ba94111362c5 100644 --- a/sys/boot/pc98/cdboot/Makefile +++ b/sys/boot/pc98/cdboot/Makefile @@ -10,7 +10,7 @@ CFLAGS+=-I${.CURDIR}/../../i386/common ORG= 0x0000 -LDFLAGS=-e start -Ttext ${ORG} -Wl,-N,-S,--oformat,binary +LDFLAGS=${LDFLAGS_BIN} .include