This is an archive of the discontinued LLVM Phabricator instance.

Add llvm::object::getELFSectionTypeName()
ClosedPublic

Authored by arichardson on Apr 27 2017, 4:00 AM.

Details

Summary

This is motivated by https://reviews.llvm.org/D32488 where I am trying to
add printing of the section type for incompatible sections to LLD error
messages. This patch allows us to use the same code in llvm-readobj and
LLD instead of duplicating the function inside LLD.

Event Timeline

grimar added inline comments.Apr 27 2017, 4:14 AM
lib/Object/ELF.cpp
153

I would use some macro here. Like in original code and
above in this file used for relocations:

#define ELF_RELOC(name, value)                              \
  case ELF::name:                                                       \
    return #name;                                                       \

It should do code shorter and be less errorprone.
May be worth to rename ELF_RELOC to something more generic and reuse,
or introduce new one. Not sure here.

ruiu added inline comments.Apr 27 2017, 11:09 AM
lib/Object/ELF.cpp
153

Yes, since this file already uses a macro, it is better to use a macro too for consistency in this case.

ruiu added inline comments.Apr 27 2017, 11:14 AM
lib/Object/ELF.cpp
240

It is probably more convenient to return 0x<hex> from this function for unknown types.

arichardson marked 2 inline comments as done.

Used a macro instead

arichardson added inline comments.Apr 28 2017, 3:14 AM
lib/Object/ELF.cpp
240

This would mean that llvm-readobj would output Type: 0x1234567 (0x1234567) as it always appends the hex value. Also we can't return a const char* then and would need to return std::string.

As the name of the function is getELFSectionTypeName() I think it is fine to return "" for unknown names because there is no known name for that section type.

ruiu added inline comments.Apr 28 2017, 8:18 AM
lib/Object/ELF.cpp
240

Then how about returning "Unknown"? That's what getELFRelocationTypeName defined above is doing, so it is good from the perspective of consistency too.

arichardson updated this revision to Diff 97274.May 1 2017, 3:17 AM

return "Unknown" in the default case

ruiu accepted this revision.May 1 2017, 12:15 PM

LGTM

lib/Object/ELF.cpp
18

Fix alignment.

This revision is now accepted and ready to land.May 1 2017, 12:15 PM
davide accepted this revision.May 1 2017, 12:19 PM

Fine with this.

I don't have commit access, could you please commit for me?