This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Difference in DWARF Info generated by GCC 3.4.6 and GCC 4.1.1


Hi all,

I am working with GCC 4.1.1, I need some clarification for the DWARF
information generated by this sample Program,

#include <stdio.h>

int fun(const char*, ...);

/* Variadic function */
int fun(const char *raj,...)
{
   return 9;
}

int main()
{
  fun("Hello world",3,2);
  return 0;
}

For the sample program given above, the assembly code generated is:
/*
SP -> Stack Pointer
FP -> Frame Pointer
RP -> Return Address Regnum
*/

.LC0:
 .string "Hello world"

_main:

 stwd FP, -(SP)
 stwd RP, -(SP)
 move SP, FP                          <<<< End of Func Prologue >>>>>>>

 move .LC0, D0                     // Location of  "Hello World"
saved in D0 for variable 'raj'
 move  3, D1
 move  2, D2
 jump _fun
 move  0, D0
 ldwd (SP)+, RP
 ldwd (SP)+, FP
 ret

_fun:
 stwd D3, -(SP)
 stwd D2, -(SP)
 stwd D1, -(SP)
 stwd D0, -(SP)                            // Location of .LC0 - Hello World
 stwd FP, -(SP)
 move SP, FP                                <<<< End of Func Prologue >>>>>>>

 move  9, D0
 ldwd (SP)+, FP
 add  16, SP
 ret


The frame base pointer in the DIE entry for _fun is taken as stack pointer. Looking at the generated assembly for _fun,

stwd D0, -(SP)    // Location of .LC0 - Hello World - variable 'raj'
stwd FP, -(SP)

after storing .LC0 (D0) in stack, the SP is decremented and FP is
stored. So the base offset with respect to SP for the variable raj is
4. But when looked at the debug output, the offset is zero.

################# Readelf O/P for 4.1.1 ##############

1><103>: Abbrev Number: 6 (DW_TAG_subprogram)
   DW_AT_sibling     : <12e>
   DW_AT_external    : 1
   DW_AT_name        : fun
   DW_AT_decl_file   : 10
   DW_AT_decl_line   : 7
   DW_AT_prototyped  : 1
   DW_AT_type        : <53>
   DW_AT_low_pc      : 0
   DW_AT_high_pc     : 0x14
    DW_AT_frame_base  : 1 byte block: 5f       (DW_OP_reg15) [Stack Pointer]

<2><11e>: Abbrev Number: 7 (DW_TAG_formal_parameter)
   DW_AT_name        : raj
   DW_AT_decl_file   : 10
   DW_AT_decl_line   : 6
   DW_AT_type        : <b9>
   DW_AT_location    : 2 byte block: 91 0     (DW_OP_fbreg: 0)

###########################################################

Can any one point out what is going wrong here? The above program is
working properly with GCC 3.4.6.

Regards,
Rohit


On 16 Apr 2007 10:04:25 -0700, Ian Lance Taylor <iant@google.com > wrote:
"Rohit Arul Raj" <rohitarulraj@gmail.com> writes:

> 1. In DIE for fun, with 3.4.6, the frame base is taken in terms of
> Frame Pointer (DW_OP_reg14), where is in 4.1.1, it is taken in terms
> of Stack Pointer (DW_OP_reg15).
>
> (For my backend, reg-no 14 is Frame Pointer and reg-no 15 is Stack Pointer)
>
> Is this the expected behavior?

It's correct if it matches the generated code.  It is possible that
gcc 4.1.1 was able to eliminate the frame pointer in a case where gcc
3.4.6 was not.

> 2. For the variable, const char *raj, the DIE for 3.4.6 has the
> location mentioned as (fbreg  + 4 [offset] ) whereas for 4.1.1,
> location is mentioned as (fbreg + 0).
>
> Any specific reason for this behavior in GCC 4.1.1

Again, it is presumably reflecting the generated code.

Ian



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]