mirror of
https://github.com/apache/nuttx.git
synced 2025-12-10 04:04:18 +08:00
arch/avr: reworked eliminating unused sections with GCC
After a mailing list suggestion, the indirection that enabled ARCH_TOOLCHAIN_GCC only when user requested it is removed. The indirection was a safety measure for chips and boards with linker scripts that (possibly) do not handle keeping for example .vectors section even if the linker considers it unreferenced. Instead, all existing configurations now disable CONFIG_DEBUG_OPT_UNUSED_SECTIONS to prevent the linker from removing any code. (Preserving previous behaviour.) This can be removed again at some point after making sure that corresponding linker script only removes code that is truly unused. Signed-off-by: Kerogit <kr.git@kerogit.eu>
This commit is contained in:
@@ -526,6 +526,11 @@ Common Configuration Notes
|
||||
CONFIG_WINDOWS_CYGWIN=y
|
||||
CONFIG_AVR_BUILDROOT_TOOLCHAIN=y
|
||||
|
||||
4. Build with GCC disables CONFIG_DEBUG_OPT_UNUSED_SECTIONS by default.
|
||||
This is because the linker script was not checked to determine
|
||||
if it properly prevents removal of sections which the linker considers
|
||||
unreferenced but which must be present in the binary.
|
||||
|
||||
Configuration Sub-Directories
|
||||
-----------------------------
|
||||
|
||||
|
||||
@@ -535,6 +535,11 @@ Common Configuration Notes
|
||||
CONFIG_WINDOWS_CYGWIN=y
|
||||
CONFIG_AVR_BUILDROOT_TOOLCHAIN=y
|
||||
|
||||
4. Build with GCC disables CONFIG_DEBUG_OPT_UNUSED_SECTIONS by default.
|
||||
This is because the linker script was not checked to determine
|
||||
if it properly prevents removal of sections which the linker considers
|
||||
unreferenced but which must be present in the binary.
|
||||
|
||||
Configuration Sub-Directories
|
||||
-----------------------------
|
||||
|
||||
|
||||
@@ -506,6 +506,11 @@ Common Configuration Notes
|
||||
CONFIG_WINDOWS_CYGWIN=y
|
||||
CONFIG_AVR_BUILDROOT_TOOLCHAIN=y
|
||||
|
||||
4. Build with GCC disables CONFIG_DEBUG_OPT_UNUSED_SECTIONS by default.
|
||||
This is because the linker script was not checked to determine
|
||||
if it properly prevents removal of sections which the linker considers
|
||||
unreferenced but which must be present in the binary.
|
||||
|
||||
Configuration Sub-Directories
|
||||
-----------------------------
|
||||
|
||||
|
||||
@@ -69,6 +69,11 @@ Configurations
|
||||
CONFIG_WINDOWS_CYGWIN=y
|
||||
CONFIG_AVR_BUILDROOT_TOOLCHAIN=y
|
||||
|
||||
4. Build with GCC disables CONFIG_DEBUG_OPT_UNUSED_SECTIONS by default.
|
||||
This is because the linker script was not checked to determine
|
||||
if it properly prevents removal of sections which the linker considers
|
||||
unreferenced but which must be present in the binary.
|
||||
|
||||
Configuration Sub-Directories
|
||||
-----------------------------
|
||||
hello:
|
||||
|
||||
@@ -46,6 +46,15 @@ nsh
|
||||
|
||||
Basic NuttShell configuration (console enabled in USART0, pins PD0 (RXD0) and PD1 (TXD0), at 115200 bps).
|
||||
|
||||
Compile
|
||||
=======
|
||||
|
||||
Note that build with GCC disables CONFIG_DEBUG_OPT_UNUSED_SECTIONS
|
||||
by default. This is because the linker script was not checked
|
||||
to determine if it properly prevents removal of sections which
|
||||
the linker considers unreferenced but which must be present
|
||||
in the binary.
|
||||
|
||||
Flash & Debug
|
||||
=============
|
||||
|
||||
|
||||
@@ -254,6 +254,11 @@ Common Configuration Notes
|
||||
b. Execute 'make menuconfig' in nuttx/ in order to start the
|
||||
reconfiguration process.
|
||||
|
||||
4. Build with GCC disables CONFIG_DEBUG_OPT_UNUSED_SECTIONS by default.
|
||||
This is because the linker script was not checked to determine
|
||||
if it properly prevents removal of sections which the linker considers
|
||||
unreferenced but which must be present in the binary.
|
||||
|
||||
Configuration Sub-Directories
|
||||
-----------------------------
|
||||
|
||||
|
||||
@@ -37,10 +37,21 @@ config AVR_ATMEL_AVR_TOOLCHAIN
|
||||
config AVR_LINUXGCC_TOOLCHAIN
|
||||
bool "Linux GCC"
|
||||
depends on HOST_LINUX
|
||||
select ARCH_TOOLCHAIN_GCC
|
||||
---help---
|
||||
For Linux, there are widely available avr-gcc packages. On
|
||||
Ubuntu, use: sudo apt-get install gcc-avr gdb-avr avr-libc
|
||||
|
||||
Note that unlike other toolchains, this one is marked
|
||||
with ARCH_TOOLCHAIN_GCC which in turn enables other GCC-
|
||||
and GNU-specific optimizations. One of them is removal
|
||||
of unused code sections by the linker.
|
||||
|
||||
Linker script for the board must take this into account
|
||||
and flag unreferenced sections that need to be present
|
||||
in the compiled binary with a KEEP statement. Most notably,
|
||||
this applies to .vectors section.
|
||||
|
||||
config AVR_CROSSPACK_TOOLCHAIN
|
||||
bool "CrossPack-AVR"
|
||||
depends on HOST_MACOS
|
||||
@@ -57,26 +68,6 @@ config AVR_BUILDROOT_TOOLCHAIN
|
||||
|
||||
endchoice # Toolchain
|
||||
|
||||
config AVR_LINUXGCC_TOOLCHAIN_IS_GCC
|
||||
bool "Mark the toolchain as a GCC toolchain"
|
||||
default n
|
||||
depends on AVR_LINUXGCC_TOOLCHAIN
|
||||
select ARCH_TOOLCHAIN_GCC
|
||||
---help---
|
||||
This option marks the toolchain as a GCC toolchain. Enabling
|
||||
this will in turn enable other configuration option. Among
|
||||
them, there is DEBUG_OPT_UNUSED_SECTIONS which will instruct
|
||||
the compiler and linker to remove unused sections from the final
|
||||
binary, saving flash space.
|
||||
|
||||
There is, however, a catch to this. Linker script for the board
|
||||
in use must mark unreferenced sections as "KEEP". Most notably,
|
||||
this applies to .vectors section which is not referenced anywhere
|
||||
but must be present. If not marked to be kept, the resulting
|
||||
binary will be faulty.
|
||||
|
||||
Consult linker script of your board before enabling this option.
|
||||
|
||||
config AVR_HAS_MEMX_PTR
|
||||
bool "Enable in-flash static const strings"
|
||||
depends on AVR_ATMEL_AVR_TOOLCHAIN || AVR_LINUXGCC_TOOLCHAIN
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_DEBUG_OPT_UNUSED_SECTIONS is not set
|
||||
CONFIG_ARCH="avr"
|
||||
CONFIG_ARCH_AVR=y
|
||||
CONFIG_ARCH_BOARD="micropendous3"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_DEBUG_OPT_UNUSED_SECTIONS is not set
|
||||
CONFIG_ARCH="avr"
|
||||
CONFIG_ARCH_AVR=y
|
||||
CONFIG_ARCH_BOARD="teensy-2.0"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_DEBUG_OPT_UNUSED_SECTIONS is not set
|
||||
# CONFIG_DISABLE_ENVIRON is not set
|
||||
# CONFIG_NSH_DISABLEBG is not set
|
||||
# CONFIG_NSH_DISABLE_IFCONFIG is not set
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_DEBUG_OPT_UNUSED_SECTIONS is not set
|
||||
# CONFIG_SPI_EXCHANGE is not set
|
||||
CONFIG_ARCH="avr"
|
||||
CONFIG_ARCH_AVR=y
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_DEBUG_OPT_UNUSED_SECTIONS is not set
|
||||
CONFIG_ARCH="avr"
|
||||
CONFIG_ARCH_AVR=y
|
||||
CONFIG_ARCH_BOARD="amber"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_DEBUG_OPT_UNUSED_SECTIONS is not set
|
||||
CONFIG_ARCH="avr"
|
||||
CONFIG_ARCH_AVR=y
|
||||
CONFIG_ARCH_BOARD="arduino-mega2560"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_DEBUG_OPT_UNUSED_SECTIONS is not set
|
||||
CONFIG_ARCH="avr"
|
||||
CONFIG_ARCH_AVR=y
|
||||
CONFIG_ARCH_BOARD="arduino-mega2560"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_DEBUG_OPT_UNUSED_SECTIONS is not set
|
||||
CONFIG_ARCH="avr"
|
||||
CONFIG_ARCH_AVR=y
|
||||
CONFIG_ARCH_BOARD="mega1284p-xplained"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_DEBUG_OPT_UNUSED_SECTIONS is not set
|
||||
# CONFIG_DISABLE_ENVIRON is not set
|
||||
# CONFIG_NSH_DISABLEBG is not set
|
||||
# CONFIG_NSH_DISABLE_IFCONFIG is not set
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_DEBUG_OPT_UNUSED_SECTIONS is not set
|
||||
CONFIG_ARCH="avr"
|
||||
CONFIG_ARCH_AVR=y
|
||||
CONFIG_ARCH_BOARD="moteino-mega"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_DEBUG_OPT_UNUSED_SECTIONS is not set
|
||||
# CONFIG_DISABLE_ENVIRON is not set
|
||||
# CONFIG_NSH_DISABLEBG is not set
|
||||
# CONFIG_NSH_DISABLE_IFCONFIG is not set
|
||||
|
||||
Reference in New Issue
Block a user