What does "readelf: Warning: Corrupt offset in range entry N" mean?

531 views Asked by At

I am running readelf -w on my (C++) executable to examine some debug sections and it prints the following warnings a couple of times:

$ readelf -w a.out
...
readelf: Warning: Corrupt offset (0x00000028) in range entry 1
readelf: Warning: Corrupt offset (0x00000044) in range entry 2
readelf: Warning: Corrupt offset (0x00000054) in range entry 3
...

I have no clue what this means and neither the manpage nor Google could help. Can anyone enlighten me?

2

There are 2 answers

1
Employed Russian On

The error comes from dwarf.c here:

  for (i = 0; i < num_range_list; i++)
...
      if (offset > (size_t) (finish - section_begin))
        {
          warn (_("Corrupt offset (%#" PRIx64 ") in range entry %u\n"),
                offset, i);
          continue;
        }

What this means is hard to say without seeing output from readelf --all. It could be that your compiler is producing bad debug info, but it could also be a bug in readelf, possibly this one.

You could try using eu-readelf from the elfutils package, which appears to be better maintained.

0
Vser On

This could also mean that the binary was compiled with -ffunction-sections and then linked with ld --gc-sections which leaves dropped sections untouched with "corrupted ranges".

See https://maskray.me/blog/2021-02-28-linker-garbage-collection