Why are common section variables displayed only in the object file and not in the executable file?

I am trying to understand more about the "general" section of an executable file, and I noticed that when executed objdumpon compiled code, I can see variables placed in the general code only in object files ( *.o) not on executable files.

Why is this?

//test.c

int i[1000];
int main(){return 0;}

build command:

> gcc -g0 -fcommon -c test.c
> gcc -g0 -fcommon test.c

objdumpshows iin the general section of the symbol table:

> objdump -x test.o
  ...
  SYMBOL TABLE:
  ...
  00000fa0    O   *COM*   00000020  i

If I did not run it in the executable:

> objdump -x a.out
  ...
  SYMBOL TABLE:
  ...
  0804a040 g  O   .bss    00000fa0  i

If I rebuild the object file with the flag -fno-common, it will appear in the segment .bssjust like in the executable file. Does the last executable file have this section "GENERAL"?

+5
source share
1 answer

- , . common , [] ( , , bss - ).

, .bss , .

gcc -fcommon/-fno-common

C- . Unix C . , -fcommon, GCC . , ISO C, . -fno-common , , . , ( extern) , , . , -fcommon. -fno-common , , , , .

, -fno-common -fcommon , , i [ , undefined !]

+6

All Articles