From owner-svn-src-all@freebsd.org Sun Dec 29 18:17:13 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 9CBF71E5D70; Sun, 29 Dec 2019 18:17:13 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47m80n3hxbz3wn7; Sun, 29 Dec 2019 18:17:13 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7A3FC1D69D; Sun, 29 Dec 2019 18:17:13 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xBTIHDJd003926; Sun, 29 Dec 2019 18:17:13 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xBTIHCda003923; Sun, 29 Dec 2019 18:17:12 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201912291817.xBTIHCda003923@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 29 Dec 2019 18:17:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356180 - head/sys/conf X-SVN-Group: head X-SVN-Commit-Author: ian X-SVN-Commit-Paths: head/sys/conf X-SVN-Commit-Revision: 356180 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 Dec 2019 18:17:13 -0000 Author: ian Date: Sun Dec 29 18:17:12 2019 New Revision: 356180 URL: https://svnweb.freebsd.org/changeset/base/356180 Log: Eliminate the generated ldscript for arm and arm64, and strip $a/$d marker symbols from the linked kernel. The main thrust of this change is to generate a kernel that has the arm "marker" symbols stripped. Marker symbols start with $a, $d, $t or $x, and are emitted by the compiler to tell other toolchain components about the locations of data embedded in the instruction stream (literal-pool stuff). They are used for generating mixed-endian binaries (which we don't support). The linked kernel has approximately 21,000 such symbols in it, wasting space (500K in kernel.full, 190K in the final linked kernel), and sometimes obscuring function names in stack tracebacks. This change also simplifies the way the kernel is linked. Instead of using sed to generate two different ldscript files to generate both an elf kernel and a binary (elf headers stripped) kernel, we now use a single ldscript that refers to a "text_start" symbol, and we provide the value for that symbol using --defsym on the linker command line. Modified: head/sys/conf/Makefile.arm head/sys/conf/Makefile.arm64 head/sys/conf/ldscript.arm head/sys/conf/ldscript.arm64 Modified: head/sys/conf/Makefile.arm ============================================================================== --- head/sys/conf/Makefile.arm Sun Dec 29 17:19:57 2019 (r356179) +++ head/sys/conf/Makefile.arm Sun Dec 29 18:17:12 2019 (r356180) @@ -32,9 +32,6 @@ S= ../../.. INCLUDES+= -I$S/contrib/libfdt -I$S/gnu/dts/include -SYSTEM_LD:= ${SYSTEM_LD:$S/conf/ldscript.$M=ldscript.$M} -SYSTEM_DEP:= ${SYSTEM_DEP:$S/conf/ldscript.$M=ldscript.$M} - .if !defined(DEBUG) && !defined(PROFLEVEL) STRIP_FLAGS = -S .endif @@ -58,20 +55,41 @@ CFLAGS += -mllvm -arm-enable-ehabi KERNVIRTADDR= 0xc0000000 .endif +# Use a custom SYSTEM_LD command to generate the elf kernel, so we can +# set the text segment start address, and also strip the "arm mapping +# symbols" which have names like $a.0 and $d.2; see the document +# "ELF for the ARM architecture" for more info on the mapping symbols. +SYSTEM_LD= \ + ${SYSTEM_LD_BASECMD} \ + --defsym='text_start=${KERNVIRTADDR} + SIZEOF_HEADERS' \ + -o ${.TARGET} ${SYSTEM_OBJS} vers.o; \ + $(OBJCOPY) \ + --wildcard \ + --strip-symbol='$$[adt]*' \ + ${.TARGET} + +# Generate the .bin (no elf headers) kernel as an extra build output. +# We must relink to generate the .bin kernel, because without headers the +# location of everything changes. We also strip the ARM marker symbols. +KERNEL_EXTRA+= ${KERNEL_KO}.bin +KERNEL_EXTRA_INSTALL+= ${KERNEL_KO}.bin + +${KERNEL_KO}.bin: ${SYSTEM_DEP} vers.o + @echo "linking ${.TARGET}" + @${SYSTEM_LD_BASECMD} \ + --defsym='text_start=${KERNVIRTADDR}' \ + -o ${.TARGET} ${SYSTEM_OBJS} vers.o + ${SIZE} ${.TARGET} + @${OBJCOPY} \ + --wildcard \ + --strip-symbol='$$[adt]*' \ + --output-target=binary \ + ${.TARGET} + @chmod 755 ${.TARGET} + # hack because genassym.c includes sys/bus.h which includes these. genassym.o: bus_if.h device_if.h -SYSTEM_LD_ = ${LD} -m ${LD_EMULATION} -Bdynamic -T ldscript.$M.noheader \ - ${_LDFLAGS} --no-warn-mismatch --warn-common --export-dynamic \ - --dynamic-linker /red/herring \ - -o ${FULLKERNEL}.noheader -X ${SYSTEM_OBJS} vers.o -SYSTEM_LD_TAIL +=;sed s/" + SIZEOF_HEADERS"// ldscript.$M \ - >ldscript.$M.noheader; \ - ${SYSTEM_LD_}; \ - ${OBJCOPY} -S -O binary ${FULLKERNEL}.noheader \ - ${KERNEL_KO}.bin; \ - rm ${FULLKERNEL}.noheader - %BEFORE_DEPEND %OBJS @@ -84,10 +102,7 @@ SYSTEM_LD_TAIL +=;sed s/" + SIZEOF_HEADERS"// ldscript %CLEAN -CLEAN+= ldscript.$M ${KERNEL_KO}.bin ldscript.$M.noheader - -ldscript.$M: $S/conf/ldscript.$M - sed s/KERNVIRTADDR/${KERNVIRTADDR}/g > ldscript.$M < $S/conf/ldscript.$M +CLEAN+= ${KERNEL_KO}.bin %RULES Modified: head/sys/conf/Makefile.arm64 ============================================================================== --- head/sys/conf/Makefile.arm64 Sun Dec 29 17:19:57 2019 (r356179) +++ head/sys/conf/Makefile.arm64 Sun Dec 29 18:17:12 2019 (r356180) @@ -27,24 +27,42 @@ S= ../../.. INCLUDES+= -I$S/contrib/libfdt -#SYSTEM_LD:= ${SYSTEM_LD:$S/conf/ldscript.$M=ldscript.$M} -#SYSTEM_DEP:= ${SYSTEM_DEP:$S/conf/ldscript.$M=ldscript.$M} +# Use a custom SYSTEM_LD command to generate the elf kernel, so we can +# set the text segment start address, and also strip the "arm mapping +# symbols" which have names like $a.0 and $d.2; see the document +# "ELF for the ARM architecture" for more info on the mapping symbols. +SYSTEM_LD= \ + ${SYSTEM_LD_BASECMD} \ + --defsym='text_start=kernbase + SIZEOF_HEADERS' \ + -o ${.TARGET} ${SYSTEM_OBJS} vers.o; \ + $(OBJCOPY) \ + --wildcard \ + --strip-symbol='$$[adtx]*' \ + ${.TARGET} +# Generate the .bin (no elf headers) kernel as an extra build output. +# We must relink to generate the .bin kernel, because without headers the +# location of everything changes. We also strip the ARM marker symbols. +KERNEL_EXTRA+= ${KERNEL_KO}.bin +KERNEL_EXTRA_INSTALL+= ${KERNEL_KO}.bin + +${KERNEL_KO}.bin: ${SYSTEM_DEP} vers.o + @echo "linking ${.TARGET}" + @${SYSTEM_LD_BASECMD} \ + --defsym='text_start=kernbase' \ + -o ${.TARGET} ${SYSTEM_OBJS} vers.o + ${SIZE} ${.TARGET} + @${OBJCOPY} \ + --wildcard \ + --strip-symbol='$$[adtx]*' \ + --output-target=binary \ + ${.TARGET} + @chmod 755 ${.TARGET} + .if !empty(DDB_ENABLED) CFLAGS += -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer .endif -SYSTEM_LD_ = ${LD} -m ${LD_EMULATION} -Bdynamic -T ldscript.$M.noheader \ - ${_LDFLAGS} --no-warn-mismatch --warn-common --export-dynamic \ - --dynamic-linker /red/herring \ - -o ${FULLKERNEL}.noheader -X ${SYSTEM_OBJS} vers.o -SYSTEM_LD_TAIL +=;sed s/" + SIZEOF_HEADERS"// $(LDSCRIPT)\ - >ldscript.$M.noheader;\ - ${SYSTEM_LD_}; \ - ${OBJCOPY} -S -O binary ${FULLKERNEL}.noheader \ - ${KERNEL_KO}.bin; \ - rm ${FULLKERNEL}.noheader - %BEFORE_DEPEND %OBJS @@ -56,7 +74,7 @@ SYSTEM_LD_TAIL +=;sed s/" + SIZEOF_HEADERS"// $(LDSCRI %FILES.m %CLEAN -CLEAN+= ldscript.$M ${KERNEL_KO}.bin ldscript.$M.noheader +CLEAN+= ${KERNEL_KO}.bin %RULES Modified: head/sys/conf/ldscript.arm ============================================================================== --- head/sys/conf/ldscript.arm Sun Dec 29 17:19:57 2019 (r356179) +++ head/sys/conf/ldscript.arm Sun Dec 29 18:17:12 2019 (r356180) @@ -6,7 +6,7 @@ SEARCH_DIR(/usr/lib); SECTIONS { /* Read-only sections, merged into text segment: */ - . = KERNVIRTADDR + SIZEOF_HEADERS; + . = text_start; /* This is set using --defsym= on the command line. */ .text : { *(.text) Modified: head/sys/conf/ldscript.arm64 ============================================================================== --- head/sys/conf/ldscript.arm64 Sun Dec 29 17:19:57 2019 (r356179) +++ head/sys/conf/ldscript.arm64 Sun Dec 29 18:17:12 2019 (r356180) @@ -6,7 +6,7 @@ SEARCH_DIR(/usr/lib); SECTIONS { /* Read-only sections, merged into text segment: */ - . = kernbase + SIZEOF_HEADERS; + . = text_start; /* This is set using --defsym= on the command line. */ .text : { *(.text)