Skip to content
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

WIP: Feature/add dlopen config flag #1

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/runtime.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@
# Default: false
# Example: PHYSICAL_CANCEL TRUE

# Environment name: COB_LOAD_GLOBAL
# Parameter name: load_global
# Purpose: tell the system loader to provide symbols in CALLed
# programs globally, allowing symbols to be found for linked
# libraries later
# Type: boolean
# Note: COBOL CALLs will always find symbols in already CALLed or
# pre-modules; this setting is mostly an advise to the system,
# not all systems are capable of loading libraries global/local
# Default: false
# Example: load_global true

#
## File I/O
#
Expand Down
17 changes: 15 additions & 2 deletions libcob/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ FILE *fmemopen (void *buf, size_t size, const char *mode);
https://wiki.musl-libc.org/functional-differences-from-glibc.html#Unloading_libraries
*/

static cob_settings *cobsetptr = NULL;

#ifdef _WIN32

#define WIN32_LEAN_AND_MEAN
Expand Down Expand Up @@ -106,14 +108,26 @@ lt_dlerror (void)
/* note: only defined in configure when HAVE_DLFCN_H is true and dlopen can be linked */
#include <dlfcn.h>

#define lt_dlopen(x) dlopen(x, RTLD_LAZY | RTLD_GLOBAL)
#define lt_dlsym(x,y) dlsym(x, y)
#define lt_dlclose(x) dlclose(x)
#define lt_dlerror() dlerror()
#define lt_dlinit()
#define lt_dlexit()
#define lt_dlhandle void *

void* lt_dlopen(const char* filename) {

if (cobsetptr == NULL || cobsetptr->cob_load_global == NULL) {
// TODO: What to do when cobsetptr is null?
}

if (cobsetptr->cob_load_global) {
return dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
} else {
return dlopen(filename, RTLD_LAZY | RTLD_GLOBAL);
}
}

#else

#include <ltdl.h>
Expand Down Expand Up @@ -158,7 +172,6 @@ static struct struct_handle *base_preload_ptr;
static struct struct_handle *base_dynload_ptr;

static cob_global *cobglobptr = NULL;
static cob_settings *cobsetptr = NULL;

static char **resolve_path;
static char *resolve_error;
Expand Down
2 changes: 2 additions & 0 deletions libcob/coblocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ typedef struct __cob_settings {
unsigned int cob_core_on_error; /* signal handling and possible raise of SIGABRT
/ creation of coredumps on runtime errors */
char *cob_core_filename; /* filename for coredump creation */

int cob_load_global; /* Wether dlopen should use the global or local namespace */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a setting from call.c, so move up before name_convert and as it is a plain boolean change its type to unsigned int

} cob_settings;


Expand Down
3 changes: 3 additions & 0 deletions libcob/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ static struct config_tbl gc_conf[] = {
#ifdef _WIN32
/* checked before configuration load if set from environment in cob_common_init() */
{"COB_UNIX_LF", "unix_lf", "0", NULL, GRP_FILE, ENV_BOOL, SETPOS (cob_unix_lf)},
#endif
#ifndef _WIN32
{"COB_LOAD_GLOBAL", "load_global", "1", NULL, GRP_CALL, ENV_BOOL, SETPOS(cob_load_global)},
#endif
{"USERNAME", "username", NULL, NULL, GRP_SYSENV, ENV_STR, SETPOS (cob_user_name)}, /* default set in cob_init() */
{"LOGNAME", "logname", NULL, NULL, GRP_HIDE, ENV_STR, SETPOS (cob_user_name)},
Expand Down