On Tue Jun 27 20:27:31 2023 +0000, Martin Storsjö wrote:
maybe Clang could treat `-fvisibility=hidden` on mingw targets as a
way to opt-out, following the logic that if a symbol is hidden, we don't expect it to be (auto)imported.
I was confused because `__attribute__((visibility ("hidden")))` does
eliminate the refptrs on Clang. I expected `-fvisibility=hidden` to have the same effect, but it does not. This is another somewhat non-obvious detail how things work. With `-fvisibility=hidden`, you set the default visibility for any symbol that you actually define within the current translation unit, to hidden. It doesn't say anything about the visibility of symbols that only are declared but that are defined elsewhere. So unfortunately, that doesn't help for this purpose. (The same also goes for avoiding GOT access indirection on e.g. ELF platforms. For setting hidden visibility as default for a larger section of declarations, it's possible to do `_Pragma("GCC visibility push(hidden)")`, but it's probably not worth the extra complexity.)
You are also right that `--with-mingw=clang` eliminates the refptrs (I
was compiling with `i386_CC=i686-w64-mingw32-clang` instead) so maybe we don't really need any changes to LLVM after all. Overall I do think we should get an option for opting out from it in Clang for mingw mode in any case, but it hasn't been enough of an issue to dig into before. But I should try to bump up the priority. In general, building in MSVC mode instead of mingw mode works almost just fine (those builds break marginally more often than the mingw builds, but when built they normally do work just as well), but there's one exception; 32 bit arm. There, the generated code requires helper functions for 32 bit integer divisions, which are provided by compiler-rt builtins in mingw mode, but which are missing when building in msvc mode. (I tested a hacky patch to provide those helpers in wine recently, but such a build seemed to crash on startup, and I haven't had time yet to dig in what's missing/wrong there.)
FYI, since Clang 18, it now has the option `-fno-auto-import` which allows omitting the refptrs in mingw mode too (code review discussion in https://reviews.llvm.org/D61670). I guess it could be useful to have Wine's configure check for support for this option and enable it where available?