readelf: Fix advance_pc to use op_addr_advance, not just op_advance.
authorMark Wielaard <mark@klomp.org>
Mon, 16 Apr 2018 08:25:35 +0000 (10:25 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 16 Apr 2018 08:25:35 +0000 (10:25 +0200)
commit40b1f188a3b3194c7f62db9760d81f07db229b33
tree760b3ccef3c045871760408ab0a9d72b294ad75b
parenteaccd7870874d8a9821e298ceaabf492490b3fa7
readelf: Fix advance_pc to use op_addr_advance, not just op_advance.

Found by John Mellor-Crummey.

The reason this bug wasn't found earlier is because gcc fixes
minimum_instr_len and max_ops_per_instr to 1 for all architectures
(in theory max_ops_per_instr could be overridden, but I didn't find
any architecture that does). And op_index always seems zero (it looks
like it is really only for special VLWI architectures).

So in all cases I saw it means that:

op_addr_advance = minimum_instr_len * ((op_index + op_advance)
                                       / max_ops_per_instr)
                = 1 * ((0 + op_advance) / 1)
                = op_advance

Completely masking the bug.

The libdw dwarf_getsrclines.c implementation does get this right.
Because it doesn't care about the data representation and so does
the calculation directly.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/readelf.c