svn commit: r321969 - in head/sys/boot: arm/at91/libat91 arm/ixp425/boot2 i386/boot2

Bruce Evans brde at optusnet.com.au
Thu Aug 3 08:24:44 UTC 2017


On Thu, 3 Aug 2017, Ngie Cooper wrote:

> Log:
>  Fix the return types for printf and putchar to match their libc and
>  POSIX equivalents
>
>  Both printf and putchar return int, not void.
>
>  This will allow code that leverages the libcalls and checks/rely on the
>  return type to interchangeably between loader code and non-loader
>  code.
>
>  MFC after:	1 month
>
> Modified:
>  head/sys/boot/arm/at91/libat91/lib.h
>  head/sys/boot/arm/at91/libat91/printf.c
>  head/sys/boot/arm/at91/libat91/putchar.c
>  head/sys/boot/arm/ixp425/boot2/ixp425_board.c
>  head/sys/boot/arm/ixp425/boot2/lib.h
>  head/sys/boot/i386/boot2/boot2.c

This is wrong for at least i386/boot2.  It isn't part of the loader, and
saves space by not returning unused values.

> Modified: head/sys/boot/i386/boot2/boot2.c
> ==============================================================================
> --- head/sys/boot/i386/boot2/boot2.c	Thu Aug  3 03:45:48 2017	(r321968)
> +++ head/sys/boot/i386/boot2/boot2.c	Thu Aug  3 05:27:05 2017	(r321969)
> @@ -114,8 +114,8 @@ void exit(int);
> static void load(void);
> static int parse(void);
> static int dskread(void *, unsigned, unsigned);
> -static void printf(const char *,...);
> -static void putchar(int);
> +static int printf(const char *,...);
> +static int putchar(int);

These are freestanding static functions, so they have nothing to do
with library functions except their name is a hint that they are
similar.

Since they are static, -funit-at-a-time might allow the unused return values
to be optimized away.  Then returning unused values would be just an
obfuscation.

This file still has a static memcpy() which is quite different from the
libc version.  It doesn't return an unused value, and its arg types are
all different (no newfangled size_t or newerfangled restrict).

Freestanding versions (static and otherwise) cause problems with builtins.
-ffreestanding turns off all builtins.  The static memcpy used to be
ifdefed so as to use __builtin_memcpy instead of the static one if the
compiler is gcc.  That apparently broke with gcc-4.2, since the builtin
will call libc memcpy() in some cases, although memcpy() is unavailable
in the freestanding case.

Bruce


More information about the svn-src-all mailing list