This is an archive of the discontinued LLVM Phabricator instance.

[CFI] Add a module flag to allow custom section on globals with !type metadata when not doing CFI
Needs ReviewPublic

Authored by kubamracek on Oct 13 2021, 2:50 PM.

Details

Summary

See the added testcase -- the problem happens when trying to apply VFE during LTO, but without CFI at all, and when having a custom section on a vtable global. In that case LowerTypeTestsPass rejects the IR because it enforces that all !type-having globals must not specify a custom section. However, in a non-CFI compilation, this requirement is too strict, using !type metadata for VFE does not have any such requirement.

This diff adds a module flag, "No CFI Section Enforcement", that allows custom sections on globals with !type metadata, and basically is a way of informing LowerTypeTestsPass that the compilation is not doing CFI. Suggestions for alternative solutions welcome!

Diff Detail

Event Timeline

kubamracek created this revision.Oct 13 2021, 2:50 PM
kubamracek requested review of this revision.Oct 13 2021, 2:50 PM

has this always been broken?

has this always been broken?

I guess it might be helpful to elaborate why it should be safe to ignore custom sections and/or when it would be safe for frontends to emit the new flag.

has this always been broken?

I guess it might be helpful to elaborate why it should be safe to ignore custom sections and/or when it would be safe for frontends to emit the new flag.

I think this "confusion" between CFI and VFE has always been there, as far as I can tell -- when doing VFE with no CFI. But vtables emitted by Clang never have a custom section specified, so I believe this problem can not be triggered from Clang.

would be safe for frontends to emit the new flag

My understanding is that if the frontend is not trying to enable CFI at all, *then* it's safe to emit the flag. Where would you like to see this explanation in source code? LangRef doesn't really try to document module flags... A comment instead?

fhahn added inline comments.Oct 19 2021, 1:27 AM
llvm/test/Transforms/GlobalDCE/virtual-functions-sections.ll
1

Shouldn't this test be in lvm/test/Transforms/LowerTypeTests/ and independent of -globaldce?