.data segment
ratheesh kannoth
ratheesh.ksz@gmail.com
Fri Jan 20 09:24:50 GMT 2023
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
> ......................................
> ........................................
More information about the Gcc-help
mailing list