public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: ratheesh kannoth <ratheesh.ksz@gmail.com>
To: gcc-help@gcc.gnu.org
Subject: Re: .data segment
Date: Fri, 20 Jan 2023 14:54:50 +0530	[thread overview]
Message-ID: <CAGZFCEHqVw8sKTS+asUPakuyQBMEWC4C=UXU0gvca_pYJApfDA@mail.gmail.com> (raw)
In-Reply-To: <CAGZFCEHk3Ocjq2xGWxHs8tCHcBUDSaxXSXsJN3C9y9YT=wning@mail.gmail.com>

i mean  -> when i analyze 2.s, uninitialized static variable,
"sta_char_unini" is in  .text section. But i expected it to be in
.data section.

On Fri, Jan 20, 2023 at 2:50 PM ratheesh kannoth <ratheesh.ksz@gmail.com> wrote:
>
> Hi List,
>
> When I compiled (gcc -O0 -g  --no-pic -S  -fverbose-asm -c  2.c  -o
> 2.s) below  program to assembly code, it showed an uninitialized
> static variable, "sta_char_unini" section.
>  But when we execute the program, I can see that  "sta_char_unini" is
> in .data section (thru /proc/<pid>/maps). What is wrong in my analysis
> of 2.s ?
>
> ===================   2.c ==================================
> #include <stdio.h>
> #include <stdint.h>
> #include <unistd.h>
>
> static char sta_char_unini;
> static char sta_char_ini = 'B';
>
> char char_unini;
> char char_ini = '6';
>
> int main()
> {
>
>         sta_char_unini = 5;
>
>         char str1[] = "Hello world";
>         char *str2  = "How are you";
>         printf("Pid = %u\n", getpid());
>
>         printf("sta_char_unini=%p sta_char_ini=%p\n", &sta_char_unini,
> &sta_char_ini);
>
>         while (1);
>
>         return 0;
> }
>
> =================================== 2.s ===================
>
>         .file   "2.c"
>         .text
> .Ltext0:
>         .local  sta_char_unini
>         .comm   sta_char_unini,1,1
>         .data
>         .type   sta_char_ini, @object
>         .size   sta_char_ini, 1
> sta_char_ini:
>         .byte   66
>         .comm   char_unini,1,1
>         .globl  char_ini
>         .type   char_ini, @object
>         .size   char_ini, 1
> char_ini:
>         .byte   54
>         .section        .rodata
> .LC0:
>         .string "How are you"
> .LC1:
>         .string "Pid = %u\n"
>         .align 8
> .LC2:
>         .string "sta_char_unini=%p sta_char_ini=%p\n"
>         .text
>         .globl  main
>         .type   main, @function
> main:
> .LFB0:
>         .file 1 "2.c"
>         .loc 1 12 1
>         .cfi_startproc
> ......................................
> ........................................

      reply	other threads:[~2023-01-20  9:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20  9:20 ratheesh kannoth
2023-01-20  9:24 ` ratheesh kannoth [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGZFCEHqVw8sKTS+asUPakuyQBMEWC4C=UXU0gvca_pYJApfDA@mail.gmail.com' \
    --to=ratheesh.ksz@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).