[Bug c/101696] New: Function multiversioning not usable with new x86-64-v*

h2+bugs at fsfe dot org gcc-bugzilla@gcc.gnu.org
Fri Jul 30 15:26:26 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101696

            Bug ID: 101696
           Summary: Function multiversioning not usable with new x86-64-v*
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: h2+bugs at fsfe dot org
  Target Milestone: ---

I really like the new feature levels, so I have created the respective binaries
for an application. I now want to dispatch to the correct one, so I thought the
easiest thing would be to have a small "arch_detect" program that gives me the
feature level as return value:

__attribute__ ((target ("default")))
int foo ()
{
    // The default version of foo.
    return 0;
}

__attribute__ ((target ("arch=x86-64")))
int foo ()
{
    return 1;
}

__attribute__ ((target ("arch=x86-64-v2")))
int foo ()
{
    return 2;
}
__attribute__ ((target ("arch=x86-64-v3")))
int foo ()
{
    return 3;
}

__attribute__ ((target ("arch=x86-64-v4")))
int foo ()
{
    return 4;
}

int main ()
{
    return foo();
}


This builds fine but always returns 0 -- independent of whether I build the
binary without -march or with -march=x86-64-v4.

Curiously, if I add the following overload:

__attribute__ ((target ("sse4.2")))
int foo ()
{
    // The default version of foo.
    return 7;
}

it will no longer build without -march=x86-64-v4, complaining that "no
dispatcher was found for the versioning attributes". If I add -march=x86-64-v4,
it will build without errors but always return 7 and not the feature level.

What am I missing?


More information about the Gcc-bugs mailing list