diff options
author | gkoehler <gkoehler@cvs.openbsd.org> | 2021-05-10 17:29:42 +0000 |
---|---|---|
committer | gkoehler <gkoehler@cvs.openbsd.org> | 2021-05-10 17:29:42 +0000 |
commit | c3fc5670031608bfcb0f970330e3bc119ab48333 (patch) | |
tree | 478376c8a3c0e6b302461a6a8cdeb9ebc27577e8 /sys | |
parent | 17d4e9d16dcbcb3af0571c80c044810817b665cc (diff) |
Add ld.script for macppc kernel, ofwboot
These are copies of powerpc64/conf/ld.script with some changes for
macppc. They work with both ld.bfd and ld.lld.
The ld.script fixes ld.lld. Without ld.script, lld would set the
symbol "etext" to a wrong value like 0x10000034, then ofwboot would
freeze and fail to boot the kernel. With ld.script, we PROVIDE a
correct etext.
ok kettenis@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/macppc/conf/Makefile.macppc | 4 | ||||
-rw-r--r-- | sys/arch/macppc/conf/ld.script | 68 | ||||
-rw-r--r-- | sys/arch/macppc/stand/ofwboot/Makefile | 10 | ||||
-rw-r--r-- | sys/arch/macppc/stand/ofwboot/ld.script | 63 |
4 files changed, 137 insertions, 8 deletions
diff --git a/sys/arch/macppc/conf/Makefile.macppc b/sys/arch/macppc/conf/Makefile.macppc index 9db16c54b2a..96c49bc75d8 100644 --- a/sys/arch/macppc/conf/Makefile.macppc +++ b/sys/arch/macppc/conf/Makefile.macppc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.macppc,v 1.101 2021/01/28 17:39:03 deraadt Exp $ +# $OpenBSD: Makefile.macppc,v 1.102 2021/05/10 17:29:41 gkoehler Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -51,7 +51,7 @@ DEBUG?= -g COPTIMIZE?= -O2 CFLAGS= ${DEBUG} ${CWARNFLAGS} ${CMACHFLAGS} ${COPTIMIZE} ${COPTS} ${PIPE} AFLAGS= -D_LOCORE ${CMACHFLAGS} -LINKFLAGS= -N -Ttext 100114 -e start --warn-common -nopie +LINKFLAGS= -N -T ld.script --warn-common -nopie .if ${MACHINE} == "powerpc64" CFLAGS+= -m32 diff --git a/sys/arch/macppc/conf/ld.script b/sys/arch/macppc/conf/ld.script index e69de29bb2d..5d0127a8366 100644 --- a/sys/arch/macppc/conf/ld.script +++ b/sys/arch/macppc/conf/ld.script @@ -0,0 +1,68 @@ +/* $OpenBSD: ld.script,v 1.2 2021/05/10 17:29:41 gkoehler Exp $ */ + +/* + * Copyright (c) 2013 Mark Kettenis <kettenis@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +ENTRY(start) + +PHDRS +{ + text PT_LOAD; + openbsd_randomize PT_OPENBSD_RANDOMIZE; +} + +SECTIONS +{ + . = 0x00100114; + .text : + { + *(.text) + } :text + PROVIDE (etext = .); + PROVIDE (_etext = .); + + .rodata : + { + *(.rodata .rodata.*) + } :text + + .data.rel.ro : + { + *(.data.rel.ro) + } :text + + .openbsd.randomdata : + { + *(.openbsd.randomdata .openbsd.randomdata.*) + } :openbsd_randomize :text + + .data : + { + *(.data) + } :text + + .sbss : + { + *(.sbss) + } + + .bss : + { + *(.bss) + } + PROVIDE (end = .); + PROVIDE (_end = .); +} diff --git a/sys/arch/macppc/stand/ofwboot/Makefile b/sys/arch/macppc/stand/ofwboot/Makefile index 38211823341..0e4ba713b95 100644 --- a/sys/arch/macppc/stand/ofwboot/Makefile +++ b/sys/arch/macppc/stand/ofwboot/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.20 2020/03/16 07:02:10 otto Exp $ +# $OpenBSD: Makefile,v 1.21 2021/05/10 17:29:41 gkoehler Exp $ # $NetBSD: Makefile,v 1.2 1997/04/17 07:46:24 thorpej Exp $ S= ${.CURDIR}/../../../.. @@ -31,18 +31,16 @@ SRCS+= moddi3.c NEWVERSWHAT= "OpenFirmware Boot" -# For now... +# Must match . in ld.script RELOC= 20000 -ENTRY= _start - CPPFLAGS+= -I. -I${.CURDIR}/../../.. -I${.CURDIR}/../../../.. CPPFLAGS+= -DRELOC=0x${RELOC} -DCONSPEED=57600 LIBS!= cd $(.CURDIR)/$(R); $(MAKE) libdep -${PROG}: ${OBJS} ${LIBSA} ${LIBZ} - ${LD} -nopie -znorelro -N -X -Ttext ${RELOC} -e ${ENTRY} -o ${PROG} \ +${PROG}: ${OBJS} ${LIBSA} ${LIBZ} ld.script + ${LD} -nopie -znorelro -N -X -T ${.CURDIR}/ld.script -o ${PROG} \ ${OBJS} ${LIBS} .include <bsd.prog.mk> diff --git a/sys/arch/macppc/stand/ofwboot/ld.script b/sys/arch/macppc/stand/ofwboot/ld.script new file mode 100644 index 00000000000..28c8cb0cc79 --- /dev/null +++ b/sys/arch/macppc/stand/ofwboot/ld.script @@ -0,0 +1,63 @@ +/* $OpenBSD: ld.script,v 1.1 2021/05/10 17:29:41 gkoehler Exp $ */ + +/* + * Copyright (c) 2013 Mark Kettenis <kettenis@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +ENTRY(_start) + +PHDRS +{ + text PT_LOAD; +} + +SECTIONS +{ + /* Must match RELOC in Makefile */ + . = 0x00020000; + .text : + { + *(.text) + } :text + PROVIDE (etext = .); + PROVIDE (_etext = .); + + .rodata : + { + *(.rodata .rodata.*) + } :text + + .data.rel.ro : + { + *(.data.rel.ro) + } :text + + .data : + { + *(.data) + } :text + + .sbss : + { + *(.sbss) + } + + .bss : + { + *(.bss) + } + PROVIDE (end = .); + PROVIDE (_end = .); +} |