Re: FILE struct size mismatch

Paul Cercueil <[email protected]> Sat, 04 Apr 2026 23:02:14 +0200
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
I fixed my problem - turns out that we copy a custom <sys/lock.h> file,
but it was copied to the "machine_dir", which was disabled by the
patch. Copying it to the arch-independent <sys/lock.h> in Newlib, the
FILE struct now has a correct size, and my stdio is working.

Sorry for the noise.

Cheers,
-Paul

Le samedi 04 avril 2026 à 17:20 +0200, Paul Cercueil a écrit :
> Hi,
> 
> I am in the process of porting the KallistiOS kernel
> (github.com/KallistiOS/KallistiOS) to the Dreamcast's sound CPU,
> which
> is an ARM7DI (ARMv3).
> 
> Given that this is older than what's supported by Newlib I have to
> patch it like that:
> 
> 
> diff --color -ruN newlib-4.6.0.20260123/newlib/configure.host newlib-
> 4.6.0.20260123-kos/newlib/configure.host
> --- newlib-4.6.0.20260123/newlib/configure.host	2024-02-10
> 09:30:58.772247624 -0600
> +++ newlib-4.6.0.20260123-kos/newlib/configure.host	2024-02-10
> 09:31:16.329331366 -0600
> @@ -130,6 +130,5 @@
>  	machine_dir=arc64
>  	;;
>    arm*)
> -	machine_dir=arm
> -	libm_machine_dir=arm
> +	newlib_cflags="${newlib_cflags} -mcpu=arm7di -
> DREENTRANT_SYSCALLS_PROVIDED -DMALLOC_PROVIDED -DABORT_PROVIDED -
> DHAVE_FCNTL -ffunction-sections -fdata-sections"
>  	;;
> 
> 
> Note that the "newlib_cflags" are the same as for our SH4 build apart
> from the "-mcpu=arm7di" so you can ignore these. The thing I wanted
> to
> point out here is that I unset the "machine_dir" and
> "libm_machine_dir"
> variables so that no ASM is compiled (as these require ARMv4
> minimum).
> 
> Newlib is configured like this:
>   ./configure \
>     --disable-newlib-supplied-syscalls \
>     --target=arm-eabi \
>     --prefix=/home/paul/dev/toolchains/arm-eabi-8.5.0 \
>     --with-arch=armv4 --with-mode=arm --disable-multilib \
>     --enable-newlib-io-c99-formats \
>     CC_FOR_TARGET="arm-eabi-gcc"
> 
> This builds fine, and most of the libc functions (memcpy etc) seem to
> work fine.
> 
> However I don't have stdio working.
> 
> This works (prints to my debug output):
> write(STDOUT_FILENO, "Hello\n", 6);
> 
> This does not work:
> printf("Hello\n")
> 
> Disabling buffering on stdout does not fix the problem.
> 
> When debugging this, I noticed that the "__sf" array (which contain
> the
> stdin/stdout/stderr FILE objects) is 312 bytes, so 104 bytes per FILE
> (which matches what I computed by hand). However, if I create a small
> program that just includes <stdio.h>, then sizeof(FILE) is 112 bytes
> for some reason.
> 
> Consequently, if I print ((uintptr_t)stdout->_write) in my small
> program, to get the address of the function that's set there, I see
> that it points to __sclose()... (Which is probably just because the
> FILE struct is defined differently).
> 
> I can't help but think that this FILE struct size mismatch is related
> to my stdio not working (e.g. if a part of Newlib uses the 104-byte
> sized struct while other parts use the 112-byte sized struct).
> 
> Thoughts very much appreciated!
> 
> Cheers,
> -Paul