I have been doing some tests and realized that it is wrong to say that the stack segment exists, because when I analyze a binary, I realized that any data type, which is neither in the register nor in static, global or constant, is in the text segment. Do you agree with me about this? I'm really in doubt, I always thought it was right to call heap and stack memory segments.I know the concept exists, but not a segment
Compile: gcc example.c -c
Ex: objdump -s example.o
#include <stdio.h>
int main(void) {
char s[] = "string";
return 0;
}
You probably refer to this:
Contents of section .text:
0000 554889e5 c745f073 74726966 c745f46e UH...E.strif.E.n
0010 67c645f6 00b80000 00005dc3 g.E.......].
You can see the string "string" in the text section, because this statement
char s[] = "string";
leads to code, which copies the string to the stack. objdump -d
shows
Disassembly of section .text:
0000000000000000 <main>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: c7 45 f0 73 74 72 69 movl $0x69727473,-0x10(%rbp)
b: 66 c7 45 f4 6e 67 movw $0x676e,-0xc(%rbp)
...
The last two instructions move "string" on the stack, since it operates with immediate values you can see the string in the hexdump. Nevertheless, it lives on the stack at runtime.