-
Notifications
You must be signed in to change notification settings - Fork 902
Extract the install prefix from the shared library. #13147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bosilca
wants to merge
5
commits into
open-mpi:main
Choose a base branch
from
bosilca:topic/runtime_prefix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4c1847c
Extract the install prefix from the shared library.
bosilca f682f4e
Add a way to complain if install directories do not exists.
bosilca 3fab720
Move the install_dirs.h.in outside of the config component.
bosilca 76f3d0e
Propagate the user provided `--libdir` to the internal libevent
bosilca 5384920
Better prefix extraction
bosilca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# | ||
# Copyright (c) 2025 NVIDIA Corporation. All rights reserved. | ||
# $COPYRIGHT$ | ||
# | ||
# Additional copyrights may follow | ||
# | ||
# $HEADER$ | ||
# | ||
|
||
noinst_LTLIBRARIES = libmca_installdirs_runtime.la | ||
|
||
libmca_installdirs_runtime_la_SOURCES = \ | ||
opal_installdirs_runtime.c | ||
libmca_installdirs_runtime_la_CPPFLAGS = -DOPAL_LIB_NAME=\"@OPAL_LIB_NAME@\" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- shell-script -*- | ||
# | ||
# Copyright (c) 2025 NVIDIA Corporation. All rights reserved. | ||
# $COPYRIGHT$ | ||
# | ||
# Additional copyrights may follow | ||
# | ||
# $HEADER$ | ||
# | ||
|
||
AC_DEFUN([MCA_opal_installdirs_runtime_PRIORITY], [5]) | ||
|
||
AC_DEFUN([MCA_opal_installdirs_runtime_COMPILE_MODE], [ | ||
AC_MSG_CHECKING([for MCA component $2:$3 compile mode]) | ||
$4="static" | ||
AC_MSG_RESULT([$$4]) | ||
]) | ||
|
||
# MCA_installdirs_config_CONFIG(action-if-can-compile, | ||
# [action-if-cant-compile]) | ||
# ------------------------------------------------ | ||
AC_DEFUN([MCA_opal_installdirs_runtime_CONFIG], [ | ||
# Check if we are building a shared library or not. Disable if static | ||
AC_MSG_CHECKING([if shared libraries are enabled]) | ||
AS_IF([test "$enable_shared" != "yes"], | ||
[installdirs_runtime_happy="no"], | ||
[installdirs_runtime_happy="yes"]) | ||
AC_MSG_RESULT([$installdirs_runtime_happy]) | ||
|
||
# Check if dladdr is available | ||
AS_IF([test "$installdirs_runtime_happy" = "yes"], | ||
[AC_CHECK_HEADERS([dlfcn.h], | ||
[], | ||
[installdirs_runtime_happy="no"])]) | ||
AS_IF([test "$installdirs_runtime_happy" = "yes"], | ||
[AC_CHECK_LIB([dl], [dladdr], | ||
[], | ||
[installdirs_runtime_happy="no"]) | ||
]) | ||
# | ||
AS_IF([test "$installdirs_runtime_happy" = "yes"], | ||
[AC_CONFIG_FILES([opal/mca/installdirs/runtime/Makefile]) | ||
$1], [$2]) | ||
]) | ||
|
111 changes: 111 additions & 0 deletions
111
opal/mca/installdirs/runtime/opal_installdirs_runtime.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright (c) 2006-2007 Los Alamos National Security, LLC. All rights | ||
* reserved. | ||
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. | ||
* $COPYRIGHT$ | ||
* | ||
* Additional copyrights may follow | ||
* | ||
* $HEADER$ | ||
*/ | ||
|
||
#include "opal_config.h" | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "opal/constants.h" | ||
#include "opal/mca/installdirs/installdirs.h" | ||
#include "opal/runtime/opal.h" | ||
|
||
static int installdirs_runtime_open(void); | ||
|
||
opal_installdirs_base_component_t mca_installdirs_runtime_component = { | ||
/* First, the mca_component_t struct containing meta information | ||
about the component itself */ | ||
{OPAL_INSTALLDIRS_BASE_VERSION_2_0_0, | ||
|
||
/* Component name and version */ | ||
"runtime", OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION, OPAL_RELEASE_VERSION, | ||
|
||
/* Component open and close functions */ | ||
installdirs_runtime_open, NULL}, | ||
{/* This component is checkpointable */ | ||
MCA_BASE_METADATA_PARAM_CHECKPOINT}, | ||
|
||
/* Next the opal_install_dirs_t install_dirs_data information */ | ||
{ | ||
NULL, | ||
}, | ||
}; | ||
|
||
#include <dlfcn.h> | ||
#include "opal/util/basename.h" | ||
#include "opal/mca/installdirs/install_dirs.h" | ||
|
||
/** | ||
* We are trying to solve a particular use case here, when the entire install tree | ||
* of Open MPI (and its dependencies) has been moved into another location. Nothing | ||
* fancy, the entire install tree has maintained his shape but changed the prefix. | ||
*/ | ||
static int installdirs_runtime_open(void) | ||
{ | ||
Dl_info info; | ||
void* opal_fct; | ||
char* libname = NULL; | ||
const char* base_prefix_path = OPAL_LIBDIR; | ||
|
||
/* Casting from void* to fct pointer according to POSIX.1-2001 and POSIX.1-2008 */ | ||
*(void **)&opal_fct = dlsym(RTLD_DEFAULT, "opal_init_util"); | ||
|
||
if( 0 == dladdr(opal_fct, &info) ) { | ||
goto bail_out_with_no_data; | ||
} | ||
|
||
/* If this build was both static and shared then this compoenent will be build and will exists | ||
* even in the static library. We need to prevent setting a prefix for the OMPI library that | ||
* is actually the application path. Check, if the name points to a library. | ||
*/ | ||
libname = opal_basename(info.dli_fname); | ||
if( strncmp(libname, "lib", 3)) { /* not a shared library */ | ||
base_prefix_path = OPAL_BINDIR; | ||
} else { | ||
#if defined(OPAL_LIB_NAME) | ||
/* Extra check using the installed name of the OPAL library */ | ||
if( strncmp(libname+3, OPAL_LIB_NAME, strlen(OPAL_LIB_NAME)) ) { /* not a shared library */ | ||
goto bail_out_with_no_data; | ||
} | ||
#endif /* defined(OPAL_LIB_NAME) */ | ||
} | ||
/* Remove the shared library name and it's first dirname to obtain a prefix. This | ||
* is true in most cases, especially when the install directory was just moved | ||
* moved around, but it is not necessarily always true. | ||
*/ | ||
char *prefix = NULL, *dname = opal_dirname(info.dli_fname); | ||
int dname_idx = strlen(dname), dname_token = dname_idx; | ||
for( int i = strlen(base_prefix_path); (i > 0) && (dname_idx > 0); i-- ) { | ||
if( dname[dname_idx] != base_prefix_path[i] ) { | ||
dname[dname_token] = '\0'; | ||
prefix = dname; | ||
dname = NULL; /* the string is now attached to the component, prevent it from being freed */ | ||
break; | ||
} | ||
if( dname[dname_idx] == OPAL_PATH_SEP[0] ) | ||
dname_token = dname_idx; | ||
dname_idx--; | ||
} | ||
|
||
mca_installdirs_runtime_component.install_dirs_data.prefix = prefix; | ||
|
||
/* If we goto here, there is some error. Unfortunately, we can't return an error from | ||
* this function, the MCA infrastructure is not yet completely setup, and a call to | ||
* mca_base_component_close will break. | ||
* So, return success but provide no meaningfull data in the component. | ||
*/ | ||
bail_out_with_no_data: | ||
|
||
free(libname); | ||
free(dname); | ||
|
||
return OPAL_SUCCESS; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# | ||
# owner/status file | ||
# owner: institution that is responsible for this package | ||
# status: e.g. active, maintenance, unmaintained | ||
# | ||
owner: NVIDIA | ||
status: active |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.