ziglang / zig-bootstrap

take off every zig
368 stars 86 forks source link

libstdc++ version check error when croscompiling to x86_64-windows #134

Closed Vexu closed 1 year ago

Vexu commented 1 year ago

Steps to reproduce

  1. checkout https://github.com/ziglang/zig-bootstrap/tree/maximum
  2. run ./build -j8 x86_64-windows-gnu baseline
  3. when rebuilding LLVM with Zig I get this error:
    CMake Error at cmake/modules/CheckCompilerVersion.cmake:98 (message):
    libstdc++ version must be at least 5.1.
    Call Stack (most recent call first):
    cmake/config-ix.cmake:15 (include)
    CMakeLists.txt:776 (include)

I did the update by rsyncing the various folders inside zig/, it seems correct but I might be wrong.

andrewrk commented 1 year ago

libstdc++ sounds like gcc which should not be relevant once LLVM is being rebuilt with zig.

andrewrk commented 1 year ago

I'm able to reproduce this, looking into it now.

andrewrk commented 1 year ago

the cmake check looks like this:

    check_cxx_source_compiles("
#include <iosfwd>
#if defined(__GLIBCXX__)
#if __GLIBCXX__ < ${GCC_MIN_DATE}
#error Unsupported libstdc++ version
#endif
#endif
#if defined(__GLIBCXX__)
extern const char _ZNKSt17bad_function_call4whatEv[];
const char *chk = _ZNKSt17bad_function_call4whatEv;
#else
const char *chk = \"\";
#endif
int main() { ++chk; return 0; }
"
      LLVM_LIBSTDCXX_MIN)
    if(NOT LLVM_LIBSTDCXX_MIN)
      message(FATAL_ERROR "libstdc++ version must be at least ${GCC_MIN}.")
    endif()

When I do this manually, it compiles successfully:

#include <iosfwd>
#if defined(__GLIBCXX__)
#if __GLIBCXX__ < 20150422
#error Unsupported libstdc++ version
#endif
#endif
#if defined(__GLIBCXX__)
extern const char _ZNKSt17bad_function_call4whatEv[];
const char *chk = _ZNKSt17bad_function_call4whatEv;
#else
const char *chk = "";
#endif
int main() { ++chk; return 0; }
$ ~/dev/zig-bootstrap/out/host/bin/zig c++ -o test test.cpp -std=c++0x -fno-sanitize=all -s -target x86_64-windows-gnu -mcpu=baseline
$ echo $?
0

Unclear why cmake is getting a non-zero exit code when it does this check.

andrewrk commented 1 year ago

Managed to narrow the problem down:

andy@ark ~/d/b/o/b/C/CMakeTmp (master)> ../../../host/bin/zig c++ -fno-sanitize=all -s -target x86_64-windows-gnu -mcpu=baseline -std=c++0x -static -Wl,--whole-archive CMakeFiles/cmTC_9bcc2.dir/objects.a -Wl,--no-whole-archive -o cmTC_9bcc2.exe -Wl,--out-implib,libcmTC_9bcc2.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles/cmTC_9bcc2.dir/linklibs.rsp
error: unable to create compilation: UnableToStaticLink
andy@ark ~/d/b/o/b/C/CMakeTmp (master) [1]> cat CMakeFiles/cmTC_9bcc2.dir/linklibs.rsp
 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 

Perhaps a regression after upgrading mingw version.

andrewrk commented 1 year ago

Regression caused by https://github.com/ziglang/zig/commit/6af0eeb58d1d220d407ce4c463eaeb25b35f2761

andrewrk commented 1 year ago

I'm testing this patch.

--- a/zig/src/main.zig
+++ b/zig/src/main.zig
@@ -1653,8 +1653,14 @@ fn buildOutputType(
                             };
                         }
                     },
-                    .dynamic => link_mode = .Dynamic,
-                    .static => link_mode = .Static,
+                    .dynamic => switch (output_mode) {
+                        .Lib => link_mode = .Dynamic,
+                        .Obj, .Exe => force_static_libs = false,
+                    },
+                    .static => switch (output_mode) {
+                        .Lib => link_mode = .Static,
+                        .Obj, .Exe => force_static_libs = true,
+                    },
                 }
             }
             // Parse linker args.

@Vexu do you have any ideas how the -static flag is supposed to work for C compilers when targeting Windows?

Vexu commented 1 year ago

@Vexu do you have any ideas how the -static flag is supposed to work for C compilers when targeting Windows?

No but I can look into it.