This is an archive of the discontinued LLVM Phabricator instance.

[llvm-nm] - Move MachO specific logic out from the dumpSymbolNamesFromObject(). NFC.
ClosedPublic

Authored by grimar on Jan 14 2021, 3:35 AM.

Details

Summary

dumpSymbolNamesFromObject is the method that dumps symbol names.

It has 563 lines, mostly because of huge piece of MachO specific code.
In this patch I move it to separate helper method.

The new size of dumpSymbolNamesFromObject is 93 lines. With it it becomes
much easier to maintain it.

I had to change the type of 2 name fields to std::string, because MachO logic
uses temporarily buffer strings (e.g ExportsNameBuffer, BindsNameBuffer etc):

std::string ExportsNameBuffer;
raw_string_ostream EOS(ExportsNameBuffer);

these buffers were moved to dumpSymbolsFromDLInfoMachO by this patch and
are invalidated after return. Technically, before this patch we had a situation
when local pointers (symbol names) were assigned to members of global static SymbolList,
what is dirty by itself.

Diff Detail

Event Timeline

grimar created this revision.Jan 14 2021, 3:35 AM
grimar requested review of this revision.Jan 14 2021, 3:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 14 2021, 3:35 AM
grimar edited the summary of this revision. (Show Details)Jan 14 2021, 3:36 AM
jhenderson added inline comments.Jan 14 2021, 4:25 AM
llvm/tools/llvm-nm/llvm-nm.cpp
1320

Whilst you're here, you could get rid of the unnecessary const & here, if you want.

1689

Is everything in this function essentially identical to what was there before (barring the new call)? For some reason, Phabricator isn't showing the "moved" marker, so I can't tell.

grimar added inline comments.Jan 14 2021, 4:27 AM
llvm/tools/llvm-nm/llvm-nm.cpp
1689

Yes.

Previously we had

if (MachO && !NoDyldInfo) {
  <logic>
}

and now we have:

if (MachO && !NoDyldInfo)
  dumpSymbolsFromDLInfoMachO(*MachO);

It is the only difference.

jhenderson accepted this revision.Jan 14 2021, 4:28 AM

Okay, LGTM!

This revision is now accepted and ready to land.Jan 14 2021, 4:28 AM
grimar added inline comments.Jan 14 2021, 4:28 AM
llvm/tools/llvm-nm/llvm-nm.cpp
1689

Oh, and

std::string ExportsNameBuffer;
raw_string_ostream EOS(ExportsNameBuffer);
std::string BindsNameBuffer;
raw_string_ostream BOS(BindsNameBuffer);
std::string LazysNameBuffer;
raw_string_ostream LOS(LazysNameBuffer);
std::string WeaksNameBuffer;
raw_string_ostream WOS(WeaksNameBuffer);
std::string FunctionStartsNameBuffer;
raw_string_ostream FOS(FunctionStartsNameBuffer);

declarations were also moved to dumpSymbolsFromDLInfoMachO of course,

Does it have to stay in llvm-nm.cpp? A different file for MachO stuff?

grimar added a comment.EditedJan 14 2021, 5:31 AM

Does it have to stay in llvm-nm.cpp? A different file for MachO stuff?

It seems possible to move some MachO specific stuff to a different file. This is out of scope of this patch though.

MaskRay accepted this revision.Jan 14 2021, 9:18 AM

LGTM.