Re: macppc: add ld.script for kernel, ofwboot
On Mon, May 10, 2021 at 09:49:24PM +0200, Mark Kettenis wrote: > > Date: Mon, 10 May 2021 14:22:33 -0400 > > From: George Koehler > > > > On Fri, 7 May 2021 10:31:55 +0200 (CEST) > > Mark Kettenis wrote: > > > > > Makes sense to me. It seems ldd always seems to require a little bit > > > more coercion to produce non-standard binaries. We use linker scripts > > > for the various EFI bootloaders as well. > > > > > > ok kettenis@ > > > > My diff had an extra "pwd" in arch/macppc/stand/ofwboot/Makefile; > > I deleted the "pwd" before committing it. > > > > > > -${PROG}: ${OBJS} ${LIBSA} ${LIBZ} > > > > - ${LD} -nopie -znorelro -N -X -Ttext ${RELOC} -e ${ENTRY} -o > > > > ${PROG} \ > > > > +${PROG}: ${OBJS} ${LIBSA} ${LIBZ} ld.script > > > > + pwd > > > > + ${LD} -nopie -znorelro -N -X -T ${.CURDIR}/ld.script -o ${PROG} > > > > \ > > > > ${OBJS} ${LIBS} > > > > >From my experiments with lld 10, I believe that macppc is almost ready > > to switch from ld.bfd to ld.lld. I know of 2 other problems: > > > > 1. ports/lang/gcc/8 needs USE_LLD = No, because lld 10 can't link > > C++ code from gcc. (I have not yet checked lld 11.) lld had no > > problem with Fortran ports built by gcc. > > > > 2. All instances of -Wl,-relax or -Wl,--relax in src or ports must > > be deleted, because it is an unknown option to lld, but lld can > > link large binaries without the option. > > Maybe just coordinate with Theo and the ports folks and move ahead. Index: gnu/usr.bin/clang/Makefile.inc === RCS file: /home/cvs/src/gnu/usr.bin/clang/Makefile.inc,v retrieving revision 1.24 diff -u -p -u -p -r1.24 Makefile.inc --- gnu/usr.bin/clang/Makefile.inc 19 May 2021 23:18:40 - 1.24 +++ gnu/usr.bin/clang/Makefile.inc 5 Jun 2021 03:40:20 - @@ -77,7 +77,3 @@ DPADD+= ${.OBJDIR}/../lib${lib}/lib${lib LDADD+=${.OBJDIR}/../lib${lib}/lib${lib}.a .endfor LDADD+=-Wl,--end-group - -.if ${MACHINE_ARCH} == "powerpc" -LDADD+=-Wl,-relax -.endif Index: devel/clang-tools-extra/Makefile === RCS file: /home/cvs/ports/devel/clang-tools-extra/Makefile,v retrieving revision 1.16 diff -u -p -u -p -r1.16 Makefile --- devel/clang-tools-extra/Makefile18 May 2021 06:19:48 - 1.16 +++ devel/clang-tools-extra/Makefile5 Jun 2021 03:32:01 - @@ -67,11 +67,6 @@ CONFIGURE_ARGS +=-DCLANG_ENABLE_STATIC_ -DLLVM_INCLUDE_EXAMPLES=OFF \ -DLLVM_INCLUDE_TESTS=OFF -.if ${MACHINE_ARCH} == "powerpc" -CONFIGURE_ARGS += -DCMAKE_EXE_LINKER_FLAGS="-Wl,--relax" -CONFIGURE_ARGS += -DCMAKE_SHARED_LINKER_FLAGS="-Wl,--relax" -.endif - GCC_VER = 8.4.0 .if ${MACHINE_ARCH} == "amd64" GCC_CONFIG = x86_64-unknown-openbsd${OSREV} Index: devel/llvm/Makefile === RCS file: /home/cvs/ports/devel/llvm/Makefile,v retrieving revision 1.277 diff -u -p -u -p -r1.277 Makefile --- devel/llvm/Makefile 22 May 2021 20:27:35 - 1.277 +++ devel/llvm/Makefile 5 Jun 2021 03:32:12 - @@ -112,11 +112,6 @@ CXXFLAGS+= -mno-retpoline CXXFLAGS+= -fomit-frame-pointer .endif -.if ${MACHINE_ARCH} == "powerpc" -CONFIGURE_ARGS += -DCMAKE_EXE_LINKER_FLAGS="-Wl,-relax" -CONFIGURE_ARGS += -DCMAKE_SHARED_LINKER_FLAGS="-Wl,-relax" -.endif - TEST_TARGET = check check-clang # XXX sync Index: games/godot/Makefile === RCS file: /home/cvs/ports/games/godot/Makefile,v retrieving revision 1.18 diff -u -p -u -p -r1.18 Makefile --- games/godot/Makefile3 May 2021 19:10:24 - 1.18 +++ games/godot/Makefile5 Jun 2021 03:32:32 - @@ -76,11 +76,6 @@ LDFLAGS += -latomic WANTLIB += atomic .endif -# Fix relocation overflows -.if ${MACHINE_ARCH:Mpowerpc} -LDFLAGS += -Wl,--relax -.endif - post-extract: cp -R ${FILESDIR}/sndio ${WRKDIST}/drivers Index: games/scummvm/Makefile === RCS file: /home/cvs/ports/games/scummvm/Makefile,v retrieving revision 1.88 diff -u -p -u -p -r1.88 Makefile --- games/scummvm/Makefile 4 Jan 2021 17:43:02 - 1.88 +++ games/scummvm/Makefile 5 Jun 2021 03:32:48 - @@ -40,11 +40,6 @@ LIB_DEPENDS= audio/fluidsynth \ CXXFLAGS+= -mxgot .endif -# Fix relocation overflows -.if ${MACHINE_ARCH} == "powerpc" -LDFLAGS+= -Wl,--relax -.endif - CONFIGURE_STYLE=simple CONFIGURE_ARGS+=--disable-alsa \ --disable-cloud \ Index: lang/gcc/8/Makefile === RCS file: /home/cvs/ports/lang/gcc/8/Makefile,v retrieving revision 1.41 diff -u -p -u -p -r1.41 Makefile --- lang/gcc/8/Makefile 9 Feb 2021
Re: macppc: add ld.script for kernel, ofwboot
> Date: Mon, 10 May 2021 14:22:33 -0400 > From: George Koehler > > On Fri, 7 May 2021 10:31:55 +0200 (CEST) > Mark Kettenis wrote: > > > Makes sense to me. It seems ldd always seems to require a little bit > > more coercion to produce non-standard binaries. We use linker scripts > > for the various EFI bootloaders as well. > > > > ok kettenis@ > > My diff had an extra "pwd" in arch/macppc/stand/ofwboot/Makefile; > I deleted the "pwd" before committing it. > > > > -${PROG}: ${OBJS} ${LIBSA} ${LIBZ} > > > - ${LD} -nopie -znorelro -N -X -Ttext ${RELOC} -e ${ENTRY} -o ${PROG} \ > > > +${PROG}: ${OBJS} ${LIBSA} ${LIBZ} ld.script > > > + pwd > > > + ${LD} -nopie -znorelro -N -X -T ${.CURDIR}/ld.script -o ${PROG} \ > > > ${OBJS} ${LIBS} > > >From my experiments with lld 10, I believe that macppc is almost ready > to switch from ld.bfd to ld.lld. I know of 2 other problems: > > 1. ports/lang/gcc/8 needs USE_LLD = No, because lld 10 can't link > C++ code from gcc. (I have not yet checked lld 11.) lld had no > problem with Fortran ports built by gcc. > > 2. All instances of -Wl,-relax or -Wl,--relax in src or ports must > be deleted, because it is an unknown option to lld, but lld can > link large binaries without the option. Maybe just coordinate with Theo and the ports folks and move ahead.
Re: macppc: add ld.script for kernel, ofwboot
On Fri, 7 May 2021 10:31:55 +0200 (CEST) Mark Kettenis wrote: > Makes sense to me. It seems ldd always seems to require a little bit > more coercion to produce non-standard binaries. We use linker scripts > for the various EFI bootloaders as well. > > ok kettenis@ My diff had an extra "pwd" in arch/macppc/stand/ofwboot/Makefile; I deleted the "pwd" before committing it. > > -${PROG}: ${OBJS} ${LIBSA} ${LIBZ} > > - ${LD} -nopie -znorelro -N -X -Ttext ${RELOC} -e ${ENTRY} -o ${PROG} \ > > +${PROG}: ${OBJS} ${LIBSA} ${LIBZ} ld.script > > + pwd > > + ${LD} -nopie -znorelro -N -X -T ${.CURDIR}/ld.script -o ${PROG} \ > > ${OBJS} ${LIBS} >From my experiments with lld 10, I believe that macppc is almost ready to switch from ld.bfd to ld.lld. I know of 2 other problems: 1. ports/lang/gcc/8 needs USE_LLD = No, because lld 10 can't link C++ code from gcc. (I have not yet checked lld 11.) lld had no problem with Fortran ports built by gcc. 2. All instances of -Wl,-relax or -Wl,--relax in src or ports must be deleted, because it is an unknown option to lld, but lld can link large binaries without the option. --George
Re: macppc: add ld.script for kernel, ofwboot
> Date: Fri, 7 May 2021 00:04:57 -0400 > From: George Koehler > > Hello tech list, > > I want macppc to switch from ld.bfd to ld.lld, but there is a problem > when lld links ofwboot or the kernel. I propose to fix it by adding > ld.script for both. These scripts also work with ld.bfd, so I want to > commit my diff at the end of this mail, ok? > > lld sets the symbol "etext" to a nonsense value like 0x1034. In > ofwboot, wrong "etext" causes freeze, failure to boot kernel. (Wrong > "etext" in kernel doesn't cause an obvious problem.) Other lld arches > use an ld.script to set a correct "etext" in kernel. > > I copied the ld.script from powerpc64's kernel and made these changes > for macppc's kernel: > - change "_start" to "start" to match macppc/locore0.S > - remove PT_DYNAMIC and sections (don't exist in macppc kernel) > - put .text at 0x00100114 to match Makefile > - remove symbols like "_erodata" (not used by macppc kernel) > - add ".rodata.*" and such, so sections and segments look correct Makes sense to me. It seems ldd always seems to require a little bit more coercion to produce non-standard binaries. We use linker scripts for the various EFI bootloaders as well. ok kettenis@ > | --- arch/powerpc64/conf/ld.script Sat Jul 18 09:16:32 2020 > | +++ arch/macppc/conf/ld.script Sat Apr 24 11:52:34 2021 > | @@ -16,18 +16,17 @@ > | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. > | */ > | > | -ENTRY(_start) > | +ENTRY(start) > | > | PHDRS > | { > | text PT_LOAD; > | - dynamic PT_DYNAMIC; > | openbsd_randomize PT_OPENBSD_RANDOMIZE; > | } > | > | SECTIONS > | { > | - . = 0x0010; > | + . = 0x00100114; > | .text : > | { > | *(.text) > | @@ -35,49 +34,35 @@ > | PROVIDE (etext = .); > | PROVIDE (_etext = .); > | > | - . = ALIGN(4096); > | - .rela.dyn : { *(.rela.dyn) } > | - > | - .dynamic : > | + .rodata : > | { > | - *(.dynamic) > | - } :dynamic :text > | + *(.rodata .rodata.*) > | + } :text > | > | - .rodata : > | + .data.rel.ro : > | { > | - *(.rodata) > | *(.data.rel.ro) > | } :text > | > | .openbsd.randomdata : > | { > | - *(.openbsd.randomdata) > | + *(.openbsd.randomdata .openbsd.randomdata.*) > | } :openbsd_randomize :text > | - PROVIDE (_erodata = .); > | > | - . = ALIGN(4096); > | .data : > | { > | *(.data) > | } :text > | > | - . = ALIGN(4096); > | - .got : { *(.got) } > | - .toc : { *(.toc) } > | + .sbss : > | + { > | + *(.sbss) > | + } > | > | - PROVIDE (__bss_start = .); > | .bss : > | { > | *(.bss) > | } > | PROVIDE (end = .); > | PROVIDE (_end = .); > | - > | - /DISCARD/ : > | - { > | - *(.dynsym) > | - *(.dynstr) > | - *(.gnu.hash) > | - *(.hash) > | - } > | } > > Then I made these changes for ofwboot: > - use "_start" and 0x0002 to match Makefile > - remove randomdata (doesn't exist in ofwboot) > > | --- arch/macppc/conf/ld.script Sat Apr 24 11:52:34 2021 > | +++ arch/macppc/stand/ofwboot/ld.script Sat Apr 24 11:52:34 2021 > | @@ -16,17 +16,17 @@ > | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. > | */ > | > | -ENTRY(start) > | +ENTRY(_start) > | > | PHDRS > | { > | text PT_LOAD; > | - openbsd_randomize PT_OPENBSD_RANDOMIZE; > | } > | > | SECTIONS > | { > | - . = 0x00100114; > | + /* Must match RELOC in Makefile */ > | + . = 0x0002; > | .text : > | { > | *(.text) > | @@ -43,11 +43,6 @@ > | { > | *(.data.rel.ro) > | } :text > | - > | - .openbsd.randomdata : > | - { > | - *(.openbsd.randomdata .openbsd.randomdata.*) > | - } :openbsd_randomize :text > | > | .data : > | { > > Index: arch/macppc/conf/Makefile.macppc > === > RCS file: /cvs/src/sys/arch/macppc/conf/Makefile.macppc,v > retrieving revision 1.101 > diff -u -p -r1.101 Makefile.macppc > --- arch/macppc/conf/Makefile.macppc 28 Jan 2021 17:39:03 - 1.101 > +++ arch/macppc/conf/Makefile.macppc 6 May 2021 20:01:08 - > @@ -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 > Index: arch/macppc/conf/ld.script > === > RCS file: /cvs/src/sys/arch/macppc/conf/ld.script,v > retrieving revision 1.1 > diff -u -p -r1.1 ld.script > --- arch/macppc/conf/ld.script13 Jun 2017 01:42:52 - 1.1 > +++