Don't use -N to set the OMAGIC with data and text writeable and data

not page aligned. To do this, use the ld script gnu ld installs on my
system.

This is imperfect: LDFLAGS_BIN and LD_FLAGS_BIN describe different
things. The loader script could be better named and take into account
other architectures. And having two different mechanisms to do
basically the same thing needs study. However, it's blocking forward
progress on lld, so I'll work in parallel to sort these out.

Differential Revision: https://reviews.freebsd.org/D7409
Reviewed by: emaste
This commit is contained in:
Warner Losh 2016-09-03 15:26:28 +00:00
parent d69d5ab04f
commit 155d3e43ff
19 changed files with 42 additions and 20 deletions

View File

@ -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"

View File

@ -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 = .;
}

View File

@ -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 <bsd.prog.mk>

View File

@ -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 <bsd.init.mk>

View File

@ -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 <bsd.prog.mk>

View File

@ -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 <bsd.prog.mk>

View File

@ -10,7 +10,7 @@ CFLAGS+=-I${.CURDIR}/../common
ORG= 0x7c00
LDFLAGS=-e start -Ttext ${ORG} -Wl,-N,-S,--oformat,binary
LDFLAGS=${LDFLAGS_BIN}
.include <bsd.prog.mk>

View File

@ -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

View File

@ -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

View File

@ -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 <bsd.prog.mk>

View File

@ -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 <bsd.prog.mk>

View File

@ -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}

View File

@ -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

View File

@ -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"

View File

@ -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 <bsd.prog.mk>

View File

@ -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 <bsd.init.mk>

View File

@ -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 <bsd.prog.mk>

View File

@ -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 <bsd.prog.mk>

View File

@ -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 <bsd.prog.mk>