On Sat, 23 Sep 2000 15:02:26 +0530 (IST), 
Sushil <[EMAIL PROTECTED]> wrote:
>    While writing kernel code what is the correct way to find out if the
>kernel is being compiled with frame pointer?

Sad to say, you cannot.  This is an extract from the kdb patch
http://oss.sgi.com/projects/kdb/download/ix86/kdb-v1.4-2.4.0-test9-pre6.gz

* An activation record runs from the return address for a function
* through to the return address for the next function or sp, whichever
* comes first.  For each activation record we extract :-
*
*   start    Address of the activation record.
*   end      Address of the last byte+1 in the activation record.
*   ret      Return address to caller.
*   oldfp    Frame pointer to previous frame, 0 if this function was
*            not compiled with frame pointers.
*   fp       Frame pointer for the current frame, 0 if this function
*            was not compiled with frame pointers or fp has not been
*            set yet.
*   arg0     Address of the first argument (in the previous activation
*            record).
*   locals   Bytes allocated to locals and automatics.
*   regs     Bytes allocated to saved registers.
*   args     Bytes allocated to arguments (in the previous activation
*            record).
*   setup    Bytes allocated to setup data on stack (return address,
*           frame pointer).
*
* Although the kernel might be compiled with frame pointers, we still
* have to assume the worst and validate the frame.  Some calls from
* asm code to C code might not use frame pointers.  Third party binary
* only modules might be compiled without frame pointers, even when the
* rest of the kernel has frame pointers.  Some routines are always
* compiled with frame pointers, even if the overall kernel is not.  A
* routine compiled with frame pointers can be called from a routine
* without frame pointers, the previous "frame pointer" is saved on
* stack but it contains garbage.
*
* We check the object code to see if it saved a frame pointer and we
* validate that pointer.  Basically frame pointers are hints.

>Is the following code correct?
>
>#ifdef CONFIG_FRAME_POINTER 
>       code assuming frame pointer
>#else
>       code assuming no frame pointer  

Not really, see above.  You code might be compiled with frame pointers
but you can never tell how your caller was compiled so you cannot trust
the "frame pointer" that you were given.

>The top level Makefile that comes with the standard kernels (the ones
>which can be downloaded from kernel.org etc.) adds -fomit-frame-pointer to
>CFLAGS by default and it does not have something like
>
>ifdef CONFIG_FRAME_POINTER
>CFLAGS += -fomit-frame-pointer
>endif
>
>Is CONFIG_FRAME_POINTER a part of some external patch?
>If yes, then is there a way to find the above in the standard
>kernels?

Some architectures require you to have a frame pointer, on those
-fomit-frame-pointer is a null flag.  On other architectures it is
optional and they tend to have extra flags in arch/xxx/Makefile.

>What about CONFIG_KDB_FRAMEPTR? Is it correct to use this in a standard
>kernel to find whether the kernel is being compiled with frame pointer?

I don't know which kernel you are looking at.  CONFIG_KDB_FRAMEPTR is
part of an old kdb patch, not part of the standard kernel.  It has been
removed from current kdb patches, kdb patches after May 9 2000 use
CONFIG_FRAME_POINTER.

Keith Owens, kdb maintainer.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.tux.org/lkml/

Reply via email to