* .data segment
@ 2023-01-20 9:20 ratheesh kannoth
2023-01-20 9:24 ` ratheesh kannoth
0 siblings, 1 reply; 2+ messages in thread
From: ratheesh kannoth @ 2023-01-20 9:20 UTC (permalink / raw)
To: gcc-help
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
......................................
........................................
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: .data segment
2023-01-20 9:20 .data segment ratheesh kannoth
@ 2023-01-20 9:24 ` ratheesh kannoth
0 siblings, 0 replies; 2+ messages in thread
From: ratheesh kannoth @ 2023-01-20 9:24 UTC (permalink / raw)
To: gcc-help
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
> ......................................
> ........................................
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-20 9:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-20 9:20 .data segment ratheesh kannoth
2023-01-20 9:24 ` ratheesh kannoth
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).