Skip to content

Commit 61ffb51

Browse files
committed
Roll up msys2/clang/windows build fixes
This rolls up everything I had to change to get a successful source build of Julia under msys2. It's a misc collection of msys2, clang and other fixes. With this, I can use the following Make.user: ``` USE_SYSTEM_CSL=1 USE_BINARYBUILDER_LLVM=0 CC=clang CXX=clang++ FC=gfortran ``` The default USE_SYSTEM_CSL is broken due to #56840 With USE_SYSTEM_CSL=1, LLVM is broken due to #57021 Clang is required because gcc can't do an LLVM source build due to known export symbol size limits (ref JuliaPackaging/Yggdrasil#11652). That said, if we address the ABI issues in #56840, the default Make.user should build again (with BB-provided LLVM).
1 parent 11eeed3 commit 61ffb51

File tree

17 files changed

+98
-49
lines changed

17 files changed

+98
-49
lines changed

Make.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,9 @@ ifeq ($(OS), WINNT)
15801580
HAVE_SSP := 1
15811581
OSLIBS += -Wl,--export-all-symbols -Wl,--version-script=$(BUILDROOT)/src/julia.expmap \
15821582
$(NO_WHOLE_ARCHIVE) -lpsapi -lkernel32 -lws2_32 -liphlpapi -lwinmm -ldbghelp -luserenv -lsecur32 -latomic -lole32
1583-
JLDFLAGS += -Wl,--stack,8388608 --disable-auto-import --disable-runtime-pseudo-reloc
1583+
# N.B.: Unlike in the sysimage, we cannot -Wl,--disable-auto-import -Wl,--disable-runtime-pseudo-reloc here, because libstdc++/LLVM are not fully correct under
1584+
# enforced visibility at this point.
1585+
JLDFLAGS += -Wl,--stack,8388608
15841586
ifeq ($(ARCH),i686)
15851587
JLDFLAGS += -Wl,--large-address-aware
15861588
endif

base/linking.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,15 @@ function link_image_cmd(path, out)
140140
LIBS = isdebugbuild() ? ("-ljulia-debug", "-ljulia-internal-debug") :
141141
("-ljulia", "-ljulia-internal")
142142
@static if Sys.iswindows()
143-
LIBS = (LIBS..., "-lopenlibm", "-lssp", "-lgcc_s", "-lgcc", "-lmsvcrt")
143+
LIBS = (LIBS..., "-lopenlibm", "-lgcc_s", "-lgcc", "-lmsvcrt")
144+
if isdebugbuild()
145+
LIBS = (LIBS..., "-lssp")
146+
if isfile(joinpath(private_libdir(), "libmingwex.a"))
147+
# In MinGW 11, the ssp implementation was moved from libssp to
148+
# libmingwex with ssp only being a stub. See #59020.
149+
LIBS = (LIBS..., "-lmingwex", "-lkernel32")
150+
end
151+
end
144152
end
145153

146154
V = verbose_linking() ? "--verbose" : ""

cli/loader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
// Borrow definition from `support/dtypes.h`
3737
#ifdef _OS_WINDOWS_
3838
# ifdef JL_LIBRARY_EXPORTS
39-
# define JL_DLLEXPORT __declspec(dllexport)
39+
# define JL_DLLEXPORT __declspec(dllexport) __attribute__ ((visibility("default")))
4040
# endif
41-
# define JL_DLLIMPORT __declspec(dllimport)
41+
# define JL_DLLIMPORT __declspec(dllimport) __attribute__ ((visibility("default")))
4242
#define JL_HIDDEN
4343
#else
4444
# define JL_DLLIMPORT __attribute__ ((visibility("default")))

cli/loader_win_utils.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ static FILE _stderr = { INVALID_HANDLE_VALUE };
1212
FILE *stdout = &_stdout;
1313
FILE *stderr = &_stderr;
1414

15+
void JL_HIDDEN free(void* mem) {
16+
HeapFree(GetProcessHeap(), 0, mem);
17+
}
18+
1519
int JL_HIDDEN fwrite(const char *str, size_t nchars, FILE *out) {
1620
DWORD written;
1721
if (out->isconsole) {
@@ -44,10 +48,6 @@ void JL_HIDDEN *realloc(void * mem, const size_t size) {
4448
return HeapReAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, mem, size);
4549
}
4650

47-
void JL_HIDDEN free(void* mem) {
48-
HeapFree(GetProcessHeap(), 0, mem);
49-
}
50-
5151
LPWSTR *CommandLineToArgv(LPWSTR lpCmdLine, int *pNumArgs) {
5252
LPWSTR out = lpCmdLine;
5353
LPWSTR cmd = out;

deps/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ ifeq ($(USE_SYSTEM_LIBBLASTRAMPOLINE), 0)
4242
DEP_LIBS += blastrampoline
4343
endif
4444

45-
ifeq ($(USE_SYSTEM_CSL), 0)
45+
# We need to run this whether or not USE_SYSTEM_CSL is set.
46+
# If it is, this target copies the system CSLs into the location our
47+
# build system expects.
4648
DEP_LIBS += csl
47-
endif
4849

4950
ifeq ($(SANITIZE), 1)
5051
DEP_LIBS += sanitizers

deps/csl.mk

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
STD_LIB_PATH := $(shell LANG=C $(FC) -print-search-dirs 2>/dev/null | grep '^programs: =' | sed -e "s/^programs: =//")
33
STD_LIB_PATH += $(PATHSEP)$(shell LANG=C $(FC) -print-search-dirs 2>/dev/null | grep '^libraries: =' | sed -e "s/^libraries: =//")
44
ifeq ($(BUILD_OS),WINNT) # the mingw compiler lies about it search directory paths
5-
STD_LIB_PATH := $(shell echo '$(STD_LIB_PATH)' | sed -e "s!/lib/!/bin/!g")
5+
STD_LIB_PATH += $(shell echo '$(STD_LIB_PATH)' | sed -e "s!/lib/!/bin/!g")
66
endif
77

8-
# Given a colon-separated list of paths in $(2), find the location of the library given in $(1)
8+
# Given a $(PATHSEP)-separated list of paths in $(2), find the location of the library given in $(1)
99
define pathsearch
1010
$(firstword $(wildcard $(addsuffix /$(1),$(subst $(PATHSEP), ,$(2)))))
1111
endef
@@ -54,6 +54,13 @@ $$(build_shlibdir)/$(1): | $$(build_shlibdir)
5454
[ -n "$$$${SRC_LIB}" ] && cp "$$$${SRC_LIB}" '$$(build_shlibdir)'
5555
endef
5656

57+
define copy_csl_static_lib
58+
install-csl: | $$(build_private_libdir) $$(build_private_libdir)/$(1)
59+
$$(build_private_libdir)/$(1): | $$(build_private_libdir)
60+
-@SRC_LIB='$$(call pathsearch,$(1),$$(STD_LIB_PATH))'; \
61+
[ -n "$$$${SRC_LIB}" ] && cp "$$$${SRC_LIB}" '$$(build_private_libdir)'
62+
endef
63+
5764
# libgfortran has multiple names; we're just going to copy any version we can find
5865
# Since we're only looking in the location given by `$(FC)` this should only succeed for one.
5966
$(eval $(call copy_csl,$(call versioned_libname,libgfortran,3)))
@@ -63,11 +70,20 @@ $(eval $(call copy_csl,$(call versioned_libname,libgfortran,5)))
6370
# These are all libraries that we should always have
6471
$(eval $(call copy_csl,$(call versioned_libname,libquadmath,0)))
6572
$(eval $(call copy_csl,$(call versioned_libname,libstdc++,6)))
66-
$(eval $(call copy_csl,$(call versioned_libname,libssp,0)))
6773
$(eval $(call copy_csl,$(call versioned_libname,libatomic,1)))
6874
$(eval $(call copy_csl,$(call versioned_libname,libgomp,1)))
6975

76+
# Configurable either a static or dynamic library depending on the system
77+
$(eval $(call copy_csl,$(call versioned_libname,libssp,0)))
78+
$(eval $(call copy_csl_static_lib,libssp.a))
79+
7080
ifeq ($(OS),WINNT)
81+
# On windows we need the static gcc runtime libraries for linking pkgimages
82+
$(eval $(call copy_csl_static_lib,libgcc.a))
83+
$(eval $(call copy_csl_static_lib,libgcc_s.a))
84+
$(eval $(call copy_csl_static_lib,libmsvcrt.a))
85+
$(eval $(call copy_csl_static_lib,libmingwex.a))
86+
$(eval $(call copy_csl_static_lib,libkernel32.a))
7187
# Windows has special gcc_s names
7288
ifeq ($(ARCH),i686)
7389
$(eval $(call copy_csl,$(call versioned_libname,libgcc_s_sjlj,1)))

deps/llvm.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ $(LLVM_BUILDDIR_withtype)/build-configured: $(SRCCACHE)/$(LLVM_SRC_DIR)/source-e
292292
echo 1 > $@
293293

294294
$(LLVM_BUILDDIR_withtype)/build-compiled: $(LLVM_BUILDDIR_withtype)/build-configured
295+
ifeq ($(OS),WINNT)
296+
ifeq ($(USEGCC),1)
297+
echo "LLVM source build is currently known to fail using GCC due to exceeded export table limits. Try clang."
298+
exit 1
299+
endif
300+
endif
295301
cd $(LLVM_BUILDDIR_withtype) && \
296302
$(if $(filter $(CMAKE_GENERATOR),make), \
297303
$(MAKE), \

deps/tools/common.mk

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
# apparently not on FreeBSD). Ref PR #22352
66

77
CONFIGURE_COMMON = --prefix=$(abspath $(build_prefix)) --build=$(BUILD_MACHINE) --libdir=$(abspath $(build_libdir)) --bindir=$(abspath $(build_depsbindir)) $(CUSTOM_LD_LIBRARY_PATH)
8+
9+
CMAKE_COMMON := -DCMAKE_INSTALL_PREFIX:PATH=$(build_prefix) -DCMAKE_PREFIX_PATH=$(build_prefix)
10+
CMAKE_COMMON += -DLIB_INSTALL_DIR=$(build_shlibdir)
11+
812
ifneq ($(XC_HOST),)
913
CONFIGURE_COMMON += --host=$(XC_HOST)
14+
else
15+
# Defeat bad automatic cross compile detection (e.g. clang on mingw)
16+
# CMAKE_COMMON += -DCMAKE_CROSSCOMPILING=0
1017
endif
1118
ifeq ($(OS),WINNT)
1219
CONFIGURE_COMMON += LDFLAGS="$(LDFLAGS) -Wl,--stack,8388608"
@@ -15,8 +22,6 @@ CONFIGURE_COMMON += LDFLAGS="$(LDFLAGS) $(RPATH_ESCAPED_ORIGIN) $(SANITIZE_LDFLA
1522
endif
1623
CONFIGURE_COMMON += F77="$(FC)" CC="$(CC) $(SANITIZE_OPTS)" CXX="$(CXX) $(SANITIZE_OPTS)" LD="$(LD)"
1724

18-
CMAKE_COMMON := -DCMAKE_INSTALL_PREFIX:PATH=$(build_prefix) -DCMAKE_PREFIX_PATH=$(build_prefix)
19-
CMAKE_COMMON += -DLIB_INSTALL_DIR=$(build_shlibdir)
2025
ifneq ($(OS),WINNT)
2126
CMAKE_COMMON += -DCMAKE_INSTALL_LIBDIR=$(build_libdir)
2227
endif
@@ -61,7 +66,12 @@ endif
6166
CMAKE_COMMON += -DCMAKE_LINKER="$$(which $(LD))" -DCMAKE_AR="$$(which $(AR))" -DCMAKE_RANLIB="$$(which $(RANLIB))"
6267

6368
ifeq ($(OS),WINNT)
69+
ifeq ($(BUILD_OS),WINNT)
70+
# Don't make CMake think we're cross compiling, but do make sure it knows we're Windows
71+
CMAKE_COMMON += -DCMAKE_HOST_SYSTEM_NAME=Windows
72+
else
6473
CMAKE_COMMON += -DCMAKE_SYSTEM_NAME=Windows
74+
endif
6575
CMAKE_COMMON += -DCMAKE_RC_COMPILER="$$(which $(CROSS_COMPILE)windres)"
6676
endif
6777

deps/zstd.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ ifneq ($(USE_BINARYBUILDER_ZSTD), 1)
33
ZSTD_GIT_URL := https://github.com/facebook/zstd.git
44
ZSTD_TAR_URL = https://api.github.com/repos/facebook/zstd/tarball/$1
55
$(eval $(call git-external,zstd,ZSTD,,,$(BUILDDIR)))
6+
# See note in llvm.mk for source tarballs with symlinks to non-existent targets
7+
$(BUILDDIR)/$(ZSTD_SRC_DIR)/source-extracted: export MSYS=winsymlinks:native
68

79
ZSTD_BUILD_OPTS := MOREFLAGS="-DZSTD_MULTITHREAD $(fPIC)" bindir=$(build_private_libexecdir)
810

doc/src/devdocs/build/windows.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ Note: MSYS2 requires **64 bit** Windows 7 or newer.
147147
For 64 bit Julia, install the x86_64 version:
148148

149149
```
150-
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake
150+
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-clang
151151
```
152152

153153
For 32 bit Julia, install the i686 version:
154154

155155
```
156-
pacman -S mingw-w64-i686-gcc mingw-w64-i686-cmake
156+
pacman -S mingw-w64-i686-gcc mingw-w64-i686-cmake mingw-w64-i686-clang
157157
```
158158

159159
5. Configuration of MSYS2 is complete. Now `exit` the MSYS2 shell.
@@ -171,7 +171,15 @@ Note: MSYS2 requires **64 bit** Windows 7 or newer.
171171
cd julia
172172
```
173173

174-
3. Start the build
174+
3. If you want to use clang (currently required if building LLVM from source), put the following in your Make.user
175+
```
176+
CC=/mingw64/bin/clang
177+
CXX=/mingw64/bin/clang++
178+
```
179+
!!! warning "UCRT Unsupported"
180+
Do not try to use any other clang that MSYS2 may install (which may not have the correct default target) or the "Clang" environment(which defaults to the currently unsupported ucrt).
181+
182+
4. Start the build
175183

176184
```
177185
make -j$(nproc)

0 commit comments

Comments
 (0)