aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2020-05-09 10:30:06 +0000
committerDimitry Andric <dim@FreeBSD.org>2020-05-09 10:30:06 +0000
commit2f5f4007e7a7773995a2f30fc287fba85d92fb07 (patch)
tree9650e000db58febafcf308c6eab30dbe31d705ca
parentcb6ff3f4fcd6bd920474b4098fd49f9b90d81236 (diff)
downloadsrc-2f5f4007e7a7773995a2f30fc287fba85d92fb07.tar.gz
src-2f5f4007e7a7773995a2f30fc287fba85d92fb07.zip
MF11 r360838:
MFC r358643: Link stand/i386 components using a linker script LLD 10.0.0 changed the behavior of the -Ttext option, so that using -Ttext=0x0 now causes linking of the loaders to fail with: ld: error: output file too large: 18446744073707016908 bytes I reported this in https://bugs.llvm.org/show_bug.cgi?id=44715, and initially reverted the upstream change in r357259 to work around it. However, after some discussion with Fangrui Song in the upstream ticket, I think we can classify this as an unfortunate interaction between using -Ttext=0 in combination with --no-rosegment. (We added the latter in r332090, because btxld does not correctly handle input with more than 2 PT_LOAD segments.) Fangrui suggested to use a linker script instead, and Warner was already attempting this in r305353, but had to revert it due to "crypto-using boot problems" (not sure what those were :). This review updates the stand/i386/boot.ldscript to handle more sections, inserts some symbols like _edata and such that we use in libsa, and also discards any .interp section. It uses ORG which is defined on the linker command line using --defsym ORG=value to set the start of all the sections. Approved by: re (kib) Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D23952
Notes
Notes: svn path=/releng/11.4/; revision=360840
-rw-r--r--stand/i386/Makefile.inc7
-rw-r--r--stand/i386/boot.ldscript16
-rw-r--r--stand/i386/boot2/Makefile4
-rw-r--r--stand/i386/gptboot/Makefile4
-rw-r--r--stand/i386/gptzfsboot/Makefile4
-rw-r--r--stand/i386/isoboot/Makefile4
-rw-r--r--stand/i386/loader/Makefile4
-rw-r--r--stand/i386/zfsboot/Makefile4
8 files changed, 27 insertions, 20 deletions
diff --git a/stand/i386/Makefile.inc b/stand/i386/Makefile.inc
index ef351fcf3e8a..5da90178de68 100644
--- a/stand/i386/Makefile.inc
+++ b/stand/i386/Makefile.inc
@@ -23,10 +23,9 @@ CFLAGS+= -I${BTXLIB}
# compact binary with no padding between text, data, bss
LDSCRIPT= ${BOOTSRC}/i386/boot.ldscript
-# LDFLAGS_BIN=-e start -Ttext ${ORG} -Wl,-T,${LDSCRIPT},-S,--oformat,binary
-# LD_FLAGS_BIN=-static -T ${LDSCRIPT} --gc-sections
-LDFLAGS_BIN=-e start -Ttext ${ORG} -Wl,-N,-S,--oformat,binary
-LD_FLAGS_BIN=-static -N --gc-sections
+LDFLAGS_ORG= -Wl,--defsym,ORG=${ORG},-T,${LDSCRIPT}
+LDFLAGS_BIN= -e start ${LDFLAGS_ORG} -Wl,-N,-S,--oformat,binary
+LD_FLAGS_BIN= -static -N --gc-sections
.if ${MACHINE_CPUARCH} == "amd64"
DO32=1
diff --git a/stand/i386/boot.ldscript b/stand/i386/boot.ldscript
index 04ea39d47693..2f2a2d3e936e 100644
--- a/stand/i386/boot.ldscript
+++ b/stand/i386/boot.ldscript
@@ -1,11 +1,17 @@
/* $FreeBSD$ */
-/* Merge text, data and bss together almost no padding */
+/* Simplified linker script for the boot loaders. */
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 = .;
+ . = ORG;
+ .text : { *(.text .text.*) } =0xcccccccc /* Pad with int3, if needed */
+ .rodata : { *(.rodata .rodata.*) }
+ .got : { *(.got) *(.igot) }
+ .got.plt : { *(.got.plt) *(.igot.plt) }
+ .data : { *(.data .data.*) }
+ _edata = .; PROVIDE (edata = .);
+ .bss : { *(.bss .bss.*) }
+ _end = .; PROVIDE (end = .);
+ /DISCARD/ : { *(.interp) }
}
diff --git a/stand/i386/boot2/Makefile b/stand/i386/boot2/Makefile
index c982e51fbb02..8df09a2c7c0c 100644
--- a/stand/i386/boot2/Makefile
+++ b/stand/i386/boot2/Makefile
@@ -56,7 +56,7 @@ boot1: boot1.out
${OBJCOPY} -S -O binary boot1.out ${.TARGET}
boot1.out: boot1.o
- ${LD} ${LD_FLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
+ ${LD} ${LD_FLAGS} -e start --defsym ORG=${ORG1} -T ${LDSCRIPT} -o ${.TARGET} boot1.o
CLEANFILES+= boot2 boot2.ld boot2.ldr boot2.bin boot2.out boot2.o \
boot2.h sio.o
@@ -84,7 +84,7 @@ CFLAGS.ashldi3.c= -Wno-missing-prototypes -Wno-missing-declarations
CLEANFILES+= ashldi3.o
boot2.out: ${BTXCRT} boot2.o sio.o ashldi3.o
- ${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC}
+ ${LD} ${LD_FLAGS} --defsym ORG=${ORG2} -T ${LDSCRIPT} -o ${.TARGET} ${.ALLSRC}
SRCS= boot2.c boot2.h
diff --git a/stand/i386/gptboot/Makefile b/stand/i386/gptboot/Makefile
index 242db06f47c1..345a7e762e7d 100644
--- a/stand/i386/gptboot/Makefile
+++ b/stand/i386/gptboot/Makefile
@@ -51,7 +51,7 @@ gptldr.bin: gptldr.out
${OBJCOPY} -S -O binary gptldr.out ${.TARGET}
gptldr.out: gptldr.o
- ${LD} ${LD_FLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} gptldr.o
+ ${LD} ${LD_FLAGS} -e start --defsym ORG=${ORG1} -T ${LDSCRIPT} -o ${.TARGET} gptldr.o
CLEANFILES+= gptboot.bin gptboot.out gptboot.o sio.o crc32.o drv.o \
cons.o ${OPENCRYPTO_XTS}
@@ -60,7 +60,7 @@ gptboot.bin: gptboot.out
${OBJCOPY} -S -O binary gptboot.out ${.TARGET}
gptboot.out: ${BTXCRT} gptboot.o sio.o crc32.o drv.o cons.o ${OPENCRYPTO_XTS}
- ${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC} ${LIBSA32}
+ ${LD} ${LD_FLAGS} --defsym ORG=${ORG2} -T ${LDSCRIPT} -o ${.TARGET} ${.ALLSRC} ${LIBSA32}
.include <bsd.prog.mk>
diff --git a/stand/i386/gptzfsboot/Makefile b/stand/i386/gptzfsboot/Makefile
index 768fd5ea2e4b..8957fea4d62c 100644
--- a/stand/i386/gptzfsboot/Makefile
+++ b/stand/i386/gptzfsboot/Makefile
@@ -55,7 +55,7 @@ gptldr.bin: gptldr.out
${OBJCOPY} -S -O binary gptldr.out ${.TARGET}
gptldr.out: gptldr.o
- ${LD} ${LD_FLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} gptldr.o
+ ${LD} ${LD_FLAGS} -e start --defsym ORG=${ORG1} -T ${LDSCRIPT} -o ${.TARGET} gptldr.o
CLEANFILES+= gptzfsboot.bin gptzfsboot.out zfsboot.o sio.o cons.o \
drv.o gpt.o ${OPENCRYPTO_XTS}
@@ -65,7 +65,7 @@ gptzfsboot.bin: gptzfsboot.out
gptzfsboot.out: ${BTXCRT} zfsboot.o sio.o gpt.o drv.o cons.o \
${OPENCRYPTO_XTS}
- ${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC} ${LIBSA32}
+ ${LD} ${LD_FLAGS} --defsym ORG=${ORG2} -T ${LDSCRIPT} -o ${.TARGET} ${.ALLSRC} ${LIBSA32}
zfsboot.o: ${ZFSSRC}/zfsimpl.c
diff --git a/stand/i386/isoboot/Makefile b/stand/i386/isoboot/Makefile
index d202ce9afb7c..597958065090 100644
--- a/stand/i386/isoboot/Makefile
+++ b/stand/i386/isoboot/Makefile
@@ -53,7 +53,7 @@ gptldr.bin: gptldr.out
${OBJCOPY} -S -O binary gptldr.out ${.TARGET}
gptldr.out: gptldr.o
- ${LD} ${LD_FLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} gptldr.o
+ ${LD} ${LD_FLAGS} -e start --defsym ORG=${ORG1} -T ${LDSCRIPT} -o ${.TARGET} gptldr.o
CLEANFILES+= isoboot.bin isoboot.out isoboot.o sio.o crc32.o drv.o \
cons.o ${OPENCRYPTO_XTS}
@@ -62,6 +62,6 @@ isoboot.bin: isoboot.out
${OBJCOPY} -S -O binary isoboot.out ${.TARGET}
isoboot.out: ${BTXCRT} isoboot.o sio.o crc32.o drv.o cons.o ${OPENCRYPTO_XTS}
- ${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC} ${LIBSA32}
+ ${LD} ${LD_FLAGS} --defsym ORG=${ORG2} -T ${LDSCRIPT} -o ${.TARGET} ${.ALLSRC} ${LIBSA32}
.include <bsd.prog.mk>
diff --git a/stand/i386/loader/Makefile b/stand/i386/loader/Makefile
index dbb993eaad02..54b252395e54 100644
--- a/stand/i386/loader/Makefile
+++ b/stand/i386/loader/Makefile
@@ -46,8 +46,10 @@ HELP_FILES= ${.CURDIR}/help.i386
CLEANFILES+= ${LOADER} ${LOADER}.bin
+ORG= 0x0
+
CFLAGS+= -Wall
-LDFLAGS+= -static -Ttext 0x0
+LDFLAGS+= -static ${LDFLAGS_ORG}
# i386 standalone support library
LIBI386= ${BOOTOBJ}/i386/libi386/libi386.a
diff --git a/stand/i386/zfsboot/Makefile b/stand/i386/zfsboot/Makefile
index b3bd7893a0f6..217166ae1251 100644
--- a/stand/i386/zfsboot/Makefile
+++ b/stand/i386/zfsboot/Makefile
@@ -47,7 +47,7 @@ zfsboot1: zfsldr.out
${OBJCOPY} -S -O binary zfsldr.out ${.TARGET}
zfsldr.out: zfsldr.o
- ${LD} ${LD_FLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} zfsldr.o
+ ${LD} ${LD_FLAGS} -e start --defsym ORG=${ORG1} -T ${LDSCRIPT} -o ${.TARGET} zfsldr.o
CLEANFILES+= zfsboot2 zfsboot.ld zfsboot.ldr zfsboot.bin zfsboot.out \
zfsboot.o zfsboot.s zfsboot.s.tmp sio.o cons.o drv.o
@@ -73,7 +73,7 @@ zfsboot.bin: zfsboot.out
${OBJCOPY} -S -O binary zfsboot.out ${.TARGET}
zfsboot.out: ${BTXCRT} zfsboot.o sio.o drv.o cons.o
- ${LD} ${LD_FLAGS} -Ttext ${ORG2} -o ${.TARGET} ${.ALLSRC} ${LIBSA32}
+ ${LD} ${LD_FLAGS} --defsym ORG=${ORG2} -T ${LDSCRIPT} -o ${.TARGET} ${.ALLSRC} ${LIBSA32}
SRCS= zfsboot.c