Das Symbol in .rodata
nicht, weil es nicht schreibgeschützt ist, auch wenn es ein Stringliteral Adressen, die ist read-only:
foo.c
char * HelloWorld = "Hello, world!";
Siehe:
$ 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
Das Symbol ist in .data
, und:
$ objdump -s -j .rodata foo.o
foo.o: file format elf64-x86-64
Contents of section .rodata:
0000 48656c6c 6f2c2077 6f726c64 2100 Hello, world!.
die Stringliteral ist in .rodata
bar.c
char * const HelloWorld = "Hello, world!";
Hier wird das Symbol ist schreibgeschützt, und es ist 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
Und die Stringliteral ist auch 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 ........
Wo sehen Sie Ihre Stringliteral sollten gespeichert werden? –
Mögliche Duplikate von [C String-Literale: Wohin gehen sie?] (Http://stackoverflow.com/questions/2589949/c-string-literals-where-do-they-go) – kaylum
@ kaylum Nein, versuchen Sie es selbst – user6336793