This is an archive of the discontinued LLVM Phabricator instance.

[DWARFLinker] Convert analyzeContextInfo to a work list (NFC)
ClosedPublic

Authored by JDevlieghere on Nov 5 2020, 12:02 PM.

Details

Summary

Convert analyzeContextInfo to a work list using the same approach I used to remove the recursion from lookForDIEsToKeep. This fixes the crash reported in https://llvm.org/PR48029.

Tested using the reproducer attached to PR48029 as well as by comparing the clang MD5 hashes before and after the change.

Diff Detail

Event Timeline

JDevlieghere created this revision.Nov 5 2020, 12:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 5 2020, 12:02 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
JDevlieghere requested review of this revision.Nov 5 2020, 12:02 PM
JDevlieghere added a reviewer: gparker42.
avl added inline comments.Nov 6 2020, 1:33 PM
llvm/lib/DWARFLinker/DWARFLinker.cpp
261

nit: it is good to initialize InImportedModule and Type also: InImportedModule = false; Type = ContextWorklistItemType::AnalyzeContextInfo;

300

This is repeated many times:

unsigned Idx = CU.getOrigUnit().getDIEIndex(Die);
CompileUnit::DIEInfo &Info = CU.getInfo(Idx);

Probably, it makes sence to add helper function to CompileUnit?

CU.getInfo(Die)

friss added a comment.Nov 6 2020, 4:31 PM

This is really hard to wrap one's head around, but after starring at it for some time the logic seems sound. There's some conditional code depending on whether we built with -gmodules or not. Can you make sure to test both clang builds? I left a couple other comments that you might want to consider. Otherwise this LGTM

llvm/lib/DWARFLinker/DWARFLinker.cpp
256–261

Not sure if it matters: the struct has a bunch of padding. You could used a fixed small underlying type for Type and put it at the end. It seems like OtherInfo and Context are mutually exclusive, they could are an anonymous union slot.

322

Is 4 a reasonable size? It seems like this would overflow most of the time, wouldn't it? Should this just be a std::vector?

JDevlieghere marked 4 inline comments as done.
  • Address code review comments
  • Rebase on top of 389713759812
$ md5 /tmp/before.dSYM/Contents/Resources/DWARF/clang
MD5 (/tmp/before.dSYM/Contents/Resources/DWARF/clang) = b9b23127655eb8e4b4f91cd5380b63bc
$ md5 /tmp/after.dSYM/Contents/Resources/DWARF/clang
MD5 (/tmp/after.dSYM/Contents/Resources/DWARF/clang) = b9b23127655eb8e4b4f91cd5380b63bc
$ md5 /tmp/gmodules-before.dSYM/Contents/Resources/DWARF/clang
MD5 (/tmp/gmodules-before.dSYM/Contents/Resources/DWARF/clang) = f0f5bfd84bc6494b60f3fa07a332a5da
$ md5 /tmp/gmodules-after.dSYM/Contents/Resources/DWARF/clang
MD5 (/tmp/gmodules-after.dSYM/Contents/Resources/DWARF/clang) = f0f5bfd84bc6494b60f3fa07a332a5da
avl accepted this revision.Nov 7 2020, 2:26 AM

LGTM. with small inline comments.

llvm/lib/DWARFLinker/DWARFLinker.cpp
385

CU.getInfo(Child) could be used here.

393

CU.getInfo(DIE) could be used here.

This revision is now accepted and ready to land.Nov 7 2020, 2:26 AM
This revision was automatically updated to reflect the committed changes.
JDevlieghere marked 2 inline comments as done.