1
1
#
2
- # Copyright (c) 2011, 2022 , Oracle and/or its affiliates. All rights reserved.
2
+ # Copyright (c) 2011, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
#
5
5
# This code is free software; you can redistribute it and/or modify it
@@ -548,6 +548,7 @@ endef
548
548
# PRECOMPILED_HEADER Header file to use as precompiled header
549
549
# PRECOMPILED_HEADER_EXCLUDE List of source files that should not use PCH
550
550
# BUILD_INFO_LOG_MACRO Overrides log level of the build info log message, default LogWarn
551
+ # STATIC_LIB_EXCLUDE_OBJS exclude objects that matches from static library
551
552
#
552
553
# After being called, some variables are exported from this macro, all prefixed
553
554
# with parameter 1 followed by a '_':
@@ -726,6 +727,12 @@ define SetupNativeCompilationBody
726
727
endif
727
728
# Sort to remove duplicates and provide a reproducible order on the input files to the linker.
728
729
$1_ALL_OBJS := $$(sort $$($1_EXPECTED_OBJS) $$($1_EXTRA_OBJECT_FILES))
730
+ ifeq ($(STATIC_LIBS), true)
731
+ # Exclude the object files that match with $1_STATIC_LIB_EXCLUDE_OBJS.
732
+ ifneq ($$($1_STATIC_LIB_EXCLUDE_OBJS), )
733
+ $1_ALL_OBJS := $$(call not-containing, $$($1_STATIC_LIB_EXCLUDE_OBJS), $$($1_ALL_OBJS))
734
+ endif
735
+ endif
729
736
730
737
# Pickup extra OPENJDK_TARGET_OS_TYPE, OPENJDK_TARGET_OS, TOOLCHAIN_TYPE and
731
738
# OPENJDK_TARGET_OS plus OPENJDK_TARGET_CPU pair dependent variables for CFLAGS.
@@ -1130,6 +1137,40 @@ define SetupNativeCompilationBody
1130
1137
endif
1131
1138
endif
1132
1139
1140
+ $1_LD_OBJ_ARG := $$($1_ALL_OBJS)
1141
+
1142
+ # If there are many object files, use an @-file...
1143
+ ifneq ($$(word 17, $$($1_ALL_OBJS)), )
1144
+ $1_OBJ_FILE_LIST := $$($1_OBJECT_DIR)/_$1_objectfilenames.txt
1145
+ ifneq ($(COMPILER_COMMAND_FILE_FLAG), )
1146
+ $1_LD_OBJ_ARG := $(COMPILER_COMMAND_FILE_FLAG)$$($1_OBJ_FILE_LIST)
1147
+ else
1148
+ # ...except for toolchains which don't support them.
1149
+ $1_LD_OBJ_ARG := `cat $$($1_OBJ_FILE_LIST)`
1150
+ endif
1151
+ endif
1152
+
1153
+ # Unfortunately the @-file trick does not work reliably when using clang.
1154
+ # Clang does not propagate the @-file parameter to the ld sub process, but
1155
+ # instead puts the full content on the command line. At least the llvm ld
1156
+ # does not even support an @-file.
1157
+ #
1158
+ # When linking a large amount of object files, we risk hitting the limit
1159
+ # of the command line length even on posix systems if the path length of
1160
+ # the output dir is very long due to our use of absolute paths. To
1161
+ # mitigate this, use paths relative to the output dir when linking over
1162
+ # 500 files with clang and the output dir path is deep.
1163
+ ifneq ($$(word 500, $$($1_ALL_OBJS)), )
1164
+ ifeq ($$(TOOLCHAIN_TYPE), clang)
1165
+ # There is no strlen function in make, but checking path depth is a
1166
+ # reasonable approximation.
1167
+ ifneq ($$(word 10, $$(subst /, ,$$(OUTPUTDIR))), )
1168
+ $1_LINK_OBJS_RELATIVE := true
1169
+ $1_ALL_OBJS_RELATIVE := $$(patsubst $$(OUTPUTDIR)/%, %, $$($1_ALL_OBJS))
1170
+ endif
1171
+ endif
1172
+ endif
1173
+
1133
1174
ifeq ($$($1_TYPE), STATIC_LIBRARY)
1134
1175
$1_VARDEPS := $$($1_AR) $$(ARFLAGS) $$($1_ARFLAGS) $$($1_LIBS) \
1135
1176
$$($1_EXTRA_LIBS)
@@ -1146,10 +1187,17 @@ define SetupNativeCompilationBody
1146
1187
$1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_VARDEPS_FILE) $$(STATIC_MAPFILE_DEP)
1147
1188
1148
1189
$$($1_TARGET): $$($1_TARGET_DEPS)
1190
+ ifneq ($$($1_OBJ_FILE_LIST), )
1191
+ ifeq ($$($1_LINK_OBJS_RELATIVE), true)
1192
+ $$(eval $$(call ListPathsSafely, $1_ALL_OBJS_RELATIVE, $$($1_OBJ_FILE_LIST)))
1193
+ else
1194
+ $$(eval $$(call ListPathsSafely, $1_ALL_OBJS, $$($1_OBJ_FILE_LIST)))
1195
+ endif
1196
+ endif
1149
1197
$$(call LogInfo, Building static library $$($1_BASENAME))
1150
1198
$$(call MakeDir, $$($1_OUTPUT_DIR) $$($1_SYMBOLS_DIR))
1151
1199
$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_link, \
1152
- $$($1_AR) $$(ARFLAGS) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_ALL_OBJS ) \
1200
+ $$($1_AR) $$(ARFLAGS) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_LD_OBJ_ARG ) \
1153
1201
$$($1_RES))
1154
1202
ifeq ($(STATIC_BUILD), true)
1155
1203
ifeq ($$($1_USE_MAPFILE_FOR_SYMBOLS), true)
@@ -1201,40 +1249,6 @@ define SetupNativeCompilationBody
1201
1249
$1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
1202
1250
$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
1203
1251
1204
- $1_LD_OBJ_ARG := $$($1_ALL_OBJS)
1205
-
1206
- # If there are many object files, use an @-file...
1207
- ifneq ($$(word 17, $$($1_ALL_OBJS)), )
1208
- $1_OBJ_FILE_LIST := $$($1_OBJECT_DIR)/_$1_objectfilenames.txt
1209
- ifneq ($(COMPILER_COMMAND_FILE_FLAG), )
1210
- $1_LD_OBJ_ARG := $(COMPILER_COMMAND_FILE_FLAG)$$($1_OBJ_FILE_LIST)
1211
- else
1212
- # ...except for toolchains which don't support them.
1213
- $1_LD_OBJ_ARG := `cat $$($1_OBJ_FILE_LIST)`
1214
- endif
1215
- endif
1216
-
1217
- # Unfortunately the @-file trick does not work reliably when using clang.
1218
- # Clang does not propagate the @-file parameter to the ld sub process, but
1219
- # instead puts the full content on the command line. At least the llvm ld
1220
- # does not even support an @-file.
1221
- #
1222
- # When linking a large amount of object files, we risk hitting the limit
1223
- # of the command line length even on posix systems if the path length of
1224
- # the output dir is very long due to our use of absolute paths. To
1225
- # mitigate this, use paths relative to the output dir when linking over
1226
- # 500 files with clang and the output dir path is deep.
1227
- ifneq ($$(word 500, $$($1_ALL_OBJS)), )
1228
- ifeq ($$(TOOLCHAIN_TYPE), clang)
1229
- # There is no strlen function in make, but checking path depth is a
1230
- # reasonable approximation.
1231
- ifneq ($$(word 10, $$(subst /, ,$$(OUTPUTDIR))), )
1232
- $1_LINK_OBJS_RELATIVE := true
1233
- $1_ALL_OBJS_RELATIVE := $$(patsubst $$(OUTPUTDIR)/%, %, $$($1_ALL_OBJS))
1234
- endif
1235
- endif
1236
- endif
1237
-
1238
1252
$1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
1239
1253
$$($1_REAL_MAPFILE) $$($1_VARDEPS_FILE)
1240
1254
0 commit comments