-
Notifications
You must be signed in to change notification settings - Fork 217
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
posix: Use RTLD_DEFAULT instead of NULL in dlsym #214
Comments
Imported from trac issue 191. Created by tflemin1 on 2017-10-30T14:12:36, last modified: 2019-08-14T14:11:46 |
Hello, I wanted to fix an issue but it seems this one is already fixed on line 102 of osloader.c: Is there anything else that needs to be done for this? |
Referenced code was refactored, current issue is at: osal/src/os/portable/os-impl-posix-dl.c Line 126 in 2284a6f
|
Note that this code is used by both RTEMS and POSIX, and (IIRC) RTEMS does not define the |
Well... it's used in src/os/rtems/osloader.c... Line 102 in 2284a6f
|
Doesn't look to me like rtems includes the portable version? |
Hmm, made the previous comment from memory without looking at the code .... All I can say is that there was some issue with using RTLD_DEFAULT across systems which is why it was hardcoded as NULL. |
Removing good first issue label (at least until a specific fix is identified.) Only posix osloader.c includes the os-impl-posix-dl.c. In the context of POSIX is it an issue due to RTLD_DEFAULT being "reserved", maybe there was a system on which it wasn't defined? Should we add an #ifndef RTLD_DEFAULT such that we use it when available and define if not? |
I want to say it is something like the symbol was only available when defining |
Took a closer look at this. I can confirm the reason that this is not using
When building with In contrast, regarding the RTEMS implementation, on that platform the It might make the most sense to just add an |
Sounds good, re-added the milestone as a target for my tracking, not critical though. |
See also this. There I had to use |
I think the approach proposed in the draft pull request should work on MacOS too, but I don't currently have a facility to test on this platform. RTEMS has a similar issue where NULL doesn't work - one must actually use RTLD_DEFAULT, but POSIX doesn't actually require the symbol, so hence the need for a conditional. One could make the case that we are actually invoking platform-defined behavior here by using NULL, as glibc considers |
It definitely should. I can try it later today and report the result. |
@jphickey the code from your draft works for me here: https://github.com/nasa/osal/pull/352/files#diff-ea89b73e0d390f934db08d14699de6a4R77. I also have to add this in order for some symbols including
otherwise I get:
|
Closed by #443 |
In {{{OS_SymbolLookup}}} defined in {{{osloader.c}}} in the POSIX OSAL, [http://pubs.opengroup.org/onlinepubs/9699919799/functions/dlsym.html dlsym] is used to obtain the address of the specified symbol:
{{{
Function = dlsym((void *)0, SymbolName);
}}}
The behavior of {{{dlsym}}} when called with a null pointer for the first argument is not defined by POSIX. On GNU/Linux, this value corresponds to {{{RTLD_DEFAULT}}}, as found in {{{/usr/include/dlfcn.h}}}.
{{{
define RTLD_DEFAULT ((void *) 0)
}}}
When called with {{{RTLD_DEFAULT}}} as a first argument, "The identifier lookup happens in the normal global scope; that is, a search for an identifier using handle would find the same definition as a direct use of this identifier in the program code." This appears to be the intended behavior in the OSAL.
However, the value of {{{RTLD_DEFAULT}}} is implementation-defined according to POSIX. The macro, rather than the value it happens to have on GNU/Linux, should be used.
This would address part of #203.
The text was updated successfully, but these errors were encountered: