public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Compile time errors on using target attribute for Function Multi Versioning
@ 2022-04-22  7:09 Raut, S Biplab
  2022-04-22  7:36 ` Xi Ruoyao
  0 siblings, 1 reply; 4+ messages in thread
From: Raut, S Biplab @ 2022-04-22  7:09 UTC (permalink / raw)
  To: gcc-help

Hi All,
          I want to support Function Multi Versioning (FMV) in my code by using GCC's "target" attribute.
Few functions in my program are hand-written intrinsic codes, so I would prefer to use "target" over "target_clones" attribute.
But, I am getting function redefinition errors for the multiple versions of the function when I try to compile the test program.

Please find the details below:
Source code is based on:- https://gcc.gnu.org/wiki/FunctionMultiVersioning#:~:text=1%20__attribute__%20((target,return%200%3B%0A%20%2033%20%7D
GCC version used:- 11.2.0
OS used:- Ubuntu 21.10
Errors encountered:- (test_target.c is the name of source file containing the FMV example code)
$ gcc test_target.c
test_target.c:12:5: error: redefinition of 'foo'
   12 | int foo ()
      |     ^~~
test_target.c:5:5: note: previous definition of 'foo' with type 'int()'
    5 | int foo ()
      |     ^~~
test_target.c:19:5: error: redefinition of 'foo'
   19 | int foo ()
      |     ^~~
test_target.c:5:5: note: previous definition of 'foo' with type 'int()'
    5 | int foo ()
      |     ^~~
test_target.c:26:5: error: redefinition of 'foo'
   26 | int foo ()
      |     ^~~
test_target.c:5:5: note: previous definition of 'foo' with type 'int()'
    5 | int foo ()
      |     ^~~

Am I missing something here in terms of compilation flags or otherwise.
Can you please help me to get this example working. Based on this example, I will need to change my actual program.

If this group is not meant for such questions/help, please guide me to the right mailing group.

With Regards,
S. Biplab Raut

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compile time errors on using target attribute for Function Multi Versioning
  2022-04-22  7:09 Compile time errors on using target attribute for Function Multi Versioning Raut, S Biplab
@ 2022-04-22  7:36 ` Xi Ruoyao
  2022-04-22  8:17   ` Raut, S Biplab
  0 siblings, 1 reply; 4+ messages in thread
From: Xi Ruoyao @ 2022-04-22  7:36 UTC (permalink / raw)
  To: Raut, S Biplab, gcc-help

On Fri, 2022-04-22 at 07:09 +0000, Raut, S Biplab via Gcc-help wrote:
> Hi All,
>           I want to support Function Multi Versioning (FMV) in my code
> by using GCC's "target" attribute.
> Few functions in my program are hand-written intrinsic codes, so I
> would prefer to use "target" over "target_clones" attribute.
> But, I am getting function redefinition errors for the multiple
> versions of the function when I try to compile the test program.
> 
> Please find the details below:
> Source code is based on:-
> https://gcc.gnu.org/wiki/FunctionMultiVersioning#:~:text=1%20__attribute__%20((target,return%200%3B%0A%20%2033%20%7D

Please read the page carefully:

"Support is only available in C++ for i386 targets."
-- 
Xi Ruoyao <xry111@mengyan1223.wang>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Compile time errors on using target attribute for Function Multi Versioning
  2022-04-22  7:36 ` Xi Ruoyao
@ 2022-04-22  8:17   ` Raut, S Biplab
  2022-04-22  9:27     ` Xi Ruoyao
  0 siblings, 1 reply; 4+ messages in thread
From: Raut, S Biplab @ 2022-04-22  8:17 UTC (permalink / raw)
  To: Xi Ruoyao, gcc-help

[AMD Official Use Only]

Thank you Xi Ruoyao for pointing that out.
Any reasons why GCC does not support it for C?

With Regards,
S. Biplab Raut

-----Original Message-----
From: Xi Ruoyao <xry111@mengyan1223.wang> 
Sent: Friday, April 22, 2022 1:07 PM
To: Raut, S Biplab <Biplab.Raut@amd.com>; gcc-help@gcc.gnu.org
Subject: Re: Compile time errors on using target attribute for Function Multi Versioning

[CAUTION: External Email]

On Fri, 2022-04-22 at 07:09 +0000, Raut, S Biplab via Gcc-help wrote:
> Hi All,
>           I want to support Function Multi Versioning (FMV) in my code 
> by using GCC's "target" attribute.
> Few functions in my program are hand-written intrinsic codes, so I 
> would prefer to use "target" over "target_clones" attribute.
> But, I am getting function redefinition errors for the multiple 
> versions of the function when I try to compile the test program.
>
> Please find the details below:
> Source code is based on:-
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.
> gnu.org%2Fwiki%2FFunctionMultiVersioning%23%3A~%3Atext%3D1%2520__attri
> bute__%2520&amp;data=05%7C01%7CBiplab.Raut%40amd.com%7C01b67bf7053048b
> 8fd3e08da2432d931%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C6378620
> 98077115339%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMz
> IiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=TCxrfZmzLCE
> CkYy7gSSS7PNA%2Bd%2BsF7EKpDBYNIaGpus%3D&amp;reserved=0((target,return%
> 200%3B%0A%20%2033%20%7D

Please read the page carefully:

"Support is only available in C++ for i386 targets."
--
Xi Ruoyao <xry111@mengyan1223.wang>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compile time errors on using target attribute for Function Multi Versioning
  2022-04-22  8:17   ` Raut, S Biplab
@ 2022-04-22  9:27     ` Xi Ruoyao
  0 siblings, 0 replies; 4+ messages in thread
From: Xi Ruoyao @ 2022-04-22  9:27 UTC (permalink / raw)
  To: Raut, S Biplab, gcc-help

On Fri, 2022-04-22 at 08:17 +0000, Raut, S Biplab wrote:
> [AMD Official Use Only]
> 
> Thank you Xi Ruoyao for pointing that out.
> Any reasons why GCC does not support it for C?

The initial implemention reused the compiler component for C++ function
overloading.  And the C programmers likely prefer an explicit way using
`__attribute__((ifunc(...)))` so nobody really wanted to spend time
implementing this for C.

-- 
Xi Ruoyao <xry111@mengyan1223.wang>
School of Aerospace Science and Technology, Xidian University

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-22  9:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-22  7:09 Compile time errors on using target attribute for Function Multi Versioning Raut, S Biplab
2022-04-22  7:36 ` Xi Ruoyao
2022-04-22  8:17   ` Raut, S Biplab
2022-04-22  9:27     ` Xi Ruoyao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).