This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Function multi-versioning: don't set comdat for internal linkage resolvers
ClosedPublic

Authored by MaskRay on Aug 27 2023, 10:02 PM.

Details

Summary

For function multi-versioning using the target or target_clones
function attributes, currently we incorrectly set comdat for internal
linkage resolvers. This is problematic for ELF linkers
as GRP_COMDAT deduplication will kick in even with STB_LOCAL signature
(https://groups.google.com/g/generic-abi/c/2X6mR-s2zoc
"GRP_COMDAT group with STB_LOCAL signature").

In short, two __attribute((target_clones(...))) static void foo()
in two translation units will be deduplicated. Fix this.

Fix #65114

Diff Detail

Event Timeline

MaskRay created this revision.Aug 27 2023, 10:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 27 2023, 10:02 PM
MaskRay requested review of this revision.Aug 27 2023, 10:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 27 2023, 10:02 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
erichkeane accepted this revision.Aug 30 2023, 8:09 AM

Needs a release note. I don't have a problem with the patch, but don't really understand how COMDAT works/linking works, but since you're basically the person I'd tell someone else to ask, I guess I'll trust you know what you're doing :)

Please add the release note while committing.

This revision is now accepted and ready to land.Aug 30 2023, 8:09 AM
MaskRay updated this revision to Diff 554756.Aug 30 2023, 9:41 AM
MaskRay edited the summary of this revision. (Show Details)

add release note

This revision was landed with ongoing or failed builds.Aug 30 2023, 9:47 AM
This revision was automatically updated to reflect the committed changes.
ilinpv added inline comments.Sep 4 2023, 2:58 PM
clang/docs/ReleaseNotes.rst
208

If I read the code right it applies for function multi-versioning using target_version and target_clones attributes ( AArch64 ) as well, doesn't it?

MaskRay added inline comments.Sep 5 2023, 3:01 PM
clang/docs/ReleaseNotes.rst
208

Yes, this patch fixed target_version as well.

Perhaps update_cc_test_checks.py should be updated to test comdat as well.

I'll adjust the release note to:

For function multi-versioning using the `target, target_clones, target_version` ...