Code:
$ cat foo.c
#include<stdio.h>
int main ()
{
char *p="aaaaaaaabbbbbbbb";
return 0;
}
$ gcc -c foo.c
$ size foo.o
text data bss dec hex filename
92 0 0 92 5c foo.o
$ nm foo.o
0000000000000000 T main
$ objdump -d foo.o
foo.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <main>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 48 c7 45 f8 00 00 00 movq $0x0,-0x8(%rbp)
b: 00
c: b8 00 00 00 00 mov $0x0,%eax
11: c9 leaveq
12: c3 retq
$ objdump -s foo.o
foo.o: file format elf64-x86-64
Contents of section .text:
0000 554889e5 48c745f8 00000000 b8000000 UH..H.E.........
0010 00c9c3 ...
Contents of section .rodata:
0000 61616161 61616161 62626262 62626262 aaaaaaaabbbbbbbb
0010 00 .
Contents of section .comment:
0000 00474343 3a202855 62756e74 7520342e .GCC: (Ubuntu 4.
0010 342e332d 34756275 6e747535 2920342e 4.3-4ubuntu5) 4.
0020 342e3300 4.3.
Contents of section .eh_frame:
0000 14000000 00000000 017a5200 01781001 .........zR..x..
0010 1b0c0708 90010000 1c000000 1c000000 ................
0020 00000000 13000000 00410e10 4386020d .........A..C...
0030 06000000 00000000 ........
Now on my machine, string constants end up in a section for read-only data (.rodata)
Some other machines would put string constants into the code section.
Some ancient fossils would put them in the data section.