[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-audit
Subject:    Re: lib/csu cleanup
From:       Bruce Evans <bde () zeta ! org ! au>
Date:       2002-01-18 6:19:45
[Download RAW message or body]

On Thu, 17 Jan 2002, Mark Murray wrote:

> 1) I've wrapped some _horrible_ assembler in #ifndef lint/#endif.
>    What is a better way (if any)? #ifndef __STDC__ does not cut it

Wrap it in __GNUC__ (it is gcc-specific), and unbreak lint so that it
doesn't define __GNUC__.

>    as GCC's preprocessor defines that for lint. I have a half-baked
>    idea for COMPILING and LINTING macros, but I'm sure there is
>    a better way. Mebbe its just using 'lint'?
>
> 2) Where can _start() be prototyped? Where is is used?

Before itself.  ld(1).

> Index: alpha/crt1.c
> ===================================================================
> RCS file: /home/ncvs/src/lib/csu/alpha/crt1.c,v
> retrieving revision 1.10
> diff -u -d -r1.10 crt1.c
> --- alpha/crt1.c	26 Oct 2001 06:45:10 -0000	1.10
> +++ alpha/crt1.c	17 Jan 2002 21:11:52 -0000
> ...
> @@ -72,13 +72,20 @@
>  	int argc;
>  	char **argv;
>  	char **env;
> +	const char *s;
> +	union {
> +		char **a;
> +		long *b;
> +	} xlat;	/* Looks horrible, but is a convincing way
> +		 * to translate different pointer types
> +		 */

s/Looks horrible/Is horrible/
It just breaks lint's detection of unportabilities.

Block comments are not formatted like this in KNF.

> ...
> @@ -108,7 +115,5 @@
>  /*
>   * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
>   */
> -#ifndef lint
> -static const char rcsid[] =
> -  "$FreeBSD: src/lib/csu/alpha/crt1.c,v 1.10 2001/10/26 06:45:10 obrien Exp $";
> -#endif
> +
> +__FBSDID("$FreeBSD: src/lib/csu/alpha/crt1.c,v 1.10 2001/10/26 06:45:10 obrien Exp $");

The comment has rotted:
old bitrot: __start() doesn't exist.
new bitrot: _FBSDID() never puts the ID in .text for elf (check this).

New style bug: blank line separates the comment from the code.

> Index: i386-elf/crt1.c
> ===================================================================
> RCS file: /home/ncvs/src/lib/csu/i386-elf/crt1.c,v
> retrieving revision 1.5
> diff -u -d -r1.5 crt1.c
> --- i386-elf/crt1.c	28 Oct 2000 21:26:48 -0000	1.5
> +++ i386-elf/crt1.c	17 Jan 2002 21:18:03 -0000
> @@ -21,14 +21,13 @@
>   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
>   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
>   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> - *
> - * $FreeBSD: src/lib/csu/i386-elf/crt1.c,v 1.5 2000/10/28 21:26:48 obrien Exp $
>   */
>
>  #ifndef __GNUC__
>  #error "GCC is needed to compile this file"
>  #endif
>
> +#include <sys/cdefs.h>

Style bug.  Including <sys/cdefs.h> explicitly is a necessary evil if
__FBSDID() is placed before other includes, but is not needed here.

>  #include <stddef.h>
>  #include <stdlib.h>
>  #include "crtbrand.c"
> @@ -50,16 +49,20 @@
>  #pragma weak _DYNAMIC
>
>  #ifdef __i386__
> +#ifndef lint
>  #define get_rtld_cleanup()				\
>      ({ fptr __value;					\
>         __asm__("movl %%edx,%0" : "=rm"(__value));	\
>         __value; })
>  #else
> +#define get_rtld_cleanup()	0
> +#endif
> +#else
>  #error "This file only supports the i386 architecture"
>  #endif

See above.  Also, lint failures when the function declared in asm doesn't
exist (because it is hidden by __GNUC__) are correct.  Linting this file
should have failed already with the #error for the !__GNUC__ case.

> ...
> @@ -68,21 +71,27 @@
>      int argc;
>      char **argv;
>      char **env;
> +    const char *s;
> +    union {
> +	char **a;
> +	int *b;
> +    } xlat;	/* Looks horrible, but is a convincing way
> +		 * to translate different pointer types
> +		 */

As above.
> @@ -101,3 +110,9 @@
>  __asm__("eprol:");
>  __asm__(".previous");
>  #endif
> +
> +/*
> + * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
> + */
> +
> +__FBSDID("$FreeBSD: src/lib/csu/i386-elf/crt1.c,v 1.5 2000/10/28 21:26:48 obrien Exp $");

As above, except the comment was born broken.

Bruce


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic