Cleanups for pru target
Dimitar Dimitrov <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <1784145.tdWV9SEqCh@dinux-standardpcq35ich92009> |
Hi, I'm attaching two improvements to help the PRU target with --gc-sections, and one cleanup allowed by a recent Binutils change. Regards, Dimitar Dimitar Dimitrov (3): libgloss: pru: Remove sim ld script pru: Enable -ffunction-sections and -fdata-sections libgloss: pru: Place sim syscalls into their own sections libgloss/pru/Makefile.in | 10 +- libgloss/pru/device-specs/sim | 2 +- libgloss/pru/ldscripts/gen-ld-scripts.sh | 80 --------- libgloss/pru/ldscripts/pruelf-sim.x | 200 ----------------------- libgloss/pru/syscalls.S | 4 +- newlib/configure.host | 1 + 6 files changed, 6 insertions(+), 291 deletions(-) delete mode 100755 libgloss/pru/ldscripts/gen-ld-scripts.sh delete mode 100644 libgloss/pru/ldscripts/pruelf-sim.x
0001-libgloss-pru-Place-sim-syscalls-into-their-own-secti.patch
(text/x-patch, 1.1 KB)
From 2249d080b0209f55aa0558f4d322eb5a86386116 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov <[email protected]> Date: Sun, 9 May 2021 16:10:45 +0300 Subject: [PATCH] libgloss: pru: Place sim syscalls into their own sections This should help reduce final ELF size if using --gc-sections linker option. Signed-off-by: Dimitar Dimitrov <[email protected]> --- libgloss/pru/syscalls.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libgloss/pru/syscalls.S b/libgloss/pru/syscalls.S index 3ad0d9215..252231e90 100644 --- a/libgloss/pru/syscalls.S +++ b/libgloss/pru/syscalls.S @@ -32,6 +32,7 @@ .extern _impure_ptr /* Handle return from syscall. */ + .section .text.__SC_ret, "ax" .global __SC_ret .type __SC_ret,@function .func @@ -52,6 +53,7 @@ __SC_ret_skip_errno_set: .endfunc .macro SC fname, id + .section .text.\fname, "ax" .global \fname .type \fname,@function .func @@ -62,8 +64,6 @@ __SC_ret_skip_errno_set: .endfunc .endm - .text - /* Syscalls are used only by simulator. Real HW users use other methods for communicating with the host - remoteproc, rpmsg, shared memory. */ -- 2.31.1
0001-libgloss-pru-Remove-sim-ld-script.patch
(text/x-patch, 11.7 KB)
From aa95a3ab484575685a665e9456ff3aa241e93e8d Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov <[email protected]> Date: Wed, 3 Mar 2021 11:24:50 +0200 Subject: [PATCH] libgloss: pru: Remove sim ld script Binutils LD default linker script was recently fixed to allow memory sizes to be set via command line. Use this feature to remove the special sim linker script in libgloss. It is acceptable to require newer Binutils version here because simulator target is only used for regression testing the toolchain. Real HW targets are not affected. Signed-off-by: Dimitar Dimitrov <[email protected]> --- libgloss/pru/Makefile.in | 10 +- libgloss/pru/device-specs/sim | 2 +- libgloss/pru/ldscripts/gen-ld-scripts.sh | 80 --------- libgloss/pru/ldscripts/pruelf-sim.x | 200 ----------------------- 4 files changed, 3 insertions(+), 289 deletions(-) delete mode 100755 libgloss/pru/ldscripts/gen-ld-scripts.sh delete mode 100644 libgloss/pru/ldscripts/pruelf-sim.x diff --git a/libgloss/pru/Makefile.in b/libgloss/pru/Makefile.in index 7fdbc0cb5..062c9e5cf 100644 --- a/libgloss/pru/Makefile.in +++ b/libgloss/pru/Makefile.in @@ -64,9 +64,6 @@ RANLIB = @RANLIB@ OBJDUMP = `t='$(program_transform_name)'; echo objdump | sed -e $$t` OBJCOPY = `t='$(program_transform_name)'; echo objcopy | sed -e $$t` -# linker scripts -SCRIPTS = `ls ${srcdir}/ldscripts/*.x` - # object files needed OBJS = \ do_global_dtors.o gettimeofday.o \ @@ -101,10 +98,7 @@ LDFLAGS_FOR_TARGET = ${MULTILIB} .S.o: $(CC) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $< -all: ${OUTPUTS} copy_scripts_to_objdir - -copy_scripts_to_objdir: $(srcdir)/ldscripts/gen-ld-scripts.sh - cp $(SCRIPTS) $(objdir) +all: ${OUTPUTS} # # here's where we build the library for each target @@ -130,7 +124,7 @@ distclean maintainer-clean realclean: clean rm -f Makefile config.status $(OUTPUTS) .PHONY: install info install-info clean-info -install: $(OUTPUTS) $(srcdir)/ldscripts/gen-ld-scripts.sh +install: $(OUTPUTS) for outputs in ${OUTPUTS}; do\ ${INSTALL_DATA} $${outputs} ${DESTDIR}${tooldir}/lib${MULTISUBDIR}/$${outputs}; \ done diff --git a/libgloss/pru/device-specs/sim b/libgloss/pru/device-specs/sim index 50d4689e0..049e277aa 100644 --- a/libgloss/pru/device-specs/sim +++ b/libgloss/pru/device-specs/sim @@ -2,4 +2,4 @@ -D__SIM__ *link_device: -%{!r:-Tpruelf-sim.x} +%{!r:--defsym=__IMEM_SIZE=0x40000 --defsym=__DMEM_SIZE=0x4000000 --defsym=__HEAP_SIZE=0x2000000 --defsym=__STACK_SIZE=0x100000} diff --git a/libgloss/pru/ldscripts/gen-ld-scripts.sh b/libgloss/pru/ldscripts/gen-ld-scripts.sh deleted file mode 100755 index ddaf75a7a..000000000 --- a/libgloss/pru/ldscripts/gen-ld-scripts.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: BSD-2-Clause-FreeBSD -# -# Copyright 2018-2019 Dimitar Dimitrov <[email protected]> -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -# Generate additional MCU-specific linker scripts by using the -# default PRU-LD linker script. -# -# We do it automatically so that: -# 1. We only change the default linker script in binutils. -# 2. All the default script complexity stays in binutils. -# 3. Here in libgloss we only bump the memory sizes to -# allow large test programs to be executed. - -dump_modified() -{ - IMEM_SIZE=$1 - DMEM_SIZE=$2 - HEAP_SIZE=$3 - STACK_SIZE=$4 - - echo "/* WARNING: automatically generated from the default pru-ld script! */" - echo -e "\n\n" - pru-ld --verbose | awk " -BEGIN { LDV_MARKER = 0; } -{ - if (\$0 == \"==================================================\" ) - { - LDV_MARKER++; - } - else if (LDV_MARKER != 1) - { - } - else if (\$0 ~ /^ imem.*ORIGIN =.*LENGTH =/) - { - print \" imem (x) : ORIGIN = 0x20000000, LENGTH = $IMEM_SIZE\" - } - else if (\$0 ~ /^ dmem.*ORIGIN =.*LENGTH =/) - { - print \" dmem (rw!x) : ORIGIN = 0x0, LENGTH = $DMEM_SIZE\" - } - else if (\$0 ~ /^__HEAP_SIZE = DEFINED/) - { - print \"__HEAP_SIZE = DEFINED(__HEAP_SIZE) ? __HEAP_SIZE : $HEAP_SIZE ;\"; - } - else if (\$0 ~ /^__STACK_SIZE = DEFINED/) - { - print \"__STACK_SIZE = DEFINED(__STACK_SIZE) ? __STACK_SIZE : $STACK_SIZE ;\"; - } - else - { - print \$0; - } -}" -} - -# IMEM DMEM HEAP_SIZE STACK_SIZE -dump_modified 256K 65536K "32 * 1024 * 1024" "1024 * 1024" | tee pruelf-sim.x diff --git a/libgloss/pru/ldscripts/pruelf-sim.x b/libgloss/pru/ldscripts/pruelf-sim.x deleted file mode 100644 index 1dc8b4f2e..000000000 --- a/libgloss/pru/ldscripts/pruelf-sim.x +++ /dev/null @@ -1,200 +0,0 @@ -/* WARNING: automatically generated from the default pru-ld script! */ - - - -/* Default linker script, for normal executables */ -OUTPUT_FORMAT("elf32-pru","elf32-pru","elf32-pru") -OUTPUT_ARCH(pru) -MEMORY -{ - imem (x) : ORIGIN = 0x20000000, LENGTH = 256K - dmem (rw!x) : ORIGIN = 0x0, LENGTH = 65536K -} -__HEAP_SIZE = DEFINED(__HEAP_SIZE) ? __HEAP_SIZE : 32 * 1024 * 1024 ; -__STACK_SIZE = DEFINED(__STACK_SIZE) ? __STACK_SIZE : 1024 * 1024 ; -PROVIDE (_stack_top = ORIGIN(dmem) + LENGTH(dmem)); -ENTRY (_start) -SECTIONS -{ - /* Read-only sections, merged into text segment: */ - .hash : { *(.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - .gnu.version : { *(.gnu.version) } - .gnu.version_d : { *(.gnu.version_d) } - .gnu.version_r : { *(.gnu.version_r) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.text : - { - *(.rel.text) - *(.rel.text.*) - *(.rel.text:*) - *(.rel.gnu.linkonce.t*) - } - .rela.text : - { - *(.rela.text) - *(.rela.text.*) - *(.rela.text:*) - *(.rela.gnu.linkonce.t*) - } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.rodata : - { - *(.rel.rodata) - *(.rel.rodata.*) - *(.rel.rodata:*) - *(.rel.gnu.linkonce.r*) - } - .rela.rodata : - { - *(.rela.rodata) - *(.rela.rodata.*) - *(.rela.rodata:*) - *(.rela.gnu.linkonce.r*) - } - .rel.data : - { - *(.rel.data) - *(.rel.data.*) - *(.rel.data:*) - *(.rel.gnu.linkonce.d*) - } - .rela.data : - { - *(.rela.data) - *(.rela.data.*) - *(.rela.data:*) - *(.rela.gnu.linkonce.d*) - } - .rel.init_array : { *(.rel.init_array) } - .rela.init_array : { *(.rela.init_array) } - .rel.fini_array : { *(.rel.fini_array) } - .rela.fini_array : { *(.rela.fini_array) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - /* Internal text space. */ - .text : - { - _text_start = . ; - . = ALIGN(4); - *(.init0) /* Start here after reset. */ - KEEP (*(.init0)) - . = ALIGN(4); - *(.text) - . = ALIGN(4); - *(.text.*) - . = ALIGN(4); - *(.text:*) - . = ALIGN(4); - *(.gnu.linkonce.t*) - . = ALIGN(4); - _text_end = . ; - } > imem - .data : - { - /* Optional variable that user is prepared to have NULL address. */ - *(.data.atzero*) - /* CRT is prepared for constructor/destructor table to have - a "valid" NULL address. */ - __init_array_start = . ; - KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*))) - KEEP (*(.init_array)) - __init_array_end = . ; - __fini_array_start = . ; - KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*))) - KEEP (*(.fini_array)) - __fini_array_end = . ; - /* DATA memory starts at address 0. So to avoid placing a valid static - variable at the invalid NULL address, we introduce the .data.atzero - section. If CRT can make some use of it - great. Otherwise skip a - word. In all cases .data/.bss sections must start at non-zero. */ - . += (. == 0 ? 4 : 0); - PROVIDE (_data_start = .) ; - *(.data) - *(.data*) - *(.data:*) - *(.rodata) /* We need to include .rodata here if gcc is used. */ - *(.rodata.*) /* with -fdata-sections. */ - *(.rodata:*) - *(.gnu.linkonce.d*) - *(.gnu.linkonce.r*) - . = ALIGN(4); - PROVIDE (_data_end = .) ; - } > dmem - .resource_table : - { - KEEP (*(.resource_table)) - } > dmem - .bss : - { - PROVIDE (_bss_start = .) ; - *(.bss) - *(.bss.*) - *(.bss:*) - *(.gnu.linkonce.b*) - *(COMMON) - PROVIDE (_bss_end = .) ; - } > dmem - /* Global data not cleared after reset. */ - .noinit : - { - PROVIDE (_noinit_start = .) ; - *(.noinit) - PROVIDE (_noinit_end = .) ; - PROVIDE (_heap_start = .) ; - . += __HEAP_SIZE ; - /* Stack is not here really. It will be put at the end of DMEM. - But we take into account its size here, in order to allow - for MEMORY overflow checking during link time. */ - . += __STACK_SIZE ; - } > dmem - /* Stabs debugging sections. */ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - .note.gnu.build-id : { *(.note.gnu.build-id) } - /* DWARF debug sections. - Symbols in the DWARF debugging sections are relative to the beginning - of the section so we begin them at 0. */ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) } - .debug_frame 0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } - /* DWARF 3 */ - .debug_pubtypes 0 : { *(.debug_pubtypes) } - .debug_ranges 0 : { *(.debug_ranges) } - /* DWARF Extension. */ - .debug_macro 0 : { *(.debug_macro) } - .debug_addr 0 : { *(.debug_addr) } -} - - -- 2.31.1
0001-pru-Enable-ffunction-sections-and-fdata-sections.patch
(text/x-patch, 938 B)
From 5f831e406cf6ba9ee0b48e56bf30d2281c1e32a4 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov <[email protected]> Date: Sun, 9 May 2021 16:11:36 +0300 Subject: [PATCH] pru: Enable -ffunction-sections and -fdata-sections Recent binutils support --gc-sections for pru, so let's make use of them. Signed-off-by: Dimitar Dimitrov <[email protected]> --- newlib/configure.host | 1 + 1 file changed, 1 insertion(+) diff --git a/newlib/configure.host b/newlib/configure.host index 38fec0597..4ac53342a 100644 --- a/newlib/configure.host +++ b/newlib/configure.host @@ -303,6 +303,7 @@ case "${host_cpu}" in newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED" newlib_cflags="${newlib_cflags} -DNO_EXEC" newlib_cflags="${newlib_cflags} -DSMALL_MEMORY" + newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections " default_newlib_nano_malloc="yes" default_newlib_atexit_dynamic_alloc="no" machine_dir=pru -- 2.31.1