The symbol is not in .rodata
because it is not read-only,
even if it addresses a string literal, which is read-only:
foo.c
char * HelloWorld = "Hello, world!";
See:
$ gcc -c foo.c
$ objdump -t foo.o
foo.o: file format elf64-x86-64
SYMBOL TABLE:
0000000000000000 l df *ABS* 0000000000000000 foo.c
0000000000000000 l d .text 0000000000000000 .text
0000000000000000 l d .data 0000000000000000 .data
0000000000000000 l d .bss 0000000000000000 .bss
0000000000000000 l d .rodata 0000000000000000 .rodata
0000000000000000 l d .note.GNU-stack 0000000000000000 .note.GNU-stack
0000000000000000 l d .comment 0000000000000000 .comment
0000000000000000 g O .data 0000000000000008 HelloWorld
The symbol is in .data
, and:
$ objdump -s -j .rodata foo.o
foo.o: file format elf64-x86-64
Contents of section .rodata:
0000 48656c6c 6f2c2077 6f726c64 2100 Hello, world!.
the string literal is in .rodata
bar.c
char * const HelloWorld = "Hello, world!";
Here the symbol is read-only, and it's in .rodata
$ gcc -c bar.c
$ objdump -t bar.o
bar.o: file format elf64-x86-64
SYMBOL TABLE:
0000000000000000 l df *ABS* 0000000000000000 bar.c
0000000000000000 l d .text 0000000000000000 .text
0000000000000000 l d .data 0000000000000000 .data
0000000000000000 l d .bss 0000000000000000 .bss
0000000000000000 l d .rodata 0000000000000000 .rodata
0000000000000000 l d .note.GNU-stack 0000000000000000 .note.GNU-stack
0000000000000000 l d .comment 0000000000000000 .comment
0000000000000010 g O .rodata 0000000000000008 HelloWorld
And the string literal is also in .rodata
:
$ objdump -s -j .rodata bar.o
bar.o: file format elf64-x86-64
Contents of section .rodata:
0000 48656c6c 6f2c2077 6f726c64 21000000 Hello, world!...
0010 00000000 00000000 ........