Bug 93274 - target_clones produces symbols with random digits with -fPIC
Summary: target_clones produces symbols with random digits with -fPIC
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 9.2.1
: P3 normal
Target Milestone: ---
Assignee: Martin Liška
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-15 11:18 UTC by Richard Biener
Modified: 2020-03-25 10:04 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-*-*, i?86-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-01-15 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2020-01-15 11:18:19 UTC
__attribute__((target_clones("default", "sse3")))
static void dt_simd_memcpy (const float *const __restrict__ in,
                     float *const __restrict__ out,
                     const int num_elem)
{
  for(int k = 0; k < num_elem; k++)
    out[k] = in[k];
}

void bar(float *in, float *out, int num_elem)
{
  dt_simd_memcpy (in, out, num_elem);
}

differs in generated code on each invocation of GCC with -fPIC
Comment 1 Richard Biener 2020-01-15 11:27:54 UTC
Probably caused by

  /* IFUNC's have to be globally visible.  So, if the default_decl is
     not, then the name of the IFUNC should be made unique.  */
  if (TREE_PUBLIC (default_decl) == 0)
    {
      char *ifunc_name = make_unique_name (default_decl, "ifunc", true);
      symtab->change_decl_assembler_name (ifunc_alias_decl,
                                          get_identifier (ifunc_name));

not sure if easy to avoid.
Comment 2 Martin Liška 2020-01-15 11:46:23 UTC
Yes, it's caused by the needed public visibility.
Comment 3 Bernhard M. Wiedemann 2020-01-15 13:55:05 UTC
The usual way to get deterministic uniqueness
is to hash over all relevant inputs
Comment 4 Alexander Monakov 2020-01-15 14:47:55 UTC
IFUNCs don't have to be somehow "globally visible". The comment is there from day 1, but it's not clear why - possibly a misunderstanding? GCC happily accepts a static ifunc, and rest of toolchain should have no problem either:

__attribute__((used,ifunc("r_f")))
static void f();

static void *r_f()
{
 return 0;
}
        .type   r_f, @function
r_f:
        xorl    %eax, %eax
        ret
        .size   r_f, .-r_f
        .type   f, @gnu_indirect_function
        .set    f,r_f
Comment 5 Martin Liška 2020-01-16 09:14:27 UTC
(In reply to Alexander Monakov from comment #4)
> IFUNCs don't have to be somehow "globally visible". The comment is there
> from day 1, but it's not clear why - possibly a misunderstanding? GCC
> happily accepts a static ifunc, and rest of toolchain should have no problem
> either:
> 
> __attribute__((used,ifunc("r_f")))
> static void f();
> 
> static void *r_f()
> {
>  return 0;
> }
>         .type   r_f, @function
> r_f:
>         xorl    %eax, %eax
>         ret
>         .size   r_f, .-r_f
>         .type   f, @gnu_indirect_function
>         .set    f,r_f

Great Alexander. Then let me to test the suggested change.
Comment 6 CVS Commits 2020-01-27 09:49:33 UTC
The master branch has been updated by Martin Liska <marxin@gcc.gnu.org>:

https://gcc.gnu.org/g:c2bd2b4664be8b73f8fd58a64dec1e93871797cc

commit r10-6242-gc2bd2b4664be8b73f8fd58a64dec1e93871797cc
Author: Martin Liska <mliska@suse.cz>
Date:   Mon Jan 27 10:48:18 2020 +0100

    Do not generate a unique fnname for resolver.
    
    	PR target/93274
    	* config/i386/i386-features.c (make_resolver_func):
    	Align the code with ppc64 target implementation.
    	Do not generate a unique name for resolver function.
    	PR target/93274
    	* gcc.target/i386/pr81213.c: Adjust to not expect
    	a globally unique name.
Comment 7 Martin Liška 2020-01-27 09:50:41 UTC
Fixed on trunk, probably not planning to backport.
Comment 8 CVS Commits 2020-03-25 10:04:01 UTC
The master branch has been updated by Martin Liska <marxin@gcc.gnu.org>:

https://gcc.gnu.org/g:724ec02c2c6d1b79788be77f68ebb6ca7b5b6acd

commit r10-7372-g724ec02c2c6d1b79788be77f68ebb6ca7b5b6acd
Author: Martin Liska <mliska@suse.cz>
Date:   Wed Mar 25 11:03:39 2020 +0100

    Make target_clones resolver fn static if possible.
    
            PR target/93274
            PR ipa/94271
            * config/i386/i386-features.c (make_resolver_func): Drop
            public flag for resolver.
            * config/rs6000/rs6000.c (make_resolver_func): Add comdat
            group for resolver and drop public flag if possible.
            * multiple_target.c (create_dispatcher_calls): Drop unique_name
            and resolution as we want to enable LTO privatization of the default
            symbol.
            PR target/93274
            PR ipa/94271
            * gcc.target/i386/pr81213-2.c: New test.
            * gcc.target/i386/pr81213.c: Add additional source.
            * gcc.dg/lto/pr94271_0.c: New test.
            * gcc.dg/lto/pr94271_1.c: New test.