Skip to content

Commit a8693b1

Browse files
authored
Windows: Do not -Wl,--export-all-symbols by default (#1099)
1 parent b98a38f commit a8693b1

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

src/PackageCompiler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ function get_extra_linker_flags(version, compat_level, soname)
806806
soname_arg = soname === nothing ? `` : `-Wl,-soname,$soname`
807807
rpath_args = rpath_sysimage()
808808

809-
extra = Sys.iswindows() ? `-Wl,--export-all-symbols` :
809+
extra = Sys.iswindows() ? (VERSION >= v"1.11" ? `-Wl,--export-all-symbols` : ``) :
810810
Sys.isapple() ? `-fPIC $compat_ver_arg $current_ver_arg $rpath_args` :
811811
Sys.isunix() ? `-fPIC $soname_arg $rpath_args` :
812812
error("unknown machine type, not windows, macOS not UNIX")

src/julia_init.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,24 @@ JL_DLLEXPORT char *dirname(char *);
88
#include <libgen.h>
99
#endif
1010

11+
#ifdef _OS_WINDOWS_
12+
#define DLLEXPORT __declspec(dllexport)
13+
#else
14+
#define DLLEXPORT
15+
#endif
16+
17+
1118
// Julia headers (for initialization and gc commands)
1219
#include "julia.h"
1320
#include "julia_init.h"
1421
#include "uv.h"
1522

16-
void setup_args(int argc, char **argv) {
23+
static void setup_args(int argc, char **argv) {
1724
uv_setup_args(argc, argv);
1825
jl_parse_opts(&argc, &argv);
1926
}
2027

21-
const char *get_sysimage_path(const char *libname) {
28+
static const char *get_sysimage_path(const char *libname) {
2229
if (libname == NULL) {
2330
jl_error("julia: Specify `libname` when requesting the sysimage path");
2431
exit(1);
@@ -40,7 +47,7 @@ const char *get_sysimage_path(const char *libname) {
4047
return libpath;
4148
}
4249

43-
void set_depot_load_path(const char *root_dir) {
50+
static void set_depot_load_path(const char *root_dir) {
4451
#ifdef _WIN32
4552
char *path_sep = ";";
4653
char *julia_share_subdir = "\\share\\julia";
@@ -83,7 +90,7 @@ void set_depot_load_path(const char *root_dir) {
8390
free(new_depot_path);
8491
}
8592

86-
void init_julia(int argc, char **argv) {
93+
DLLEXPORT void init_julia(int argc, char **argv) {
8794
setup_args(argc, argv);
8895

8996
const char *sysimage_path = get_sysimage_path(JULIAC_PROGRAM_LIBNAME);
@@ -114,4 +121,4 @@ void init_julia(int argc, char **argv) {
114121
free(_sysimage_path);
115122
}
116123

117-
void shutdown_julia(int retcode) { jl_atexit_hook(retcode); }
124+
DLLEXPORT void shutdown_julia(int retcode) { jl_atexit_hook(retcode); }

src/juliaconfig.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,18 @@ function ldflags()
4040
fl = "-L$(shell_escape(julia_libdir())) -L$(shell_escape(julia_private_libdir()))"
4141
if Sys.iswindows()
4242
fl = fl * " -Wl,--stack,8388608"
43-
fl = fl * " -Wl,--export-all-symbols"
43+
if VERSION >= v"1.11"
44+
# This should not really be necessary if users are using DLLEXPORT as required
45+
# on Windows in any compiled / init `.c` files, but we keep these flag for
46+
# backwards-compatibility on v1.11+ where it is mostly harmless now that LLVM
47+
# 16+ emits `-exclude-symbols` directives
48+
#
49+
# On Julia 1.10, users must annotate their code with DLLEXPORT for it to link,
50+
# since this flag would cause Julia to easily hit COFF symbol limits.
51+
#
52+
# (see https://github.com/JuliaLang/julia/pull/59736)
53+
fl = fl * " -Wl,--export-all-symbols"
54+
end
4455
elseif Sys.islinux()
4556
fl = fl * " -Wl,--export-dynamic"
4657
end

0 commit comments

Comments
 (0)