Page MenuHomeFreeBSD

Add missing powerpc64 relocation support to libdwarf

Authored by bdragon on May 22 2019, 11:06 PM.



Due to missing relocation support in libdwarf for powerpc64, handling of dwarf info on unlinked objects was bogus.

Examining raw dwarf data on objects compiled on ppc64 with a modern compiler (in-tree gcc tends to hide the issue, since it only rarely generates relocations in .debug_info and uses DW_FORM_str instead of DW_FORM_strp for everything), you will find that the dwarf data appears corrupt, with repeated references to the compiler version where things like types and function names should appear.

This happens because the 0 offset of .debug_str contains the compiler version, and without applying the relocations, *all* indirect strings in .dwarf_info will end up pointing to it.

This corruption then propogates to the CTF data, as ctfconvert relies on libdwarf to read the dwarf info, for every compiled object (when building a kernel.)

However, if you examine the dwarf data on a compiled executable, it will appear correct, because during final link the relocations get applied and baked in by the linker.

"I can't believe we got this far without it." -- me, initial summary

Test Plan

note: remember to rebuild kernel toolchain by force when testing, since stuff gets built against statically linked ctf tools, and they don't auto-bootstrap when they are not considered "outdated". Might also need to make install in the elftoolchain folder for good measure.

This will need a bump to the elftoolchain bootstrap check in Makefile.inc1.

Diff Detail

rS FreeBSD src repository - subversion
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Of course I was getting the first part backwards. The point stands that the support was missing.

47 ↗(On Diff #57736)

OK obviously I got this one backwards.

bdragon marked an inline comment as not done.

Fix backwards logic.

This is the root cause of all the ctfmerge oddness on powerpc64.

fix my diff config, context was missing

LGTM although I am curious how _dwarf_get_reloc_type actually gets used?

46–47 ↗(On Diff #57741)

where does this actually get used in the tree?

46–47 ↗(On Diff #57741)

It looks to me like this bit might only be used if you're using libdwarf to *generate* dwarf data. I am not convinced there's anything in-tree using it this way.

bdragon retitled this revision from Add missing powerpc64 support to libdwarf to Add missing powerpc64 relocation support to libdwarf.May 27 2019, 4:41 AM
bdragon edited the summary of this revision. (Show Details)
bdragon edited the test plan for this revision. (Show Details)
emaste added inline comments.
46–47 ↗(On Diff #57741)

I'm now not convinced anything is using this in or out of the tree, so it's perhaps somewhat academic. (See e.g. or a web search for DW_ISA_PPC)

Presumably we would treat PPC/PPC64 as with MIPS (a single DW_ISA_ constant) not as with x86 (which has two).

This revision is now accepted and ready to land.May 27 2019, 12:04 PM
This revision was automatically updated to reflect the committed changes.