Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Aug 2000 02:09:16 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        bbec@capgemini.fr (Bruno BEC)
Cc:        freebsd-platforms@FreeBSD.ORG (freeBSD platforms)
Subject:   Re: FreeBSD and ANSI compiler
Message-ID:  <200008190209.TAA01146@usr08.primenet.com>
In-Reply-To: <399D2C24.CFABF66@capgemini.fr> from "Bruno BEC" at Aug 18, 2000 02:29:24 PM

next in thread | previous in thread | raw e-mail | index | archive | help
> In order to have better performances on a new platform we intend to
> compile FreeBSD with a specific ANSI-C compliant compiler instead of
> gcc.
> We made the same experience with the Linux Kernel and had bad surprises
> due to significant non ANSI code souce (this code is not rejected by gcc
> 
> which is not fully ANSI-C).
> 
> Did one of you have any experience or information about the ANSI
> compliance of the FreeBSD kernel ?


Here's what I ran into trying to use TenDRA, the several times
I tried it...

FreeBSD uses:

o	inline assembly functions (obvious reasons)

		__asm__(".weak alias");

o	linker sets (a cheat to make the linker create a list of
	structs from individual structs in a bunch of object
	files.  This lets you decide at link time, rather than at
	compile time, whether or not you will include a module
	in a list of modules, in which a particular module is
	dereferenced through a pointer in a struct.  This is an
	overload of the C++ virtual base class initialization
	functions, which use linker sets to aggregate the
	constructors to get them callled at runtime.

	#ifdef __alpha__
	#define MAKE_SET(set, sym)                                      \
	static void const * const __set_##set##_sym_##sym = &sym;       \
	__asm(".align 3");                                              \
	__asm(".section .set." #set ",\"aw\"");                         \
	__asm(".quad " #sym);                                           \
	__asm(".previous")
	#else
	#define MAKE_SET(set, sym)                                      \
	static void const * const __set_##set##_sym_##sym = &sym;       \
	__asm(".section .set." #set ",\"aw\"");                         \
	__asm(".long " #sym);                                           \
	__asm(".previous")
	#endif

o	variant array indices (one place that I remember, which may
	have already been fixed; this sort of thing is really pretty
	inexcusable).

	foo( int i)
	{
		char array[ i];
		...
	}

o	#pragma pack (this is for strucutre packing for byte
	alignment in structures; some compilers like to be
	"efficient" for access, which make them impossible to
	use to directly map structures to hardware memory mapped
	data; this forces them to pack on particular byte
	boundaries).

	#pragma pack(1)

	struct dohickey {
		unsigned int	abyte:8;
		unsigned int	aword:16;
		unsigned int	abyte:8;
		...
	};

o	K&R style declatations for functions, with prototypes of
	whatever the compiler prefers (e.g. tests for ANSI and C++
	and uses them if the answer is yes).

	void fee( int i, char c);

	void
	fee( i, c)
	int	i;
	char	c;
	{
		...
	}

o	Some newer code uses ANSI prototypes on function declarations
	(this means that if you have a compiler that likes strictly
	one mode or the other, or you have a K&R compiler, you are
	pretty much screwed.

	void fum( int i, char c);

	void
	fum( int i, char c)
	{
		...
	}

Other than that; it's pretty clean, as these things go.  It would be
nice if someone would comb out the remaining rats, like the ANSI C
prototypes in functions, the inline assembly, and the variant array
indices.  Linker sets would require an object post-processor that
created a data-only onlject from input object files that had the
data stored as text with magic bytes (e.g. like how the "what"
command works on extracting ids).  The inline assembly would be
hard to remove entirely, but it should perhaps be isolated in
seperate platform dependent source files and/or include files, to
allow a variant inline vs. external assembly file usage.  At the
very least, C versions of everything for which C versions are at
all possible, should be provided.  I think the variant array
indices, if they exist, really need to go: they are so GNU
dependant that they have no hope.

Hope this helps...



					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.


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




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