This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

readelf -W -p .rodata not showing "null" string?


Hi,

I am very new to ELF format.

I have tried a very simple program:
#include <cstdio>

void myprintf(const char* ptr) {
printf("%p\n", ptr);
}

int main() {
myprintf("hello world");
myprintf("\0\0");
myprintf("ab\0cde");
}

And then I did:
$ readelf -a test_elf | grep rodata
  [16] .rodata           PROGBITS         0000000000400760  00000760

So I know the virtual memory address of .rodata section starts at 0x400760

Then I did:
$ readelf -W -p .rodata test_elf

String dump of section '.rodata':
  [    10]  %p^J
  [    14]  hello world
  [    23]  ab
  [    26]  cde

I noticed that "\0\0" isn't listed as one of the entries above.

By calculating the address of "\0\0", it should be 0x400760 + length("hello
world\0") = 0x400780, matching the output of my program:
$ ./test_elf
0x400774
0x400780
0x400783

In other words, "\0\0" indeed stores in .rodata section.  I wonder whether
it is intended or a bug not to show the entry for "null" strings.

I am using:
$ readelf --version
GNU readelf version 2.28-8.el7.sc1
if it matters.

Another question might be kind of off topic to this mailing list; if anyone
can point me to the right place to ask, I would be highly appreciated:
I am trying to use elf.h to retrieve the indexes/offsets of all the string
literals in .rodata.
So far, I am only about to read the .rodata section via read(fd, buffer,
Elf64_Shdr::sh_size), and it contains all the string literals (including
the null strings) but I don't know how to get the offsets/indexes to those
string literals.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]