Page MenuHomeFreeBSD

Add missing powerpc64 relocation support to libdwarf
ClosedPublic

Authored by bdragon on May 22 2019, 11:06 PM.
Referenced Files
Unknown Object (File)
Sun, Apr 7, 12:37 PM
Unknown Object (File)
Sun, Apr 7, 11:32 AM
Unknown Object (File)
Sun, Apr 7, 11:05 AM
Unknown Object (File)
Sat, Apr 6, 2:09 AM
Unknown Object (File)
Sat, Apr 6, 2:09 AM
Unknown Object (File)
Mon, Mar 25, 5:19 PM
Unknown Object (File)
Mon, Mar 25, 7:36 AM
Unknown Object (File)
Mar 4 2024, 3:23 AM

Details

Summary

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

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

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

contrib/elftoolchain/libdwarf/libdwarf_reloc.c
47

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?

contrib/elftoolchain/libdwarf/libdwarf_reloc.c
46–47

where does this actually get used in the tree?

contrib/elftoolchain/libdwarf/libdwarf_reloc.c
46–47

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.
contrib/elftoolchain/libdwarf/libdwarf_reloc.c
46–47

I'm now not convinced anything is using this in or out of the tree, so it's perhaps somewhat academic. (See e.g. https://codesearch.debian.net/search?q=DW_ISA_PPC 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.