Re: How can I get an assembler definition of a structure?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

> I would like an assembler (or offset map) of task_struct. It is defined in
> sched.h with quite a few subdefinitions.
>
> How can I request this of GCC (or AS)?

None that I know. However, it might give you idea:
$ cat coba.c

#include<stdio.h>

typedef struct
{
        float a;
        int b;
} mystruct;


static mystruct this_struct;

int main(int argc, char * argv[])
{
        this_struct.a=0.1;
        this_struct.b=2;
        printf("%.2f \n",this_struct.a);
        printf("%d \n",this_struct.b);
        return 0;
}

$ gcc -ggdb -O0 -W -Wall -o coba coba.c

$ objdump -d -S ./coba
...
 this_struct.a=0.1;
 8048384:       b8 cd cc cc 3d          mov    $0x3dcccccd,%eax
 8048389:       a3 c8 95 04 08          mov    %eax,0x80495c8
        this_struct.b=2;
 804838e:       c7 05 cc 95 04 08 02    movl   $0x2,0x80495cc
 8048395:       00 00 00
...

$ nm -B -S ./coba | grep this_struct
080495c8 00000008 b this_struct

So, this_struct is 8 byte size. "a" is located in 0x080495c8 and
0x80495cc ( offset 4 byte from the start of "this_struct"). Pay
attention that I use "static" thus this struct is placed in .bss.

Finally, we can get the picture:
this_struct --- a (offset 0)
+-----------------b (offset 4)

Surely, alignment and the usage of "packed" do matter here. So does
the optimization flags.

regards,

Mulyadi.

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux