-
Notifications
You must be signed in to change notification settings - Fork 30
Add a COB_LOAD_GLOBAL config option to modify dlopen
behavior
#209
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
base: gcos4gnucobol-3.x
Are you sure you want to change the base?
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
f6aa350
to
ab26e16
Compare
When developing, I've noticed some test failures, where some of them might be related to our change. On the latest commit of this repositories "main branch" (
In the first version of this PR (bd80e8c), there is an additional test failure (781) when using
In history up to the latest commit (62de625), there exists a fix (see 1f4d607), the same that is already applied in WIN32 environments, to fix this.
|
dlopen
behaviordlopen
behavior
using the more important part "default changed" first, more explanation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## gcos4gnucobol-3.x #209 +/- ##
=====================================================
- Coverage 67.85% 67.58% -0.28%
=====================================================
Files 33 33
Lines 60458 60827 +369
Branches 15821 15896 +75
=====================================================
+ Hits 41026 41109 +83
- Misses 13567 13847 +280
- Partials 5865 5871 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
8871e45
to
3234374
Compare
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.
I hope to reinspect that PR soon, ideally after looking over CANCEL in general.
Can you please do the minor and cosmetic changes outlined in this review and rebase afterwards?
@@ -87,6 +87,12 @@ NEWS - user visible changes -*- outline -*- | |||
$b for executable basename, $d for date in YYYYMMDD format, $t for time | |||
in HHMMSS format (before, only $$ was available for pid) | |||
|
|||
** introduction of the COB_LOAD_GLOBAL boolean flag, which determines whether |
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.
that's a text block with sentences, which needs to start upper-case; but maybe go with a short entry as text, then a double-colon and newline, then more explanatory text (this could stay as sentences) afterwards, in any case the full-stops should be outside of the quotes :-)
2024-12-16 Simon Sobisch <[email protected]> | ||
|
||
* config/runtime.cfg: Add documentation for COB_LOAD_GLOBAL flag | ||
|
||
2024-08-17 Ammar Almoris <[email protected]> |
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.
oops: after the date (also applies to the next entry) there should be two spaces, not one; and "add" should be lower-cased and may be shorted as "add COB_LOAD_GLOBAL"
} | ||
return LoadLibrary(filename); | ||
#elif defined(USE_LIBDL) | ||
int flags = cobsetptr->cob_load_global |
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.
should be const int
} else { | ||
error = lt_dladvise_local(&advise); | ||
} |
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.
use tab instead of space to indent, please leave a space before opening parenthesis
void* handle = lt_dlopenadvise(filename, advise); | ||
return handle; |
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.
declarations are only allowed at the start of the block with C89, but that isn't really needed here either - just do the same as above, directly return
the function call's result
AT_CHECK([COB_LOAD_GLOBAL=true ./caller], [0], [], []) | ||
AT_CHECK([COB_LOAD_GLOBAL=false ./caller], [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.
Both lines should also use $COBCRUN_DIRECT
(the test above that you've copied from misses this also, so please adjust there as well).
AT_CHECK([$COMPILE caller.cob], [0], [], []) | ||
AT_CHECK([COB_LOAD_GLOBAL=true ./caller], [0], [], []) | ||
AT_CHECK([COB_LOAD_GLOBAL=false ./caller], [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.
Can you please add both COB_LOAD_GLOBAL options (and its name to the keyword) for the pre-load test to have that covered as well?
# 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, |
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.
should be "pre-loaded modules"
@@ -289,6 +283,37 @@ static int last_entry_is_working_directory (const char *buff, const char *pstr) | |||
return 0; | |||
} | |||
|
|||
static void* cob_dlopen(const char* filename) { | |||
#ifdef _WIN32 |
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.
because of the #elif
below, please use #if defined (_WIN32)
here
|
||
return dlopen(filename, flags); | ||
#else | ||
if (advise != NULL) { |
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.
advise is global, so only set if the "last set" variant is different to the current one - you can store the last used cob_load_global as a static var within this function for that
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