Skip to content

Commit 1ec7a3a

Browse files
committed
Extract the install prefix from the shared library.
This is part of a multi-project effort, a similar PR will be created in OpenPMIX and OMPI. The goal of each of these changes is the same: instead of using build-time generated prefix that ignore a project rebase, take the prefix from the shared library of each project and derive the necessary paths from it. The user can however overwrite this using the environment variables, and the configuration files. Signed-off-by: George Bosilca <[email protected]>
1 parent 9fbd849 commit 1ec7a3a

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Copyright (c) 2025 NVIDIA Corporation. All rights reserved.
3+
# $COPYRIGHT$
4+
#
5+
# Additional copyrights may follow
6+
#
7+
# $HEADER$
8+
#
9+
10+
noinst_LTLIBRARIES = libmca_installdirs_runtime.la
11+
12+
libmca_installdirs_runtime_la_SOURCES = \
13+
opal_installdirs_runtime.c
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- shell-script -*-
2+
#
3+
# Copyright (c) 2025 NVIDIA Corporation. All rights reserved.
4+
# $COPYRIGHT$
5+
#
6+
# Additional copyrights may follow
7+
#
8+
# $HEADER$
9+
#
10+
11+
AC_DEFUN([MCA_opal_installdirs_runtime_PRIORITY], [5])
12+
13+
AC_DEFUN([MCA_opal_installdirs_runtime_COMPILE_MODE], [
14+
AC_MSG_CHECKING([for MCA component $2:$3 compile mode])
15+
$4="static"
16+
AC_MSG_RESULT([$$4])
17+
])
18+
19+
# MCA_installdirs_config_CONFIG(action-if-can-compile,
20+
# [action-if-cant-compile])
21+
# ------------------------------------------------
22+
AC_DEFUN([MCA_opal_installdirs_runtime_CONFIG], [
23+
# Check if we are building a shared library or not. Disable if static
24+
AC_MSG_CHECKING([if shared libraries are enabled])
25+
AS_IF([test "$enable_shared" != "yes"],
26+
[installdirs_runtime_happy="no"],
27+
[installdirs_runtime_happy="yes"])
28+
AC_MSG_RESULT([$installdirs_runtime_happy])
29+
30+
# Check if dladdr is available
31+
AS_IF([test "$installdirs_runtime_happy" = "yes"],
32+
[AC_CHECK_HEADERS([dlfcn.h],
33+
[],
34+
[installdirs_runtime_happy="no"])])
35+
AS_IF([test "$installdirs_runtime_happy" = "yes"],
36+
[AC_CHECK_LIB([dl], [dladdr],
37+
[],
38+
[installdirs_runtime_happy="no"])
39+
])
40+
#
41+
AS_IF([test "$installdirs_runtime_happy" = "yes"],
42+
[AC_CONFIG_FILES([opal/mca/installdirs/runtime/Makefile])
43+
$1], [$2])
44+
])
45+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2006-2007 Los Alamos National Security, LLC. All rights
3+
* reserved.
4+
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
5+
* $COPYRIGHT$
6+
*
7+
* Additional copyrights may follow
8+
*
9+
* $HEADER$
10+
*/
11+
12+
#include "opal_config.h"
13+
14+
#include <stdlib.h>
15+
#include <string.h>
16+
17+
#include "opal/constants.h"
18+
#include "opal/mca/installdirs/installdirs.h"
19+
#include "opal/runtime/opal.h"
20+
21+
static int installdirs_runtime_open(void);
22+
23+
opal_installdirs_base_component_t mca_installdirs_runtime_component = {
24+
/* First, the mca_component_t struct containing meta information
25+
about the component itself */
26+
{OPAL_INSTALLDIRS_BASE_VERSION_2_0_0,
27+
28+
/* Component name and version */
29+
"runtime", OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION,
30+
31+
/* Component open and close functions */
32+
installdirs_runtime_open, NULL},
33+
{/* This component is checkpointable */
34+
MCA_BASE_METADATA_PARAM_CHECKPOINT},
35+
36+
/* Next the opal_install_dirs_t install_dirs_data information */
37+
{
38+
NULL,
39+
},
40+
};
41+
42+
#include <dlfcn.h>
43+
#include "opal/util/basename.h"
44+
45+
static int installdirs_runtime_open(void)
46+
{
47+
Dl_info info;
48+
void* opal_fct;
49+
50+
/* Casting from void* to fct pointer according to POSIX.1-2001 and POSIX.1-2008 */
51+
*(void **)&opal_fct = dlsym(RTLD_DEFAULT, "opal_init_util");
52+
53+
if( 0 == dladdr(opal_fct, &info) ) {
54+
/* Can't find the symbol */
55+
return OPAL_ERROR;
56+
}
57+
58+
char* dname = opal_dirname(info.dli_fname);
59+
char* prefix = opal_dirname(dname);
60+
free(dname);
61+
62+
mca_installdirs_runtime_component.install_dirs_data.prefix = prefix;
63+
64+
return OPAL_SUCCESS;
65+
}

0 commit comments

Comments
 (0)