This is an archive of the discontinued LLVM Phabricator instance.

Adding SymbolRef::getSectionName for getting a textual section name for the symbol. Updating llvm-objdump to use this
Needs ReviewPublic

Authored by colinl on Aug 7 2015, 10:16 AM.

Details

Summary

Key features of this patch is separation of file-format specific tweaks to the section name are pushed in to an appropriate class. The MachO specific decorating of section name with the segment name is in MachOObjectFile rather than llvm-objdump.

Another feature is being able to get a section name in cases where a section iterator can't be retrieved e.g. processor specific sections in ELF files.

I'm planning to commit this in two patches. One creating the method and moving the MachO functionality which is an NFC change. A followup patch is the change to ELFObjectFile including a test showing an processor specific section name being printed out.

Diff Detail

Event Timeline

colinl updated this revision to Diff 31527.Aug 7 2015, 10:16 AM
colinl retitled this revision from to Adding SymbolRef::getSectionName for getting a textual section name for the symbol. Updating llvm-objdump to use this.
colinl updated this object.
colinl added reviewers: rafael, bkramer, ruiu, shankarke.
colinl set the repository for this revision to rL LLVM.
rafael added inline comments.Aug 7 2015, 10:25 AM
include/llvm/Object/ELFObjectFile.h
34

Please use llvm's streams.

209

Use ErrorOr

531

Don't put an anonymous namespace in a header.

colinl updated this revision to Diff 31533.Aug 7 2015, 11:36 AM

Applied ErrorOr instead of by-reference result pattern. Substituted sstream for raw_string_stream. Moved utility function out of header.

rafael edited edge metadata.Aug 7 2015, 11:55 AM

Is there some intended use other than the human friendly dump that llvm-objdump does?

An absolute symbol is not in a section named *ABS*. That is just what llvm-objdump prints in place of the section name for absolute symbols.

For the hexagon case. What does gnu objdump do?

include/llvm/Object/ELFObjectFile.h
58

Functions should be a verb and start with a lowercase letter. How about getNameFromPRCNumber?

What is PRC?

533

I don't think we use auto in cases like this.

lib/Object/MachOObjectFile.cpp
473

Don't use auto in here.

483

This looks a bit odd. The segment is not part of the section name.

It is double odd because this would be the only function adding the segment name.

lib/Object/ObjectFile.cpp
64

Move this earlier, just after the call that produces the error.

You can also fuse it with the if

if (std::error_code EC = ...)

return EC;
colinl marked 4 inline comments as done.Aug 7 2015, 1:50 PM

I guess the function's purpose is really to service llvm-objdump. I would have preferred to put this code somehow in the llvm-objdump tool though there's no visitor for the related symbol and object file classes so doing so seemed like it would be a mess of dyn_cast chains.

The end goal was for small common symbols to have something like ".scommon.4" printed instead of "*UND*". Stock GNU objdump prints *ABS* though I didn't debug why, that seems likely to be a logic fallthrough.

include/llvm/Object/ELFObjectFile.h
58

It should probably be SHN to match SHN_LOPROC and SHN_HIPROC.

533

I can change it to ELFFile<ELFT>::Elf_Sym *. Seems a little unfortunate because shortening typenames like this seems like what auto is for.

lib/Object/MachOObjectFile.cpp
483

This was to retain existing llvm-objdump behavior.

ruiu added inline comments.Aug 7 2015, 1:58 PM
include/llvm/Object/ELFObjectFile.h
533

We don't use "auto" if its type is not obvious from the very narrow context. I don't use "auto" unless the real type appears on the right-hand side.

colinl updated this revision to Diff 31681.Aug 10 2015, 9:57 AM
colinl edited edge metadata.
colinl removed rL LLVM as the repository for this revision.
colinl marked 6 inline comments as done.

Addressed comments and changed function names to indicate they're for the purpose of objdump. Maybe with new naming it'll fit in to place better?

It still seems unfortunate to inject objdump specific functions in to the Object library. If there are ideas on a cleaner way to generate this name WRT to placement and being able to access required functionality, I'm open to input.

ruiu added inline comments.Aug 10 2015, 3:06 PM
lib/Object/ELFObjectFile.cpp
60–67

This can be

return Twine("SHN_PROC[0x") + Twine::utohexstr(Index) + "]";

?

It still seems unfortunate to inject objdump specific functions in to the Object library. If there are ideas on a cleaner way to generate this name WRT to placement and being able to access required functionality, I'm open to input.

Yes, please put all this in llvm-objdump. We only have 3 object
formats, so this shouldn't be too bad. Being in objdump should allow
you to also just pass the stream into these functions instead of
computing a string that is then printed.

Cheers,
Rafael

espindola edited reviewers, added: espindola; removed: rafael.Mar 15 2018, 11:01 AM