This is an archive of the discontinued LLVM Phabricator instance.

[clang] Corrections for target_clones multiversion functions.
ClosedPublic

Authored by tahonermann on Apr 1 2022, 7:27 PM.

Details

Summary

This change merges code for emit of target and target_clones multiversion
resolver functions and, in doing so, corrects handling of target_clones
functions that are declared but not defined. Previously, a use of such
a target_clones function would result in an attempted emit of an ifunc
that referenced an undefined resolver function. Ifunc references to
undefined resolver functions are not allowed and, when the LLVM verifier
is not disabled (via '-disable-llvm-verifier'), resulted in the verifier
issuing a "IFunc resolver must be a definition" error and aborting the
compilation. With this change, ifuncs and resolver function definitions
are always emitted for used target_clones functions regardless of whether
the target_clones function is defined (if the function is defined, then
the ifunc and resolver are emitted regardless of whether the function is
used).

This change has the side effect of causing target_clones variants and
resolver functions to be emitted in a different order than they were
previously. This is harmless and is reflected in the updated tests.

Diff Detail

Event Timeline

tahonermann created this revision.Apr 1 2022, 7:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2022, 7:27 PM

Removed the in-class declaration of CodeGenModule::EmitTargetClonesResolver().

tahonermann added inline comments.Apr 2 2022, 1:21 PM
clang/lib/CodeGen/CodeGenModule.cpp
3323

This comment seemed oddly placed and didn't seem to convey used information, so I gave it the boot.

3411–3461

This functionality was all merged into CodeGenModule::emitMultiVersionFunctions() where much of it was already present.

3488–3493

Use of GetOrCreateMultiVersionResolver() here avoids duplication of code to determine how resolver functions are named for each multiversion function kind.

3670–3673

This is the change that effectively ensures that a target_clones function resolver is emitted.

clang/test/CodeGen/attr-target-clones.c
26

target_clones resolvers are now emitted consistently with target resolvers.

152–156

Some checks were simply missing previously.

161–165

Declarations emitted cause the function is no defined!

Simplified code to select a resolver function.

tahonermann added inline comments.Apr 2 2022, 1:25 PM
clang/lib/CodeGen/CodeGenModule.cpp
3495

setLinkage() was previously only called in the ifunc case. I don't know why that would be, so I "fixed" it here.

tahonermann published this revision for review.Apr 2 2022, 2:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 2 2022, 2:12 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
erichkeane accepted this revision.Apr 4 2022, 6:53 AM
erichkeane added inline comments.
clang/lib/CodeGen/CodeGenModule.cpp
3495

Likely that was the only place we 'noticed' it was a problem?

This revision is now accepted and ready to land.Apr 4 2022, 6:53 AM

Squashed the addition of tests originally made in D122954 to this review.

This revision was landed with ongoing or failed builds.Apr 5 2022, 4:51 PM
This revision was automatically updated to reflect the committed changes.
skan added a subscriber: skan.Jun 18 2023, 9:13 PM