Improve RUBY_GC_LIBRARY

Instead of passing the full GC SO file name to RUBY_GC_LIBRARY, we now
only need to pass the GC name.

For example, before we needed to pass `RUBY_GC_LIBRARY=librubygc.default.so`
but now we only need to pass `RUBY_GC_LIBRARY=default`.
This commit is contained in:
Peter Zhu 2024-10-10 11:09:53 -04:00
parent 047a7750d1
commit d641b7d172
Notes: git 2024-10-11 12:56:55 +00:00
3 changed files with 19 additions and 7 deletions

View File

@ -99,7 +99,7 @@ jobs:
- name: Build shared GC
run: |
echo "RUBY_GC_LIBRARY=librubygc.default.so" >> $GITHUB_ENV
echo "RUBY_GC_LIBRARY=default" >> $GITHUB_ENV
make shared-gc SHARED_GC=default
if: ${{ matrix.shared_gc }}

View File

@ -3403,6 +3403,8 @@ AC_DEFINE_UNQUOTED(DLEXT_MAXLEN, `expr $len + 1`)
test ".$DLEXT" = "." || AC_DEFINE_UNQUOTED(DLEXT, ".$DLEXT")
AC_SUBST(DLEXT)
AC_DEFINE_UNQUOTED(SOEXT, ".$SOEXT")
: "strip" && {
AC_MSG_CHECKING([for $STRIP flags])
AC_LINK_IFELSE([AC_LANG_PROGRAM], [AS_IF(

22
gc.c
View File

@ -659,7 +659,7 @@ ruby_external_gc_init(void)
char *gc_so_path = NULL;
void *handle = NULL;
if (gc_so_file) {
/* Check to make sure that gc_so_file matches /[\w-_.]+/ so that it does
/* Check to make sure that gc_so_file matches /[\w-_]+/ so that it does
* not load a shared object outside of the directory. */
for (size_t i = 0; i < strlen(gc_so_file); i++) {
char c = gc_so_file[i];
@ -667,17 +667,27 @@ ruby_external_gc_init(void)
switch (c) {
case '-':
case '_':
case '.':
break;
default:
fprintf(stderr, "Only alphanumeric, dash, underscore, and period is allowed in "RUBY_GC_LIBRARY"\n");
fprintf(stderr, "Only alphanumeric, dash, and underscore is allowed in "RUBY_GC_LIBRARY"\n");
exit(1);
}
}
gc_so_path = alloca(strlen(SHARED_GC_DIR) + strlen(gc_so_file) + 1);
strcpy(gc_so_path, SHARED_GC_DIR);
strcpy(gc_so_path + strlen(SHARED_GC_DIR), gc_so_file);
size_t gc_so_path_size = strlen(SHARED_GC_DIR "librubygc." SOEXT) + strlen(gc_so_file) + 1;
gc_so_path = alloca(gc_so_path_size);
{
size_t gc_so_path_idx = 0;
#define GC_SO_PATH_APPEND(str) do { \
gc_so_path_idx += strlcpy(gc_so_path + gc_so_path_idx, str, gc_so_path_size - gc_so_path_idx); \
} while (0)
GC_SO_PATH_APPEND(SHARED_GC_DIR);
GC_SO_PATH_APPEND("librubygc.");
GC_SO_PATH_APPEND(gc_so_file);
GC_SO_PATH_APPEND(SOEXT);
GC_ASSERT(gc_so_path_idx == gc_so_path_size - 1);
#undef GC_SO_PATH_APPEND
}
handle = dlopen(gc_so_path, RTLD_LAZY | RTLD_GLOBAL);
if (!handle) {