Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 3 Aug 2017 17:53:43 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Ngie Cooper <ngie@freebsd.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r321969 - in head/sys/boot: arm/at91/libat91 arm/ixp425/boot2 i386/boot2
Message-ID:  <20170803173421.C2203@besplex.bde.org>
In-Reply-To: <201708030527.v735R5dg041043@repo.freebsd.org>
References:  <201708030527.v735R5dg041043@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170803173421.C2203>