在 2025-3-30 23:41, Jacek Caban 写道:
On 29.03.2025 20:53, Martin Storsjö wrote:
On Sun, 30 Mar 2025, LIU Hao wrote:

This eliminates such warnings in C:

   .../mingw-w64-headers/crt/fenv.h:64:39: warning: ‘__mingw_fe_dfl_env’ initialized and declared ‘extern’
    extern const __MINGW_SELECTANY fenv_t __mingw_fe_dfl_env = { 0, 0 };
                                          ^~~~~~~~~~~~~~~~~~

Only if compiling in a way where the headers aren't considered system headers, right - afaik that's the only case where this warning actually is visible?


That's my understanding too. There are more cases like this, see grep for DECLSPEC_SELECTANY in headers. I don’t mind changing this particular case, so that’s fine with me.

However, more generally, I don’t think we should change all headers. Ideally, GCC would silence the warning for extern const, as both Clang and MSVC do.

As part of the investigation of the section size thing, I tried to find out where the duplicate definitions came from. Then I found this:

C:/MSYS64/ucrt64/lib/libucrt.a:lib64_libucrt_extra_a-ucrt_amsg_exit.o:0000000000000000 r .rdata$__mingw_fe_dfl_env C:/MSYS64/ucrt64/lib/libucrt.a:lib64_libucrt_extra_a-ucrt_amsg_exit.o:0000000000000000 R __mingw_fe_dfl_env C:/MSYS64/ucrt64/lib/libucrt.a:lib64_libucrt_extra_a-ucrt__wgetmainargs.o:0000000000000000 r .rdata$__mingw_fe_dfl_env C:/MSYS64/ucrt64/lib/libucrt.a:lib64_libucrt_extra_a-ucrt__wgetmainargs.o:0000000000000000 R __mingw_fe_dfl_env C:/MSYS64/ucrt64/lib/libucrt.a:lib64_libucrt_extra_a-ucrt__getmainargs.o:0000000000000000 r .rdata$__mingw_fe_dfl_env C:/MSYS64/ucrt64/lib/libucrt.a:lib64_libucrt_extra_a-ucrt__getmainargs.o:0000000000000000 R __mingw_fe_dfl_env


It looked like such symbols were defined everywhere <fenv.h> was included. Then 
I made this experiment
(https://gcc.godbolt.org/z/h5KGTq1ve):

   ```
   constexpr inline int unused_value = 1;
   constexpr inline int used_value = 2;
   extern __attribute__((__selectany__)) const int selectany_value = 3;

   const int* get_used_value(void) { return &used_value; }
   ```

   ```
   get_used_value():
     lea     rax, used_value[rip]
     ret
   selectany_value:
     .long   3
   used_value:
     .long   2
   ```

The conclusion is that `selectany` is not 100% equivalent to `constexpr inline`; if a variable is `constexpr inline` but it is not odr-used, then it's not defined in the object file, as if it wasn't defined.

The effect that `__mingw_fe_dfl_env` etc. are defined everywhere is probably not good. Jacek, do you agree with this change? I can adjust the patch if we agree on that.



--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

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

Reply via email to