Skip to content

Commit e1ed0f3

Browse files
dlopen: Add source files to mark if runtime is dynamic library (#29097)
This PR adjusts the runtime build script and adds two new source files. The source files set an `int` to indicate whether or not the runtime was built as a dynamic library or not. It adjusts the runtime Makefile(s) in order to include one of the two source files as needed. TESTING - [x] `standard` Reviewed by @jabraham17. Thanks much!
2 parents e468261 + 8e39670 commit e1ed0f3

13 files changed

Lines changed: 94 additions & 15 deletions

runtime/Makefile.help

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ SUBDIRS = \
9090

9191
SRCS =
9292

93-
RUNTIME_OBJS = \
93+
COMMON_RUNTIME_OBJS = \
9494
$(COMMON_OBJS) \
9595
$(TASKS_OBJS) \
9696
$(THREADS_OBJS) \
@@ -104,6 +104,14 @@ RUNTIME_OBJS = \
104104
$(AUXFS_HDFS_OBJS) \
105105
$(AUXFS_CURL_OBJS)
106106

107+
STATIC_RUNTIME_OBJS = \
108+
$(STATIC_RUNTIME_ONLY_OBJS) \
109+
$(COMMON_RUNTIME_OBJS)
110+
111+
SHARED_RUNTIME_OBJS = \
112+
$(SHARED_RUNTIME_ONLY_OBJS) \
113+
$(COMMON_RUNTIME_OBJS)
114+
107115
LAUNCH_LIB_OBJS = \
108116
$(COMMON_LAUNCHER_OBJS) \
109117
$(COMM_LAUNCHER_OBJS) \
@@ -176,25 +184,25 @@ else
176184
# RUNTIME_SHARED_LIB_CXX_LINK_FLAGS=-Wl,--no-undefined
177185
endif
178186

179-
$(RUNTIME_SHARED_LIB): $(RUNTIME_OBJS) $(RUNTIME_DIR_TIMESTAMP) \
187+
$(RUNTIME_SHARED_LIB): $(SHARED_RUNTIME_OBJS) $(RUNTIME_DIR_TIMESTAMP) \
180188
$(RUNTIME_LIST_INCLUDESANDDEFINES) \
181189
$(RUNTIME_LIST_LIBRARIES) \
182190
$(RUNTIME_OVERRIDE_LD)
183191
ifneq ($(CHPL_MAKE_LIB_PIC),pic)
184192
@echo "note: Skipping creation of '$(RUNTIME_SHARED_LIB_NAME)' because 'CHPL_LIB_PIC' != 'pic'"
185193
else
186-
$(CHPL_MAKE_TARGET_CXX) -shared -o $@ $(RUNTIME_OBJS) $(LIBS) \
194+
$(CHPL_MAKE_TARGET_CXX) -shared -o $@ $(SHARED_RUNTIME_OBJS) $(LIBS) \
187195
$(RUNTIME_SHARED_LIB_CXX_LINK_FLAGS) \
188196
$(CHPL_MAKE_TARGET_BUNDLED_RUNTIME_LINK_ARGS) \
189197
$(CHPL_MAKE_TARGET_SYSTEM_RUNTIME_LINK_ARGS)
190198
endif
191199

192-
$(RUNTIME_STATIC_LIB): $(RUNTIME_OBJS) $(RUNTIME_DIR_TIMESTAMP) \
200+
$(RUNTIME_STATIC_LIB): $(STATIC_RUNTIME_OBJS) $(RUNTIME_DIR_TIMESTAMP) \
193201
$(RUNTIME_LIST_INCLUDESANDDEFINES) \
194202
$(RUNTIME_LIST_LIBRARIES) \
195203
$(RUNTIME_OVERRIDE_LD)
196204
@rm -f $@
197-
$(AR) -rc $@ $(RUNTIME_OBJS)
205+
$(AR) -rc $@ $(STATIC_RUNTIME_OBJS)
198206
$(RANLIB) $@
199207
$(TAGS_COMMAND)
200208
CHPL_HOST_COMPILER='$(CHPL_MAKE_HOST_COMPILER)' \
@@ -205,13 +213,13 @@ $(RUNTIME_STATIC_LIB): $(RUNTIME_OBJS) $(RUNTIME_DIR_TIMESTAMP) \
205213
CHPL_TARGET_CXX='$(CHPL_MAKE_TARGET_CXX)' \
206214
../util/printchplenv --runtime --no-tidy --anonymize --simple > $(RUNTIME_CHPLCONFIG)
207215

208-
$(RUNTIME_LIST_INCLUDESANDDEFINES): $(RUNTIME_OBJS) $(RUNTIME_DIR_TIMESTAMP)
216+
$(RUNTIME_LIST_INCLUDESANDDEFINES): $(COMMON_RUNTIME_OBJS) $(RUNTIME_DIR_TIMESTAMP)
209217
$(MAKE) -f Makefile.config printincludesanddefines > $(RUNTIME_LIST_INCLUDESANDDEFINES)
210218

211-
$(RUNTIME_LIST_LIBRARIES): $(RUNTIME_OBJS) $(RUNTIME_DIR_TIMESTAMP)
219+
$(RUNTIME_LIST_LIBRARIES): $(COMMON_RUNTIME_OBJS) $(RUNTIME_DIR_TIMESTAMP)
212220
$(MAKE) -f Makefile.config printlibraries > $(RUNTIME_LIST_LIBRARIES)
213221

214-
$(RUNTIME_OVERRIDE_LD): $(RUNTIME_OBJS) $(RUNTIME_DIR_TIMESTAMP)
222+
$(RUNTIME_OVERRIDE_LD): $(COMMON_RUNTIME_OBJS) $(RUNTIME_DIR_TIMESTAMP)
215223
$(MAKE) -f Makefile.config printoverrideld > $(RUNTIME_OVERRIDE_LD)
216224

217225
$(RUNTIME_DIR)/main.o: $(RUNTIME_OBJDIR)/src/main.o

runtime/src/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ include Makefile.share
3939
ifneq ($(MAKE_LAUNCHER),1)
4040
TARGETS = \
4141
$(COMMON_OBJS) \
42+
$(SHARED_RUNTIME_ONLY_OBJS) \
43+
$(STATIC_RUNTIME_ONLY_OBJS) \
4244
$(MAIN_OBJS) \
4345
$(MAIN_MLI_OBJS) \
4446
$(RUNTIME_MALLOC_OBJS) \

runtime/src/Makefile.share

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ MAIN_LAUNCHER_SRCS = \
8181
RUNTIME_MALLOC_SRCS = \
8282
chpl-mem-replace-malloc.c
8383

84+
STATIC_RUNTIME_ONLY_SRCS = \
85+
chplrt-static-build-marker.c
86+
87+
SHARED_RUNTIME_ONLY_SRCS = \
88+
chplrt-shared-build-marker.c
89+
90+
STATIC_RUNTIME_ONLY_OBJS = \
91+
$(STATIC_RUNTIME_ONLY_SRCS:%.c=$(COMMON_OBJDIR)/%.o)
92+
93+
SHARED_RUNTIME_ONLY_OBJS = \
94+
$(SHARED_RUNTIME_ONLY_SRCS:%.c=$(COMMON_OBJDIR)/%.o)
8495

8596
COMMON_OBJS = \
8697
$(COMMON_SRCS:%.c=$(COMMON_OBJDIR)/%.o)

runtime/src/chpl-prginfo.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@
3535

3636
static chpl_rt_prginfo* chpl_prg_root;
3737

38-
// TODO: Have to switch to linking in separate object files?
39-
#ifndef CHPL_RT_IS_BUILT_AS_DYNAMIC_LIBRARY
40-
int chpl_rt_is_dynamic_library = 0;
41-
#else
42-
int chpl_rt_is_dynamic_library = 1;
43-
#endif
44-
4538
/** Define setters that module code can call to set up program data. */
4639
#define CONCAT(a__, b__) a__##b__
4740
#define PREFIX chpl_rt_prginfo_data_entry_set_
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2020-2026 Hewlett Packard Enterprise Development LP
3+
* Copyright 2004-2019 Cray Inc.
4+
* Other additional copyright holders may be indicated within.
5+
*
6+
* The entirety of this work is licensed under the Apache License,
7+
* Version 2.0 (the "License"); you may not use this file except
8+
* in compliance with the License.
9+
*
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
#include "chplrt.h"
22+
23+
int chpl_rt_is_dynamic_library = 1;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2020-2026 Hewlett Packard Enterprise Development LP
3+
* Copyright 2004-2019 Cray Inc.
4+
* Other additional copyright holders may be indicated within.
5+
*
6+
* The entirety of this work is licensed under the Apache License,
7+
* Version 2.0 (the "License"); you may not use this file except
8+
* in compliance with the License.
9+
*
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
#include "chplrt.h"
22+
23+
int chpl_rt_is_dynamic_library = 0;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use CTypes;
2+
3+
// Variable that is defined in the runtime in 'chpl-prginfo.h'.
4+
proc main() {
5+
extern const chpl_rt_is_dynamic_library: c_int;
6+
var ok = chpl_rt_is_dynamic_library == 1;
7+
assert(ok);
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--no-builtin-runtime

test/dynamic-loading/SharedRuntimeBuildMarker.good

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CHPL_LIB_PIC != pic

0 commit comments

Comments
 (0)