该.rodata
部分的前 16 个字节是什么?
例如,我有以下代码:
#include <cstdio>
void myprintf(const char* ptr) {
printf("%p\n", ptr);
}
int main() {
myprintf("hello world");
myprintf("\0\0");
myprintf("ab\0cde");
static char hi[] = "hi";
myprintf(hi);
}
我编译:
$ g++ -Wall test_elf.cpp -o test_elf -O3 -std=c++17
接着
$ readelf -W -p .rodata test_elf
String dump of section '.rodata':
[ 10] %p^J
[ 14] hello world
[ 23] ab
[ 26] cde
如您所见,第一个常量字符串文字之前有 16 个字节。我elf.h
用来解析,我还看到第一个常量字符串文字之前有 16 个字节。其中 14 个字节为零。1 个非零字节是1
. 另一个是2
。