Page MenuHomePhabricator

[llvm-readobj] Fix "Section" output when emitting relocations in JSON
Needs ReviewPublic

Authored by paulkirth on Oct 31 2022, 10:52 AM.

Details

Reviewers
jhenderson
Summary

Prior to this patch, the JSON output would emit an invalid key from the
shared LLVM implementation. This caused llvm-readobj to output invalid
JSON. This patch introduces a small helper function to print the
relocation information differently between the LLVM and JSON formats.

Before this patch:

"Relocations": [Section (2) .rel.text {

  {
    "Relocation": {
      "Offset": 0,
      "Type": {
        "Value": "R_X86_64_NONE",
        "RawValue": 0
      },
      "Symbol": {
        "Value": "rel_0",
        "RawValue": 1
      }
    }
  },
  ...

After this patch:

"Relocations": [
   {
     "SectionIdx": 2,
     "Relocs": [
       {
         "Relocation": {
           "Offset": 0,
           "Type": {
             "Name": "R_X86_64_NONE",
             "Value": 0
           },
           "Symbol": {
             "Name": "rel_0",
             "Value": 1
           }
         }
       },
       ...

Diff Detail

Event Timeline

paulkirth created this revision.Oct 31 2022, 10:52 AM
Herald added a project: Restricted Project. · View Herald Transcript
paulkirth requested review of this revision.Oct 31 2022, 10:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2022, 10:52 AM
jhenderson requested changes to this revision.Nov 1 2022, 1:33 AM

Please provide before and after examples, and test cases for the fix. Also, please fix the title to use "llvm-readobj" in the commit message/patch description, not simply "readobj".

This revision now requires changes to proceed.Nov 1 2022, 1:33 AM
paulkirth updated this revision to Diff 483651.Dec 16 2022, 1:25 PM
paulkirth retitled this revision from [readobj] Emit valid JSON when emitting Relocations to [llvm-readobj] Fix "Section" output when emitting relocations in JSON.
paulkirth edited the summary of this revision. (Show Details)

Rebase

  • Update summary
  • Add tests
  • Simplify implementation to avoid code duplication
paulkirth updated this revision to Diff 484087.Dec 19 2022, 2:48 PM

Rebase to fix patch application