Skip to content

Commit 996986b

Browse files
committed
ocamlopt: do not link -lzstd nor zstd.n.o by default, only for compilerlibs
To this end, we produce a new library libcomprmarsh.a, containing runtime/zstd.n.o, and attach both -lcomprmarsh and -lzstd to ocamlcommon.cmxa. (cherry picked and much improved from commit 9398511da3ede347ef9d07cc6d5d75fa844ea447) (cherry picked from commit 6a2e09d)
1 parent 96dd664 commit 996986b

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

Makefile

+22-6
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,15 @@ beforedepend:: utils/config_main.mli utils/config_boot.mli
414414
$(addprefix compilerlibs/ocamlcommon., cma cmxa): \
415415
OC_COMMON_LINKFLAGS += -linkall
416416

417+
COMPRESSED_MARSHALING_FLAGS=-cclib -lcomprmarsh \
418+
$(patsubst %, -ccopt %, $(filter-out -l%,$(ZSTD_LIBS))) \
419+
$(patsubst %, -cclib %, $(filter -l%,$(ZSTD_LIBS))) \
420+
421+
compilerlibs/ocamlcommon.cmxa: \
422+
OC_NATIVE_LINKFLAGS += $(COMPRESSED_MARSHALING_FLAGS)
423+
424+
compilerlibs/ocamlcommon.cmxa: stdlib/libcomprmarsh.$(A)
425+
417426
partialclean::
418427
rm -f compilerlibs/ocamlcommon.cma
419428

@@ -927,8 +936,6 @@ ocamlc_SOURCES = driver/main.mli driver/main.ml
927936

928937
ocamlc$(EXE): OC_BYTECODE_LINKFLAGS += -compat-32 -g
929938

930-
ocamlc.opt$(EXE): OC_NATIVE_LINKFLAGS += $(addprefix -cclib ,$(BYTECCLIBS))
931-
932939
partialclean::
933940
rm -f ocamlc ocamlc.exe ocamlc.opt ocamlc.opt.exe
934941

@@ -1133,15 +1140,15 @@ runtime_COMMON_C_SOURCES = \
11331140
sys \
11341141
$(TSAN_NATIVE_RUNTIME_C_SOURCES) \
11351142
$(UNIX_OR_WIN32) \
1136-
weak \
1137-
zstd
1143+
weak
11381144

11391145
runtime_BYTECODE_ONLY_C_SOURCES = \
11401146
backtrace_byt \
11411147
fail_byt \
11421148
fix_code \
11431149
interp \
1144-
startup_byt
1150+
startup_byt \
1151+
zstd
11451152
runtime_BYTECODE_C_SOURCES = \
11461153
$(runtime_COMMON_C_SOURCES:%=runtime/%.c) \
11471154
$(runtime_BYTECODE_ONLY_C_SOURCES:%=runtime/%.c)
@@ -1172,7 +1179,8 @@ runtime_PROGRAMS = runtime/ocamlrun$(EXE)
11721179
runtime_BYTECODE_STATIC_LIBRARIES = $(addprefix runtime/, \
11731180
ld.conf libcamlrun.$(A))
11741181
runtime_BYTECODE_SHARED_LIBRARIES =
1175-
runtime_NATIVE_STATIC_LIBRARIES = runtime/libasmrun.$(A)
1182+
runtime_NATIVE_STATIC_LIBRARIES = \
1183+
runtime/libasmrun.$(A) runtime/libcomprmarsh.$(A)
11761184
runtime_NATIVE_SHARED_LIBRARIES =
11771185

11781186
ifeq "$(RUNTIMED)" "true"
@@ -1223,6 +1231,8 @@ libasmruni_OBJECTS = \
12231231
libasmrunpic_OBJECTS = $(runtime_NATIVE_C_SOURCES:.c=.npic.$(O)) \
12241232
$(runtime_ASM_OBJECTS:.$(O)=_libasmrunpic.$(O))
12251233

1234+
libcomprmarsh_OBJECTS = runtime/zstd.n.o
1235+
12261236
## General (non target-specific) assembler and compiler flags
12271237

12281238
runtime_CPPFLAGS = -DCAMLDLLIMPORT= -DIN_CAML_RUNTIME
@@ -1339,6 +1349,9 @@ runtime/libasmrun_pic.$(A): $(libasmrunpic_OBJECTS)
13391349
runtime/libasmrun_shared.$(SO): $(libasmrunpic_OBJECTS)
13401350
$(V_MKDLL)$(MKDLL) -o $@ $^ $(NATIVECCLIBS)
13411351

