Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 892766 - sys-libs/newlib-4.3.0.20230120 and -9999, econf missing some entries due to using ${myconf} instead of "${myconf[@]}"
Summary: sys-libs/newlib-4.3.0.20230120 and -9999, econf missing some entries due to u...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Cross compilation support
URL: https://gitlab.com/gemarcano/newlib-4...
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2023-01-31 21:54 UTC by Gabriel Marcano
Modified: 2023-03-09 01:03 UTC (History)
5 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
newlib-ebuild-fix-myconf.patch (newlib-4.3.0.20230120.ebuild.patch,527 bytes, patch)
2023-03-09 00:52 UTC, Gabriel Marcano
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriel Marcano 2023-01-31 21:54:35 UTC
Using crossdev-generated cross-arm-none-eabi/newlib-4.3.0.20230120, with some
additions to /etc/portage/env/cross-arm-none-eabi/gcc.conf:
    EXTRA_ECONF="--with-multilib-list=rmprofile
        --with-native-system-header-dir=/include"

and /etc/portage/env/cross-arm-none-eabi/newlib.conf:
    EXTRA_ECONF="--with-multilib-list=rmprofile"
    CFLAGS='${CFLAGS} -fno-lto'
    CXXFLAGS='${CXXFLAGS} -fno-lto'

Most of my Gentoo system is built with LTO, but I've made sure that newlib
does not build with LTO.

