On Tue, 13 Jul 2021, LIU Hao wrote:

在 7/13/21 5:02 PM, Jonathan Marler 写道:
Thanks for the convenient info.  However, when I try to use __attribute__((__weak__)) I get a compiler warning from GCC, i.e.

     extern __inline__ __attribute__((__weak__))
     void foo(void) {}

     int main(int argc, char *argv[])
     {
         foo();
     }
$ gcc main.c
main.c:2:10: warning: inline function ‘foo’ declared weak [-Wattributes]
     2 |     void foo(void) {}
       |          ^~~

I'm having a hard time figuring out why I get this warning.  The info you sent looks consistent with the docs I'm finding, but this warning makes it look like GCC thinks the "weak" attribute is redundant?  Note that I still get this same warning if I remove the "extern", so it seems like GCC doesn't like inline and the weak attribute...any idea why?



(Please *Reply to All*.)

There must have been reasons why GCC ignores `weak` attribute on inline functions [1]. It might be technical limitation, but I think it makes no sense, because 1) Clang accepts, and 2) decomposing the two attributes actually works as expected [2].

Overall I'd suggest to avoid using `weak` if it's possible; it's kinda tricky/messy on COFF targets, and IIRC there's a number of cases with GCC/binutils where it doesn't quite work as you'd want to. (On ELF it's robust though.)

Do things work out if you use the existing __mingw_ovr attribute define? That one iirc expands to something which is always inlined and doesn't expect any global definition.

// Martin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to