This is an archive of the discontinued LLVM Phabricator instance.

[XCOFF][llvm-objdump] change the priority of symbols with the same address by symbol types.
ClosedPublic

Authored by Esme on Jan 19 2022, 12:03 AM.

Details

Summary

In XCOFF, each section comes with a default symbol with the same name as the section. It doesn't bind to code locations and it may cause incorrect display of symbol names under llvm-objdump -d.
For example, here is a scenario where the text section has three symbols, i.e.

00000000 .text // .text is a default symbol for text section.
00000000 .foo
0000001c .foo2

The symbols in the same section are sorted in ascending order. ie.

00000000 .foo
00000000 .text // .text has higher priority than .foo because we compare them by their names.
0000001c .foo2

llvm-objdump -d will choose the highest priority symbol to display when there are symbols with the same address.

00000000 <.text>: // incorrect here; <.foo> is expected.
...
0000001c <.foo2>:
...

This patch will change the priority of symbols with the same address by symbol type.

Diff Detail

Event Timeline

Esme created this revision.Jan 19 2022, 12:03 AM
Esme requested review of this revision.Jan 19 2022, 12:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2022, 12:03 AM
Esme edited the summary of this revision. (Show Details)Jan 19 2022, 12:52 AM
shchenz added inline comments.Jan 19 2022, 9:11 PM
llvm/tools/llvm-objdump/llvm-objdump.cpp
1144

Only handle .text is not enough I think. We can explicitly declare the section names in sthe ource code. For example:

int __attribute__((section ("explicit_sec"))) foo(int a)
{
          return a;
}
int __attribute__((section ("explicit_sec2")))  foo1(int a)
{
          return a;
}

int  __attribute__((section ("explicit_sec"))) foo2(int a)
{
          return a;
}

int __attribute__((section ("explicit_sec2"))) foo3(int a)
{
          return a;
}
int   foo4(int a)
{
          return a;
}
int   foo5(int a)
{
          return a;
}

Your patch can fix the first function in .text section, but can not fix the first function in explicit_sec2 or explicit_sec?

Esme updated this revision to Diff 402391.Jan 23 2022, 8:44 PM
Esme retitled this revision from [XCOFF][llvm-objdump] ignore the default .text symbol during dissembling. to [XCOFF][llvm-objdump] change the priority of symbols with the same address by symbol types..
Esme edited the summary of this revision. (Show Details)

The problem is, as I understand it, that the XCOFF symbol type enum isn't ordered in a convenient symbol-priority order, right?

Esme added a comment.Feb 16 2022, 9:27 PM

The problem is, as I understand it, that the XCOFF symbol type enum isn't ordered in a convenient symbol-priority order, right?

Hmm, I think the problem is the symbol type should have a higher priority than the symbol name size during sorting (at least for XCOFF).

Esme updated this revision to Diff 409485.Feb 16 2022, 9:29 PM

Make the SymbolRef::Type in a convenient symbol-priority order.

jhenderson accepted this revision.Feb 17 2022, 1:37 AM

Looks reasonable to me. Might be worth getting someone with XCOFF familiarity to review too though.

This revision is now accepted and ready to land.Feb 17 2022, 1:37 AM
shchenz accepted this revision.Feb 17 2022, 5:50 PM

LGTM too. Thanks for fixing this.

This revision was landed with ongoing or failed builds.Feb 17 2022, 9:30 PM
This revision was automatically updated to reflect the committed changes.