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]

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


Hi Henry,

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

> 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.

Note that strictly speaking, in C-terms "\0\0" is actually two,
zero-length, strings...


> 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.

It is intended.  The string dump function in readelf is intended to dump "normal"
text, it does not expect to have to display null strings.  (Actually the rule
is that the string must start with a printable character, not a NUL or control
character, but then it can contain any kind of character it likes up to the
terminating NUL).

If you want to see the contents of the section as byte values you can use the -x
option instead of -p.


> 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.

Ah - this question refers to the elfutils project, not the binutils project.
So you need to ask this question on the elfutils-devel@sourceware.org list.

Cheers
  Nick



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