foss-for-synopsys-dwc-arc-processors/toolchain

Newlib Nano weighs more than Newlib because of implicit -g

Closed this issue · 4 comments

Consider this sample for Crosstool-NG:

CT_CONFIG_VERSION="3"
CT_EXPERIMENTAL=y
CT_DEBUG_CT=y
CT_DEBUG_CT_SAVE_STEPS=y
CT_ARCH_ARC=y
CT_MULTILIB=y
CT_TARGET_CFLAGS="-O2 -ffunction-sections -fdata-sections"
CT_TARGET_VENDOR="snps"
CT_TARGET_ALIAS="arc-elf32"
CT_BINUTILS_SRC_DEVEL=y
CT_BINUTILS_DEVEL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/binutils-gdb.git"
CT_BINUTILS_DEVEL_BRANCH="arc-2023.03"
CT_NEWLIB_SRC_DEVEL=y
CT_NEWLIB_DEVEL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/newlib.git"
CT_NEWLIB_DEVEL_BRANCH="arc-2023.03"
CT_LIBC_NEWLIB_IO_LL=y
CT_LIBC_NEWLIB_IO_FLOAT=y
CT_LIBC_NEWLIB_GLOBAL_ATEXIT=y
# CT_LIBC_NEWLIB_ENABLE_TARGET_OPTSPACE is not set
CT_GCC_SRC_DEVEL=y
CT_GCC_DEVEL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/gcc.git"
CT_GCC_DEVEL_BRANCH="arc-2023.03"
# CT_CC_GCC_CONFIG_TLS is not set
# CT_CC_GCC_USE_GRAPHITE is not set
# CT_CC_GCC_ENABLE_TARGET_OPTSPACE is not set
CT_CC_LANG_CXX=y
CT_DEBUG_GDB=y
CT_GDB_SRC_DEVEL=y
CT_GDB_DEVEL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/binutils-gdb.git"
CT_GDB_DEVEL_BRANCH="arc-2023.03"
# CT_GDB_CROSS_PYTHON is not set
CT_COMP_LIBS_NEWLIB_NANO=y
CT_NEWLIB_NANO_SRC_DEVEL=y
CT_NEWLIB_NANO_DEVEL_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/newlib.git"
CT_NEWLIB_NANO_DEVEL_BRANCH="arc-2023.03"
CT_LIBC_NEWLIB_NANO_IO_FLOAT=y
# CT_LIBC_NEWLIB_NANO_FVWRITE_IN_STREAMIO is not set
# CT_LIBC_NEWLIB_NANO_ATEXIT_DYNAMIC_ALLOC is not set
# CT_LIBC_NEWLIB_NANO_MULTITHREAD is not set

By default Crosstool-NG enables CT_LIBC_NEWLIB_NANO_ENABLE_TARGET_OPTSPACE for Newlib Nano which leads to using --enable-target-optspace options for configuring of Newlib. Then newlib/config/mt-ospace is used for adding options for target:

# Build libraries optimizing for space, not speed.
CFLAGS_FOR_TARGET += -g -Os
CXXFLAGS_FOR_TARGET += -g -Os

Then Newlib is built with -g which increases library's size significantly. You always can strip debug symbols but such behavior may mislead users because you have 2 sets of Newlib simultaneously in toolchain's tree: one without -g and one with -g (Newlib Nano). If I don't want to build a toolchain with debug symbols I don't expect Newlib to be built with -g.

I see that this -g -Os is intentional for --enable-target-optspace and was taken from GCC. What can be done to deal with it properly?

I would say that it is worth building all the target libs with -g. Or even better if the same set of flags used by all the target libs and binaries, i.e. from CT_TARGET_CFLAGS.

@yaroslavsadin Can we add CT_TARGET_CFLAGS="-g" for all generated samples?

@kolerov Done, pls check the latest eng build

I confirm that standard libraries from the latest engineering build contain debug symbols.