-
Notifications
You must be signed in to change notification settings - Fork 25
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: Add a COB_LOAD_GLOBAL config option to modify dlopen
behavior
#209
base: gcos4gnucobol-3.x
Are you sure you want to change the base?
WIP: Add a COB_LOAD_GLOBAL config option to modify dlopen
behavior
#209
Conversation
Apart from the other PR's review to that branch, the change here makes the current scenario even more confusing. After the changes:
@florianschmidt1994 can you please inspect the libtool variant (to test this you can simply undefine |
Yup, I'll check it out. Basically something like this, right? static void* cob_dlopen(const char* filename) {
#ifdef _WIN32
if (x == NULL) {
return GetModuleHandle (NULL);
}
return LoadLibrary(x);
#elif defined(USE_LIBDL)
int flags = cobsetptr->cob_load_global
? RTLD_LAZY | RTLD_GLOBAL
: RTLD_LAZY | RTLD_LOCAL;
return dlopen(filename, flags);
# else
// TODO: initialise lt_dladvise
lt_dlopenadvise(filename, /*advise here*/);
} |
@GitMensch I've tried out your suggestion in the latest commit and temporarily defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice update, we may be able to push that soon
Note: we still need the testcase addition - does not need to be something that benefit from this as this is hard to make portable - just do a simple CALL and CANCEL. We should have an easy one for COB_LOAD_CASE
libcob/call.c
Outdated
} | ||
|
||
void* handle = lt_dlopenadvise(filename, advise); | ||
lt_dladvise_destroy(&advise); // Clean up advise object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make the advise static and clean it up in call.c's cleanup function (depending on its preprocessor macro, of course), you can also init it in the init function - just set the advise flag here (the setting for both dlopen and lt_dlopen will be moved out to a config function later - you're welcome to add it (see screenio.c, this may be even explained in the video :-) and call it from the config side if this var or COB_LIBRARY_PATH was adjusted
f6aa350
to
ab26e16
Compare
AT_CLEANUP | ||
|
||
AT_SETUP([COB_LOAD_GLOBAL=false CALL/CANCEL still works]) | ||
AT_KEYWORDS([runmisc CALL CANCEL COB_LOAD_GLOBAL]) | ||
|
||
AT_DATA([CALLEE.cob], [ | ||
IDENTIFICATION DIVISION. | ||
PROGRAM-ID. callee. | ||
PROCEDURE DIVISION. | ||
EXIT PROGRAM. | ||
]) | ||
|
||
AT_DATA([caller.cob], [ | ||
IDENTIFICATION DIVISION. | ||
PROGRAM-ID. caller. | ||
PROCEDURE DIVISION. | ||
CALL "callee" | ||
END-CALL. | ||
CANCEL "callee". | ||
STOP RUN. | ||
]) | ||
|
||
AT_CHECK([$COMPILE_MODULE CALLEE.cob], [0], [], []) | ||
AT_CHECK([$COMPILE caller.cob], [0], [], []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After initial testing - please combine those tests into one, possibly named "CALL/CANCEL and COB_LOAD_GLOBAL"
This PR adds a config option called
COB_LOAD_GLOBAL
which allows the flags ofdlopen
used incall.c
to be changed betweenRTLD_GLOBAL
andRTLD_LOCAL
(see https://linux.die.net/man/3/dlopen)Motivation
This flag is motivated by an ambition to be able to write a multi-threaded c program, that then loads
libcob
withdlmopen
in one namespace per thread, effectively allowing us to call the same libcob / Cobol module from multiple threads in a "thread-safe" way. The image below shows the a very simplified intended call sequenceBecause there is a "bug" in dlopen that stops us from calling
dlopen("module", RTLD_GLOBAL)
, this PR introduces an option to be able to change this flag toRTLD_LOCAL
at runtime.Docs
Implementation
lt_dlopen
from a macro definition to an actual function, which internally calls dlopen with the flags based on the configuration