This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Skip ODRUniquing for mismatched tags
ClosedPublic

Authored by ychen on Oct 13 2021, 5:19 PM.

Details

Summary

Otherwise, ODRUniquing would map some member method/variable MDNodes
to have enum type DIScope, resulting in invalid debug info and bad
DWARF.

  • Add a Verifier check that when a 'scope:' operand is an ODR type that is not an enum.
  • Makes ODRUniquing apply to only ODR types with the same tag so that the debuginfo/DWARF is well-formed.

Diff Detail

Event Timeline

ychen created this revision.Oct 13 2021, 5:19 PM
ychen requested review of this revision.Oct 13 2021, 5:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 13 2021, 5:19 PM
ychen edited the summary of this revision. (Show Details)Oct 13 2021, 5:25 PM
ychen edited the summary of this revision. (Show Details)

I think this has come up before in llvm-dev threads, etc - could you link to those in the patch description for further context?

For other folks, bit of a design question: Perhaps we shouldn't special case enums here, and just say that if the ODR uniquing triggers on nodes with different tags, we don't deduplicate in that case? Clearly this is best-effort, I don't think we should go and do full structural equivalence but checking the tag seems cheap and if someone's violated the ODR by accident maybe this'd make it easier on them?

ychen added a comment.Oct 14 2021, 4:04 PM

I think this has come up before in llvm-dev threads, etc - could you link to those in the patch description for further context?

Searched llvm-dev with "odr"/"LTO"/"uniquing" didn't find anything closely related. However, https://bugs.llvm.org/show_bug.cgi?id=24923 seems pretty relevant although it is of structure type ODR violation and this patch is for enum/non-enum type ODR violation.

I think this has come up before in llvm-dev threads, etc - could you link to those in the patch description for further context?

Searched llvm-dev with "odr"/"LTO"/"uniquing" didn't find anything closely related. However, https://bugs.llvm.org/show_bug.cgi?id=24923 seems pretty relevant although it is of structure type ODR violation and this patch is for enum/non-enum type ODR violation.

Ah, yeah, that's a generalization of the issue - might be worth fixing the general issue rather than only addressing this (more severe) subset of it. (@aprantl - thoughts?) Guess the generalization is checking both the tag type matches and the size of the type matches too?

Seems the case I was remembering was something @mtrofin came across internally at Google a couple of years ago ( Google internal: b/129559805 ) - yeah, I can't find lots of info on it other than the fact that we fixed the ODR violation by renaming an enum type, but doesn't look like we looked further into fixing (Thin)LTO to not fail in this particular way. (maybe @mtrofin remembers something more of that situation)

llvm/lib/IR/Verifier.cpp
867–873

Looks like this could be a function template rather than a macro?

ychen updated this revision to Diff 380468.Oct 18 2021, 10:38 AM
  • Skip ODR-type-uniquing for mismatched tags.
  • Use function template for the verifier check.

This generally looks good to me - but I'd like @aprantl or similar to take a look/sign off from an "debug info verifier/invariants" perspective.

llvm/test/Linker/debug-info-bad-enum.ll
5

Probably also check that the resulting IR is good/correct? Like that the first CU has a reference to the enumeration type from the enum list, and the second CU has a reference to the structure_type from the retained types list?

ychen updated this revision to Diff 380522.Oct 18 2021, 2:36 PM
  • Fix unit tests
ychen updated this revision to Diff 380528.Oct 18 2021, 3:05 PM
  • Address David's feedback: add debug metadata checks.
ychen marked 2 inline comments as done.Oct 18 2021, 3:05 PM
ychen added inline comments.
llvm/test/Linker/debug-info-bad-enum.ll
5

Yep.

aprantl accepted this revision.Oct 22 2021, 11:04 AM

From a pragmatic point of view this seems to make sense to me.

llvm/lib/IR/Verifier.cpp
847

Can you add a comment here explaining why we single out enum types?

llvm/test/Linker/debug-info-bad-enum.ll
3

Can you add a comment here explaining what behavior is being tested here?

This revision is now accepted and ready to land.Oct 22 2021, 11:04 AM

I'm not a verifier expert, but I'm also not convinced the verifier change is doing quite the right thing. Yes, it finds the case we ran into, but it seems like it's just checking for that one bogus case where the containing scope is incorrectly an enum. It seems to me that proper scope-checking should be looking for the tag to be something that we agree should be allowed to be a scope, rather than looking for the tag to be one thing (of many?) that we agree should not be a scope.

ychen updated this revision to Diff 381654.Oct 22 2021, 2:29 PM
ychen marked an inline comment as done.
  • Address Adrian's comments.
ychen marked 2 inline comments as done.Oct 22 2021, 2:39 PM

I'm not a verifier expert, but I'm also not convinced the verifier change is doing quite the right thing. Yes, it finds the case we ran into, but it seems like it's just checking for that one bogus case where the containing scope is incorrectly an enum. It seems to me that proper scope-checking should be looking for the tag to be something that we agree should be allowed to be a scope, rather than looking for the tag to be one thing (of many?) that we agree should not be a scope.

Yeah, I think the function name "verifyScopeOperand" is misleading in that it was not meant to check scope operand in general, but only for when an ODR type is the scope operand. So I renamed it to "verifyODRTypeAsScopeOperand" instead and add a TODO for the general case. And all of the supported tags for DICompositeType, I'm only sure that enum could not be a scope. The modified unit test does the basic checking that mismatched tags do not unique with each other. Does this sound good to you?

ychen updated this revision to Diff 381658.Oct 22 2021, 2:44 PM
  • rebase
ychen retitled this revision from [DebugInfo] When the enum type causes ODR violation, skip ODRUniquing to [DebugInfo] Skip ODRUniquing for mismatched tags.Oct 25 2021, 10:33 AM
ychen edited the summary of this revision. (Show Details)Oct 26 2021, 12:55 PM
probinson accepted this revision.Oct 26 2021, 1:00 PM

Given that enum is really the only problematic case, LGTM.

This revision was landed with ongoing or failed builds.Oct 26 2021, 3:29 PM
This revision was automatically updated to reflect the committed changes.