public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Tobias Burnus <tobias@codesourcery.com>
To: <newlib@sourceware.org>
Subject: Build-dependency issues with ELIX_LEVEL
Date: Tue, 29 Mar 2022 11:14:09 +0200	[thread overview]
Message-ID: <0e04b11a-1b6d-c70a-c0fe-4ece59996461@codesourcery.com> (raw)

Hello,

there is an issue with ELIX_LEVEL and dependencies.

Namely, files compiled for a given ELIX_LEVEL (here: 1)
still call functions which are only available in a higher
ELIX_LEVEL.

Expected: Either those files are also build - or the function
is not called (#ifdef or also removing the other file from
the ELIX_LEVEL).

The issue seems to be old - but popped up for nvptx (link
error when using 'fprintf), but I think it should be addressed
in general.

  * * *

The original issue (missing '_fputwc_r' symbol) did show up with nvptx, which uses
   #define _ELIX_LEVEL 1
   #define _WIDE_ORIENT 1
   #undef _NANO_FORMATTED_IO

The problem is:
    newlib/libc/stdio/vfprintf.c (and newlib/libc/stdio/nano-vfprintf.c )

that are compiled via newlib/Makefile.in as
   @HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_TRUE@    libc/stdio/nano-vfprintf_float.c \
   @HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@   libc/stdio/vfprintf.c \

both files have
  #ifdef _WIDE_ORIENT
  ...
                 if (_fputwc_r (ptr, p[i], fp) == WEOF)

But _fputwc_r is only available via:
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@@HAVE_STDIO_DIR_TRUE@       libc/stdio/fputwc.c \


I have not studied the ELIX_LEVEL documentation in depth, but I think the following
is the proper solution (tested with nvptx, i.e. only the non-nano version):

--------------------------------------
newlib: Only call _fputwc_r if ELIX_LEVEL >= 3

--- a/newlib/libc/stdio/nano-vfprintf.c
+++ b/newlib/libc/stdio/nano-vfprintf.c
@@ -359 +359 @@ __sprint_r (struct _reent *ptr,
-#ifdef _WIDE_ORIENT
+#if defined _WIDE_ORIENT && (!defined _ELIX_LEVEL || _ELIX_LEVEL >= 3)
@@ -410 +410 @@ __sfputs_r (struct _reent *ptr,
-#ifdef _WIDE_ORIENT
+#if defined _WIDE_ORIENT && (!defined _ELIX_LEVEL || _ELIX_LEVEL >= 3)

--- a/newlib/libc/stdio/vfprintf.c
+++ b/newlib/libc/stdio/vfprintf.c
@@ -373 +373 @@ __sfputs_r (struct _reent *ptr,
-#ifdef _WIDE_ORIENT
+#if defined _WIDE_ORIENT && (!defined _ELIX_LEVEL || _ELIX_LEVEL >= 3)
@@ -409 +409 @@ __sprint_r (struct _reent *ptr,
-#ifdef _WIDE_ORIENT
+#if defined _WIDE_ORIENT && (!defined _ELIX_LEVEL || _ELIX_LEVEL >= 3)
--------------------------------------

  * * *

Looking closer at the generated files, there are also more issues
(see bottom for a list). Analyzing another one:

./newlib/libc/stdio/vdiprintf.c
   calls newlib/libc/stdio/vfiprintf.c's
      _vfiprintf_r
   which calls libc/stdio/vasniprintf.c's (or, '#ifdef _NANO_FORMATTED_IO', libc/stdio/vasnprintf.c's)
      _vasniprintf_r
which then calls libc/stdio/nano-vfprintf.c's
      _svfiprintf_r

However, while
   @HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@   libc/stdio/vdiprintf.c \
and likewise _svfiprintf_r, the vasniprintf.c is missing for NANO and for
non-NANO it is only enabled for ELIX_LEVEL 4. Untested fix:

------------------------------------------
--- a/newlib/libc/stdio/Makefile.inc
+++ b/newlib/libc/stdio/Makefile.inc
@@ -9,2 +9,3 @@ libc_a_SOURCES += \
        %D%/nano-vfprintf_i.c \
+       %D%/nano-vasniprintf.c \
        %D%/nano-vfscanf.c \
@@ -26,2 +27,3 @@ libc_a_SOURCES += \
        %D%/vdiprintf.c \
+       %D%/vasnprintf.c \
        %D%/vfprintf.c \
@@ -184,3 +186,2 @@ else
        %D%/ungetwc.c \
-       %D%/vasnprintf.c \
        %D%/vswprintf.c \
------------------------------------------

Thoughts?

Tobias

PS: The full list of symbols called - but not provided in libc
(compiled for nvptx) is the following. Note: I might have misgreped
and I have only had a closer look at _fputwc_r and _vasniprintf_r.

=== __ffsdi2 ==
string/libc_a-ffsl.o
string/libc_a-ffsll.o
=== __hash_open ==
search/libc_a-ndbm.o
=== _fgetwc_r ==
stdio/libc_a-vfiwscanf.o
stdio/libc_a-vfwscanf.o
=== _fputwc_r ==
stdio/libc_a-vfiprintf.o
=== _fseeko_r ==
stdio/libc_a-fseek.o
=== _ftello_r ==
stdio/libc_a-ftell.o
=== _memalign_r ==
stdlib/libc_a-aligned_alloc.o
=== _ungetwc_r ==
stdio/libc_a-vfiwscanf.o
stdio/libc_a-vfwscanf.o
=== _vasniprintf_r ==
stdio/libc_a-vdiprintf.o
=== _vasnprintf_r ==
stdio/libc_a-vdprintf.o
=== _wcrtomb_r ==
stdio/libc_a-svfiwscanf.o
stdio/libc_a-svfwscanf.o
stdio/libc_a-vfiwscanf.o
stdio/libc_a-vfwscanf.o
=== _wcsnrtombs_l ==
stdlib/libc_a-wcstod.o
=== btowc ==
locale/libc_a-locale.o
stdio/libc_a-vfiwprintf.o
stdio/libc_a-svfwprintf.o
stdio/libc_a-vfwprintf.o
stdio/libc_a-svfiwprintf.o
=== fcntl ==
reent/libc_a-fcntlr.o
=== getentropy ==
stdlib/libc_a-arc4random.o
=== getpid; ==
reent/libc_a-signalr.o
=== gettimeofday ==
reent/libc_a-gettimeofdayr.o
time/libc_a-time.o
=== iswcntrl ==
string/libc_a-wcwidth.o
=== iswprint ==
string/libc_a-wcwidth.o
=== iswspace ==
stdio/libc_a-svfiwscanf.o
stdio/libc_a-svfwscanf.o
stdio/libc_a-vfiwscanf.o
stdio/libc_a-vfwscanf.o
stdlib/libc_a-wcstod.o
stdlib/libc_a-wcstoul.o
stdlib/libc_a-wcstoll.o
stdlib/libc_a-wcstoimax.o
stdlib/libc_a-wcstol.o
stdlib/libc_a-wcstoumax.o
stdlib/libc_a-wcstoull.o
=== iswspace_l ==
stdlib/libc_a-wcstod.o
stdlib/libc_a-wcstoul.o
stdlib/libc_a-wcstoll.o
stdlib/libc_a-wcstoimax.o
stdlib/libc_a-wcstol.o
stdlib/libc_a-wcstoumax.o
stdlib/libc_a-wcstoull.o
=== kill ==
reent/libc_a-signalr.o
signal/libc_a-signal.o
=== link ==
reent/libc_a-linkr.o
reent/libc_a-unlinkr.o
reent/libc_a-renamer.o
reent/libc_a-renamer.o
stdio/libc_a-remove.o
=== malloc ==
machine/nvptx/libc_a-mallocr.o
machine/nvptx/libc_a-realloc.o
machine/nvptx/libc_a-calloc.o
machine/nvptx/libc_a-malloc.o
signal/libc_a-signal.o
stdio/libc_a-svfiprintf.o
stdio/libc_a-setvbuf.o
stdio/libc_a-tmpnam.o
stdio/libc_a-vfiwprintf.o
stdio/libc_a-svfwprintf.o
stdio/libc_a-makebuf.o
stdio/libc_a-svfprintf.o
stdio/libc_a-findfp.o
stdio/libc_a-vfwprintf.o
stdio/libc_a-ungetc.o
stdio/libc_a-svfiwprintf.o
stdio/libc_a-fvwrite.o
stdlib/libc_a-quick_exit.o
stdlib/libc_a-__atexit.o
stdlib/libc_a-wcstod.o
string/libc_a-strdup_r.o
time/libc_a-tzset_r.o
=== memmem ==
string/libc_a-strnstr.o
=== mkdir ==
reent/libc_a-mkdirr.o
=== sbrk ==
reent/libc_a-sbrkr.o
=== stat ==
reent/libc_a-statr.o
reent/libc_a-fstatr.o
stdio/libc_a-makebuf.o
=== strncasecmp_l ==
time/libc_a-strptime.o
=== swprintf ==
stdio/libc_a-svfwscanf.o
stdio/libc_a-vfwscanf.o
time/libc_a-wcsftime.o
=== times ==
reent/libc_a-timesr.o
=== towlower ==
time/libc_a-wcsftime.o
=== wcrtomb ==
stdio/libc_a-svfiwscanf.o
stdio/libc_a-svfiwscanf.o
stdio/libc_a-svfwscanf.o
stdio/libc_a-svfwscanf.o
stdio/libc_a-vfiwscanf.o
stdio/libc_a-vfiwscanf.o
stdio/libc_a-vfwscanf.o
stdio/libc_a-vfwscanf.o

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

             reply	other threads:[~2022-03-29  9:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29  9:14 Tobias Burnus [this message]
2022-03-30  9:43 ` [Patch] (1/n) newlib: Only call _fputwc_r if ELIX_LEVEL >= 4 (was: Build-dependency issues with ELIX_LEVEL) Tobias Burnus
2022-03-30 20:02   ` Jeff Johnston
2022-03-30 10:56 ` [Patch] (2/n) newlib: Move vasniprintf.c to ELIX 1 " Tobias Burnus
2022-04-06  5:11   ` *ping* " Tobias Burnus
2022-04-06 16:25     ` Jeff Johnston

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0e04b11a-1b6d-c70a-c0fe-4ece59996461@codesourcery.com \
    --to=tobias@codesourcery.com \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).