I tried building an older project of mine for an STM32 board, and ran into:

    arm-none-eabi-g++  -o main.elf main.elf.p/src_main.cpp.o 
        main.elf.p/src_usb_descriptors.c.o main.elf.p/src_freertos_hook.c.o
        main.elf.p/src_snes_controller.cpp.o -lnosys -flto -Wl,--as-needed
        -Wl,--no-undefined -mcpu=cortex-m0plus -Wl,--start-group libtinyusb.a
        --specs=nano.specs --specs=nosys.specs -nostartfiles
        -T/mnt/Luna/home/gabriel/Projects/stm32_snes_controller/linker.ld
        -Wl,-Map,/mnt/Luna/home/gabriel/Projects/stm32_snes_controller/build/output.map
        /home/gabriel/.local/stm32l052k8/lib/libcmsis5.a
        /home/gabriel/.local/stm32l052k8/lib/libstart.a
        /home/gabriel/.local/stm32l052k8/lib/libstm32l052_hal.a
        /home/gabriel/.local/stm32l052k8/lib/libfreertos.a -Wl,--end-group
    /usr/libexec/gcc/arm-none-eabi/ld: 
        /usr/lib/gcc/arm-none-eabi/12/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc_nano.a(libc_a-syscalls.o):
        in function `_open':
    syscalls.c:(.text._open+0x0): multiple definition of `_open'; 
        main.elf.p/src_main.cpp.o (symbol from plugin):(.text+0x0): first defined
        here
    /usr/libexec/gcc/arm-none-eabi/ld: 
        /usr/lib/gcc/arm-none-eabi/12/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc_nano.a(libc_a-syscalls.o):
        in function `_close':
    syscalls.c:(.text._close+0x0): multiple definition of `_close'; 
        main.elf.p/src_main.cpp.o (symbol from plugin):(.text+0x0): first defined
        here
    /usr/libexec/gcc/arm-none-eabi/ld: main.elf section `.rodata' will not fit 
        in region `FLASH'
    /usr/libexec/gcc/arm-none-eabi/ld: region `FLASH' overflowed by 2132 bytes
    collect2: error: ld returned 1 exit status
  
I was able to reduce the required code to reproduce, and I'm linking it as the URL
for this bug report.

I reverted to cross-arm-none-eabi/newlib-4.2.0.20211231 and I no longer get the 
multiple definition errors of `_open` and `_close`.

I suspect this may be a new Newlib bug, and not a crossdev one, but I'm not 
100% sure. Specifically, I am unable to figure out in Newlib how `_open` and
`_close` are handled, because while I thought they were supposed to be weak
symbols, I can't find anywhere in newlib where they're defined as such. The
closest I can find is in `libgloss/arm/syscalls.c` and neither is defined as
weak-- and from dissassembling the generated libc_nano.a archives, I can
confirm that the _open and _close definitions being pulled to cause the clash
are the ones defined in `libgloss/arm/syscalls.c`.

I did experiment with the `--specs=` entries, and it appears to be that the 
problem may be some interplay between `--specs=nano.specs` and
`--specs=nosys.specs`. In the past, having both there worked fine, but with
newlib-4.3 it looks like `nano.specs` is pulling in the additional definitions.
If I remove `--specs=nano.specs`, and leave `--specs=nosys.specs`, I no longer
get the multiple definitions error (the binary is just much, much bigger).

My understanding of how this is supposed to work is that by using
`--specs=nosys.specs` should somehow make it such that all syscalls are
stubbed, but something must have changed between
`cross-arm-none-eabi/newlib-4.2.0.20211231` and
`cross-arm-none-eabi/newlib-4.3.0.20230120` in how this is handled.

I've confirmed on my end that my example repository builds on newlib-4.2, but
fails on newlib-4.3.

Reproducible: Always

Steps to Reproduce:
1. create arm-none-eabi cross compiler using crossdev
2. ensure cross-arm-none-eabi/newlib-4.3.0.20230120 was installed
3. git clone https://gitlab.com/gemarcano/newlib-4.3-open-bug.git
4. cd newlib-4.3-open-bug
5. make
Actual Results:  
$ make
arm-none-eabi-gcc main.c -o main --specs=nano.specs --specs=nosys.specs
/usr/libexec/gcc/arm-none-eabi/ld: /usr/lib/gcc/arm-none-eabi/12/../../../../arm-none-eabi/lib/libc_nano.a(libc_a-syscalls.o): in function `_open':
syscalls.c:(.text._open+0x0): multiple definition of `_open'; /tmp/ccCsqcnM.o:main.c:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:6: main] Error 1

Expected Results:  
$ make
arm-none-eabi-gcc main.c -o main --specs=nano.specs --specs=nosys.specs
$ # in other words, it succeeds

# emerge --info cross-arm-none-eabi/newlib
Portage 3.0.44 (python 3.10.9-final-0, default/linux/amd64/17.1/desktop/plasma/systemd/merged-usr, gcc-12, glibc-2.36-r7, 6.1.7-gentoo x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-6.1.7-gentoo-x86_64-AMD_Ryzen_9_4900H_with_Radeon_Graphics-with-glibc2.36
KiB Mem:    15725220 total,   5104676 free
KiB Swap:   16776188 total,  16776188 free
Timestamp of repository gentoo: Tue, 31 Jan 2023 17:16:59 +0000
Head commit of repository gentoo: 001728121ad53080269f5cbb6e45ea260dd3bd8f

sh bash 5.2_p15-r1
ld GNU ld (Gentoo 2.40 p1) 2.40
app-misc/pax-utils:        1.3.7::gentoo
app-shells/bash:           5.2_p15-r1::gentoo
dev-java/java-config:      2.3.1::gentoo
dev-lang/perl:             5.36.0-r2::gentoo
dev-lang/python:           3.10.9-r1::gentoo, 3.11.1-r1::gentoo
dev-lang/rust:             1.66.1::gentoo
dev-util/cmake:            3.25.2::gentoo
dev-util/meson:            1.0.0::gentoo
sys-apps/baselayout:       2.13-r1::gentoo
sys-apps/sandbox:          2.30-r1::gentoo
sys-apps/systemd:          252.5::gentoo
sys-devel/autoconf:        2.13-r7::gentoo, 2.71-r5::gentoo
sys-devel/automake:        1.16.5::gentoo
sys-devel/binutils:        2.40::gentoo
sys-devel/binutils-config: 5.5::gentoo
sys-devel/clang:           14.0.6-r1::gentoo, 15.0.7-r1::gentoo
sys-devel/gcc:             12.2.1_p20230121-r1::gentoo
sys-devel/gcc-config:      2.10::gentoo
sys-devel/libtool:         2.4.7-r1::gentoo
sys-devel/lld:             15.0.7::gentoo
sys-devel/llvm:            14.0.6-r2::gentoo, 15.0.7::gentoo
sys-devel/make:            4.4::gentoo
sys-kernel/linux-headers:  6.1::gentoo (virtual/os-headers)
sys-libs/glibc:            2.36-r7::gentoo
Repositories:

gentoo
    location: /var/db/repos/gentoo
    sync-type: git
    sync-uri: git://github.com/gentoo-mirror/gentoo
    priority: -1000
    volatile: True
    sync-git-verify-commit-signature: true

local
    location: /var/db/repos/local
    masters: gentoo
    volatile: True

crossdev
    location: /var/db/repos/crossdev
    masters: gentoo
    priority: 10
    volatile: True

brother-overlay
    location: /var/lib/layman/brother-overlay
    sync-type: laymansync
    sync-uri: https://github.com/stefan-langenmaier/brother-overlay.git
    masters: gentoo
    priority: 50
    volatile: True

guru
    location: /var/lib/layman/guru
    sync-type: laymansync
    sync-uri: https://anongit.gentoo.org/git/repo/proj/guru.git
    masters: gentoo
    priority: 50
    volatile: True

ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="@FREE"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=native -O3 -pipe -fomit-frame-pointer -flto"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /opt/brother/scanner/brscan4/brsanenetdevice4.cfg /usr/lib64/libreoffice/program/sofficerc /usr/share/config /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-march=native -O3 -pipe -fomit-frame-pointer -flto"
DISTDIR="/var/cache/distfiles"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GDK_PIXBUF_MODULE_FILE GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR XDG_STATE_HOME"
FCFLAGS="-march=native -O3 -pipe -fomit-frame-pointer -flto"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg-live config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-march=native -O3 -pipe -fomit-frame-pointer -flto"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LEX="flex"
MAKEOPTS="-j18"
PKGDIR="/var/cache/binpkgs"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/tmp"
SHELL="/bin/bash"
USE="X a52 aac acl acpi activities alsa amd64 avahi bluetooth branding bzip2 cairo cdda cdr cli crypt cups dbus declarative dri dts dvd dvdr encode exif flac fortran gdbm gif gpm gtk gui iconv icu ipv6 jpeg kde kwallet lcms libglvnd libnotify libtirpc lm-sensors mad mdns mng mp3 mp4 mpeg mtp multilib ncurses nls nptl ogg opengl openmp pam pango pcre pdf plasma png policykit ppds pulseaudio qml qt5 readline screencast sdl seccomp semantic-desktop sound spell ssl startup-notification svg systemd test-rust tiff truetype udev udisks unicode upower usb vorbis vulkan wayland widgets wxwidgets x264 xattr xcb xft xml xv xvid zeroconf zlib" ABI_X86="64" ADA_TARGET="gnat_2021" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="mmx mmxext sse sse2 aes avx avx2 f16c fma3 pclmul popcnt rdrand sha sse3 sse4_1 sse4_2 sse4a ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput evdev synaptics" KERNEL="linux" L10N="en en-US en_US es es-US es_US" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-4 php8-0" POSTGRES_TARGETS="postgres12 postgres13" PYTHON_SINGLE_TARGET="python3_10" PYTHON_TARGETS="python3_10" RUBY_TARGETS="ruby27 ruby30" USERLAND="GNU" VIDEO_CARDS="amdgpu radeon radeonsi" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq proto steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  ADDR2LINE, AR, ARFLAGS, AS, ASFLAGS, CC, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EMERGE_DEFAULT_OPTS, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LD, LFLAGS, LIBTOOL, LINGUAS, MAKE, MAKEFLAGS, NM, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, RANLIB, READELF, RUSTFLAGS, SIZE, STRINGS, STRIP, YACC, YFLAGS

=================================================================
                        Package Settings
=================================================================

cross-arm-none-eabi/newlib-4.3.0.20230120::crossdev was built with the following:
USE="nano nls unicode -headers-only -threads" ABI_X86="(64)"
CFLAGS="-O3 -pipe -fomit-frame-pointer -flto -fno-lto -fno-lto"
CXXFLAGS="-O3 -pipe -fomit-frame-pointer -flto -fno-lto -fno-lto"
LDFLAGS=""
Comment 1 Gabriel Marcano 2023-03-08 10:09:04 UTC
I'm taking another look at this, to see if I can figure out what's going wrong. From looking at the newlib ebuild, and the build logs, it looks like something is going wrong with the nano portion of the build. Looking at the object files being pulled in to generate libc.a, for the non-nano build there's no libc_a-syscalls.o object, yet for the newlib build that object file is being pulled in.

My current guess is that one of the many additional flags being passed when building newlib nano is triggering a bug in the newlib build system (they refactored a lot of the build stuff from 4.2 to 4.3 from what I can tell). From the ebuild:

    # Build newlib-nano beside newlib (original)
    # Based on https://tracker.debian.org/media/packages/n/newlib/rules-2.1.0%2Bgit20140818.1a8323b-2
    if use nano ; then
        mkdir -p "${NEWLIBNANOBUILD}" || die
        cd "${NEWLIBNANOBUILD}" || die
        export "CFLAGS_FOR_TARGET=${CFLAGS_ORIG} ${CFLAGS_NANO}"
        export "CCASFLAGS=${CCASFLAGS_ORIG} ${CFLAGS_NANO}"
        ECONF_SOURCE=${S} \
        econf \
            $(use_enable unicode newlib-mb) \
            $(use_enable nls) \
            --enable-newlib-reent-small \
            --disable-newlib-fvwrite-in-streamio \
            --disable-newlib-fseek-optimization \
            --disable-newlib-wide-orient \
            --enable-newlib-nano-malloc \
            --disable-newlib-unbuf-stream-opt \
            --enable-lite-exit \
            --enable-newlib-global-atexit \
            --enable-newlib-nano-formatted-io \
            ${myconf}
    fi

When I get a second, I may try re-building nano a bunch of times, just removing one line at a time from the econf set of arguments... I might also try taking a look at the build system, and try to see what variables are being manipulated by these flags...
Comment 2 Gabriel Marcano 2023-03-09 00:51:34 UTC
Yep, this is a bug with Gentoo's ebuilds for newlib.

Specifically, the flaw is in the second econf invocation in the ebuild. The final line of the second econf is currently:
    ${myconf}

The issue with this is that myconf is an list, and ${myconf} only returns the first element of the list!

The fix is to replace that ${myconf} with ${myconf[@]}, like with the first invocation of econf.

The reason this worked with newlib-4.2. is that the myconf list only consisted of a single element. With newlib-4.3, there are two elements, and the second one is currently being silently dropped.
Comment 3 Gabriel Marcano 2023-03-09 00:52:51 UTC
Created attachment 856873 [details, diff]
newlib-ebuild-fix-myconf.patch

This is the fix for the ebuild-- this actually should be applied to all of the ebuilds for newlib, as they all have the same problem.
Comment 4 Gabriel Marcano 2023-03-09 01:00:04 UTC
I've updated the bug title to describe what the bug actually is.

The reason the bug manifested itself originally as some weird interaction between nano and nosys is that the flags that were being left out of the econf invocation on my system were:
    --disable-newlib-supplied-syscalls --disable-newlib-multithread

Specifically, because --disable-newlib-supplied-syscalls was being accidentally dropped, newlib nano was being built with newlib supplied syscalls, leading to the original issues of _open already being defined.
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-03-09 01:00:24 UTC
excellent spot, thanks, this is why I always use it as an array
Comment 6 Larry the Git Cow gentoo-dev 2023-03-09 01:03:04 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4f45d911ab3fccbf139b004c9576c4cab305de18

commit 4f45d911ab3fccbf139b004c9576c4cab305de18
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2023-03-09 01:02:20 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2023-03-09 01:02:20 +0000

    sys-libs/newlib: fix passing args to econf
    
    Closes: https://bugs.gentoo.org/892766
    Thanks-to: Gabriel Marcano <gabemarcano@yahoo.com>
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-libs/newlib/{newlib-4.1.0-r1.ebuild => newlib-4.1.0-r2.ebuild}    | 4 ++--
 .../{newlib-4.2.0.20211231.ebuild => newlib-4.2.0.20211231-r1.ebuild} | 4 ++--
 .../{newlib-4.3.0.20230120.ebuild => newlib-4.3.0.20230120-r1.ebuild} | 2 +-
 sys-libs/newlib/newlib-9999.ebuild                                    | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)