Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Jun 2002 10:53:30 +0200
From:      Erik Trulsson <ertr1013@student.uu.se>
To:        Terry Lambert <tlambert2@mindspring.com>
Cc:        Bruce Evans <bde@zeta.org.au>, Maxime Henrion <mux@FreeBSD.ORG>, current@FreeBSD.ORG
Subject:   Re: duplicate -ffreestanding in kernel build
Message-ID:  <20020617085329.GA12598@falcon.midgard.homeip.net>
In-Reply-To: <3D0D95C9.70210E62@mindspring.com>
References:  <20020617150426.W3371-100000@gamplex.bde.org> <3D0D8788.D668B2C0@mindspring.com> <20020617073924.GA12276@falcon.midgard.homeip.net> <3D0D95C9.70210E62@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jun 17, 2002 at 12:54:49AM -0700, Terry Lambert wrote:
> Erik Trulsson wrote:
> > As for documentation I suggest you read the documentation for the
> > -ffreestanding and -fnobuiltin options in gcc.
> > (And read up on the "as-if" rule in the Standard.)
> 
> I read it.  It did not specifically state that it made this
> assumption, from what I could read.  I read both the man and
> info pages.
> 
> I asked this before: am I missing some documentation, here?

That a hosted C compiler is allowed to substitute puts("foo") for
printf("foo\n") is implied by the C Standard itself. (Using the "as-if"
rule.)  Compilers are not required to document this any more than they
need to document the fact that they may change "2*i" into "i+i"
(assuming "i" is an integer variable.)

Actually, if a compiler doesn't document that it does *not* do such
substitutions then one must assume that it might do it.


Anyway, in the manual for gcc 3.1 one can find the following paragraph (as part
of the description of the -fno-builtin option):

        GCC normally generates special code to handle certain built-in
        functions more efficiently; for instance, calls to alloca may
        become single instructions that adjust the stack directly, and
        calls to memcpy may become inline copy loops. The resulting
        code is often both smaller and faster, but since the function
        calls no longer appear as such, you cannot set a breakpoint on
        those calls, nor can you change the behavior of the functions
        by linking with a different library.

Exactly what functions gcc recognizes as built-ins depends on the
version of gcc (3.1 recognizes more functions than 2.95), but printf is
one of the functions gcc 3.1 treats as built-in.
This, to me, says that gcc may transform a call to one of the built-in
functions into something else.

> 
> 
> > > I think I'm going to be sick.
> > 
> > Why?  Because your assumptions turned out to be merely assumptions and
> > not facts?
> 
> Because (as Mark Valentine said):
> 
> 	"It means you can't futz with the implementation of the
> 	 standard library in a standard way."

To which I would reply that there is no standard way of futzing with
the standard library.  Trying to supply your own definitions of the
standard functions when compiling in a hosted environment is, IMO, a
Bad Idea and not very portable.

> 
> Does "-nostdlib" imply "turn the printf/puts conversions off,
> thanks"?  Assuming you can substitute one standard library

Not by my reading of the documentation, it doesn't.

> function for another in certain cases really should be more
> or less predicated on your having the standard library functions
> in scope for the link, right?

The -nostdlib option just tells the compiler that it should not
*automatically* link with the normal link libraries. This does not
necessarily imply that the standard library functions are not available
to the linker.
This, to me,  means that your code should not call any standard
functions or you need to supply a conforming library to the linker
yourself.
(Besides, I consider -nostdlib to be an option of the "don't use unless
you know exactly what you are doing and why" type. So far I have never
had any reason to use it myself.)

I will say it again: If you don't want the compiler to make assumptions
about the behaviour of the standard functions use -ffreestanding
(possibly in conjunction with -nostdlib if you want to supply your own
startup code.)


> 
> -- Terry


-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se

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




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