1352+
runtime/libcomprmarsh.$(A): $(libcomprmarsh_OBJECTS)
1353+
$(V_MKLIB)$(call MKLIB,$@, $^)
1354+
13421355
## Runtime target-specific preprocessor and compiler flags
13431356

13441357
runtime/%.$(O): OC_CPPFLAGS += $(runtime_CPPFLAGS)
@@ -1495,9 +1508,12 @@ runtimeopt: stdlib/libasmrun.$(A)
14951508
makeruntimeopt: runtime-allopt
14961509
stdlib/libasmrun.$(A): runtime-allopt
14971510
cd stdlib; $(LN) ../runtime/libasmrun.$(A) .
1511+
stdlib/libcomprmarsh.$(A): runtime/libcomprmarsh.$(A)
1512+
cd stdlib; $(LN) ../runtime/libcomprmarsh.$(A) .
14981513

14991514
clean::
15001515
rm -f stdlib/libasmrun.a stdlib/libasmrun.lib
1516+
rm -f stdlib/libcomprmarsh.a stdlib/libcomprmarsh.lib
15011517

15021518
# Dependencies
15031519

Makefile.config.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ CPPFLAGS=@CPPFLAGS@
173173
OCAMLC_CFLAGS=@ocamlc_cflags@
174174

175175
OCAMLC_CPPFLAGS=@ocamlc_cppflags@
176-
BYTECCLIBS=@cclibs@
176+
ZSTD_LIBS=@zstd_libs@
177+
BYTECCLIBS=@zstd_libs@ @cclibs@
177178
EXE=@exeext@
178179
OUTPUTEXE=@outputexe@$(EMPTY)
179180
SUPPORTS_SHARED_LIBRARIES=@supports_shared_libraries@

configure

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

+3-1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ AC_SUBST([oc_dll_ldflags])
167167
AC_SUBST([oc_exe_ldflags])
168168
AC_SUBST([cclibs])
169169
AC_SUBST([native_ldflags])
170+
AC_SUBST([zstd_libs])
170171
AC_SUBST([ocamlc_cflags])
171172
AC_SUBST([ocamlc_cppflags])
172173
AC_SUBST([flexdll_source_dir])
@@ -2144,6 +2145,8 @@ AC_PATH_TOOL([PKG_CONFIG], [pkg-config], [false])
21442145
## ZSTD compression library
21452146

21462147
zstd_status=""
2148+
zstd_libs=""
2149+
21472150
AS_IF([test x"$with_zstd" != "xno"],
21482151
# Try pkg-config first, as it gives the most reliable results
21492152
AS_IF([${PKG_CONFIG} libzstd 2>/dev/null],
@@ -2166,7 +2169,6 @@ AS_IF([test x"$with_zstd" != "xno"],
21662169

21672170
AS_IF([test x"$zstd_status" = "xok"],
21682171
[AC_MSG_NOTICE([compressed compilation artefacts supported])
2169-
cclibs="$cclibs $zstd_libs"
21702172
internal_cppflags="$internal_cppflags $zstd_flags"
21712173
AC_DEFINE([HAS_ZSTD])],
21722174
[AS_CASE(["$with_zstd"],

ocamltest/ocamltest_config.ml.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ let exe = {@QS@|@exeext@|@QS@}
8282
let mkdll = {@QS@|@mkdll_exp@|@QS@}
8383
let mkexe = {@QS@|@mkexe_exp@|@QS@}
8484

85-
let bytecc_libs = {@QS@|@cclibs@|@QS@}
85+
let bytecc_libs = {@QS@|@zstd_libs@ @cclibs@|@QS@}
8686

8787
let nativecc_libs = {@QS@|@cclibs@|@QS@}
8888

utils/config.generated.ml.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let ocamlc_cppflags = {@QS@|@ocamlc_cppflags@|@QS@}
3333
the two drivers should be identical. *)
3434
let ocamlopt_cflags = {@QS@|@ocamlc_cflags@|@QS@}
3535
let ocamlopt_cppflags = {@QS@|@ocamlc_cppflags@|@QS@}
36-
let bytecomp_c_libraries = {@QS@|@cclibs@|@QS@}
36+
let bytecomp_c_libraries = {@QS@|@zstd_libs@ @cclibs@|@QS@}
3737
(* bytecomp_c_compiler and native_c_compiler have been supported for a
3838
long time and are retained for backwards compatibility.
3939
For programs that don't need compatibility with older OCaml releases

0 commit comments

Comments
 (0)