This is an archive of the discontinued LLVM Phabricator instance.

[lldb][ObjectFileELF] Improve error output for unsupported arch/relocations
ClosedPublic

Authored by sgraenitz on Apr 5 2023, 9:23 AM.

Details

Summary

ObjectFileELF::ApplyRelocations() considered all 32-bit input objects to be i386 and didn't provide good error messages for AArch32 objects. Please find an example in https://github.com/llvm/llvm-project/issues/61948
While we are here, let' improve the situation for unsupported architectures as well. I think we should report the error here too and not silently fail (or crash with assertions enabled).

Diff Detail

Event Timeline

sgraenitz created this revision.Apr 5 2023, 9:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2023, 9:23 AM
Herald added a subscriber: emaste. · View Herald Transcript
sgraenitz requested review of this revision.Apr 5 2023, 9:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2023, 9:23 AM
Herald added a subscriber: MaskRay. · View Herald Transcript

This would be good to land in preparation for D147642

SixWeining accepted this revision.Apr 5 2023, 11:16 PM

LGTM. I think this is a requirement for adding other 32bit arch support.

This revision is now accepted and ready to land.Apr 5 2023, 11:16 PM

Agreed.

The tangled web of switch statements makes my head spin so if you ever feel like tackling that please do :)

lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
2705

Should this report error also? Given that you want it to not crash.

Though it did that already, you must have had reason to change it.

sgraenitz updated this revision to Diff 513187.Apr 13 2023, 5:29 AM

Include R_386_NONE for error reporting

sgraenitz marked an inline comment as done.Apr 13 2023, 5:30 AM

Thanks for your feedback

lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
2705

I think the relocation types that can occur in debug sections are considered an invariant. If we see other relocation types, we got on a wrong track long before. The relocation resolver that exists in LLVM nowadays follows a support/resolve approach, which gives it a cleaner structure, but it comes down to the same behavior eventually: https://github.com/llvm/llvm-project/blob/release/16.x/llvm/lib/Object/RelocationResolver.cpp#L287-L299

I think it's best to keep this as is: Bail out with the assertion in development builds and ignore it silently in release builds.

This revision was automatically updated to reflect the committed changes.
sgraenitz marked an inline comment as done.