Date: Tue, 11 Jul 2006 18:01:56 +0800 From: mag@intron.ac To: des@des.no Cc: freebsd-hackers@freebsd.org, delphij@delphij.net, Julian Elischer <julian@elischer.org> Subject: Re: kern/99979: Get Ready for Kernel Module in C++ Message-ID: <1152612305.19369@origin.intron.ac> In-Reply-To: <86fyh8zgw8.fsf@xps.des.no> References: <200607092136.k69LaNDX055391@www.freebsd.org> <84dead720607092015q7f1701abse143f3855c2aa95a@mail.gmail.com> <1152540567.99616@origin.intron.ac> <44B2AE69.4080703@elischer.org> <44B2D2DF.2000401@sh.cvut.cz> <86sll8zl9x.fsf@xps.des.no> <courier.44B35DBC.00003F75@intron.ac> <86fyh8zgw8.fsf@xps.des.no>
next in thread | previous in thread | raw e-mail | index | archive | help
Dag-Erling [iso-8859-1] Sm grav wrote: > mag@intron.ac writes: >> But prior to long-term discussion, please commit my 4 patches >> firstly. They are nearly CPP-independent and do no harm to current >> FreeBSD kernel. > > We don't do the kind of changes you propose without discussion. > >> --- kern.mk.orig Fri Jun 30 05:15:25 2006 >> +++ kern.mk Mon Jul 10 18:42:43 2006 >> @@ -88,7 +88,7 @@ >> .if ${CC} == "icc" >> CFLAGS+= -nolib_inline >> .else >> -CFLAGS+= -ffreestanding >> +CFLAGS+= -fno-builtin >> .endif > > Are you sure this is correct? I'm pretty certain it isn't. The > kernel's C environment is not a hosted implementation. GCC manual page gcc(1) says: -ffreestanding Compile for a freestanding environment; this implies the `-fno- builtin' option, and implies that main has no special require- ments. GCC manual says: (http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/C-Dialect-Options.html) -ffreestanding Assert that compilation takes place in a freestanding environment. This implies -fno-builtin. A freestanding environment is one in which the standard library may not exist, and program startup may not necessarily be at main. The most obvious example is an OS kernel. This is equivalent to -fno-hosted. But "-ffreestanding" doesn't work with C++. According to above explanation, "-fno-builtin" is a subset of "-ffreestanding" and it's enough for kernel. In /usr/src/contrib/gcc/c-opts.c, "-ffreestanding" is recognized as: case OPT_ffreestanding: value = !value; /* Fall through.... */ case OPT_fhosted: flag_hosted = value; flag_no_builtin = !value; /* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */ if (!value && warn_main == 2) warn_main = 0; break; In /usr/src/contrib/gcc/c-decl.c, "-ffreestanding" takes effects as: if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted) { if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) != integer_type_node) { /* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned. If warn_main is -1 (-Wno-main) we don't want to be warned. */ if (!warn_main) pedwarn ("%Jreturn type of '%D' is not `int'", fndecl, fndecl); } else { #ifdef DEFAULT_MAIN_RETURN /* Make it so that `main' always returns success by default. */ DEFAULT_MAIN_RETURN; #else if (flag_isoc99) c_expand_return (integer_zero_node); #endif } } >From above code we can conclude that "-ffreestanding" can affect only something about main() more than "-fno-builtin". I have compiled the whole FreeBSD kernel with "-fno-builtin" and met no problems. Now I am running the kernel with "-fno-builtin" to write to you with Linux ABI Mozilla-GTK1 1.7.12 and NVIDIA X11 driver 1.0-8762. > >> --- systm.h.orig Mon Jul 10 05:42:58 2006 >> +++ systm.h Mon Jul 10 18:44:01 2006 >> @@ -203,7 +203,7 @@ >> int suword16(void *base, int word); >> int suword32(void *base, int32_t word); >> int suword64(void *base, int64_t word); >> -intptr_t casuptr(intptr_t *p, intptr_t old, intptr_t new); >> +intptr_t casuptr(intptr_t *p, intptr_t old, intptr_t __new__); > > This is a namespace violation. A simpler solution is to leave out > argument names entirely. If the code style permits, I agree with you. GCC support library usually uses "namespace" to add various prefixes to its built-in functions/variables in order to avoid conflicts against user code. In ELF binary file, built-in functions/variables' names are much longer than "__new__". See files in /usr/src/contrib/libstdc++/libsupc++/. ------------------------------------------------------------------------ From Beijing, China
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1152612305.19369>