linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dlsym.3: Extend discussion of NULL symbol values
@ 2020-05-16 10:02 Alexander Monakov
  2020-05-19 20:21 ` Michael Kerrisk (man-pages)
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Monakov @ 2020-05-16 10:02 UTC (permalink / raw)
  To: mtk.manpages; +Cc: linux-man, Alexander Monakov

Avoid implying that use of IFUNC is the only way to produce a symbol
with NULL value. Give more scenarios how a symbol may get NULL value,
but explain that in those scenarios dlsym will fail with Glibc ld.so
due to an implementation inconsistency.

Signed-off-by: Alexander Monakov <amonakov@ispras.ru>
---
Hello!

Michael, in
https://stackoverflow.com/questions/13941944/why-can-the-value-of-the-symbol-returned-by-dlsym-be-null
you're in agreement with Petr Skocik that dlsym failure on NULL absolute symbols
is a Glibc bug. I'm also in agreement.

In any case, current wording implies that apart from IFUNC there's no way a
symbol will have NULL value, which is not true: the symbol may have NULL value,
only it can't be looked up via dlsym. This patch clarifies the situation.

Thanks.
Alexander


 man3/dlsym.3 | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/man3/dlsym.3 b/man3/dlsym.3
index 8a1ae7789..5ea151209 100644
--- a/man3/dlsym.3
+++ b/man3/dlsym.3
@@ -143,16 +143,22 @@ The
 .BR dlvsym ()
 function is a GNU extension.
 .SH NOTES
-The value of a symbol returned by
+There are several scenarios when the address of a global symbol is NULL.
+For example, a symbol can be placed at zero address by the linker, via
+a linker script or with
+.I --defsym
+command-line option. Undefined weak symbols also have NULL value.
+Finally, the symbol value may be the result of
+a GNU indirect function (IFUNC) resolver function that returns
+NULL as the resolved value. In the latter case,
 .BR dlsym ()
-will never be NULL if the shared object is the result of normal compilation,
-since a global symbol is never placed at the NULL address.
-There are nevertheless cases where a lookup using
+also returns NULL without error. However, in the former two cases, the
+behavior of GNU dynamic linker is inconsistent: relocation processing
+succeeds and the symbol can be observed to have NULL value, but
 .BR dlsym ()
-may return NULL as the value of a symbol.
-For example, the symbol value may be the result of
-a GNU indirect function (IFUNC) resolver function that returns
-NULL as the resolved value.
+fails and
+.BR dlerror ()
+indicates a lookup error.
 .\"
 .SS History
 The
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] dlsym.3: Extend discussion of NULL symbol values
  2020-05-16 10:02 [PATCH] dlsym.3: Extend discussion of NULL symbol values Alexander Monakov
@ 2020-05-19 20:21 ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-05-19 20:21 UTC (permalink / raw)
  To: Alexander Monakov; +Cc: mtk.manpages, linux-man

Hello Alexander,

On 5/16/20 12:02 PM, Alexander Monakov wrote:
> Avoid implying that use of IFUNC is the only way to produce a symbol
> with NULL value. Give more scenarios how a symbol may get NULL value,
> but explain that in those scenarios dlsym will fail with Glibc ld.so
> due to an implementation inconsistency.
> 
> Signed-off-by: Alexander Monakov <amonakov@ispras.ru>

Thanks for the nicely written patch! Applied.

Cheers,

Michael

> ---
> Hello!
> 
> Michael, in
> https://stackoverflow.com/questions/13941944/why-can-the-value-of-the-symbol-returned-by-dlsym-be-null
> you're in agreement with Petr Skocik that dlsym failure on NULL absolute symbols
> is a Glibc bug. I'm also in agreement.
> 
> In any case, current wording implies that apart from IFUNC there's no way a
> symbol will have NULL value, which is not true: the symbol may have NULL value,
> only it can't be looked up via dlsym. This patch clarifies the situation.
> 
> Thanks.
> Alexander
> 
> 
>  man3/dlsym.3 | 22 ++++++++++++++--------
>  1 file changed, 14 insertions(+), 8 deletions(-)
> 
> diff --git a/man3/dlsym.3 b/man3/dlsym.3
> index 8a1ae7789..5ea151209 100644
> --- a/man3/dlsym.3
> +++ b/man3/dlsym.3
> @@ -143,16 +143,22 @@ The
>  .BR dlvsym ()
>  function is a GNU extension.
>  .SH NOTES
> -The value of a symbol returned by
> +There are several scenarios when the address of a global symbol is NULL.
> +For example, a symbol can be placed at zero address by the linker, via
> +a linker script or with
> +.I --defsym
> +command-line option. Undefined weak symbols also have NULL value.
> +Finally, the symbol value may be the result of
> +a GNU indirect function (IFUNC) resolver function that returns
> +NULL as the resolved value. In the latter case,
>  .BR dlsym ()
> -will never be NULL if the shared object is the result of normal compilation,
> -since a global symbol is never placed at the NULL address.
> -There are nevertheless cases where a lookup using
> +also returns NULL without error. However, in the former two cases, the
> +behavior of GNU dynamic linker is inconsistent: relocation processing
> +succeeds and the symbol can be observed to have NULL value, but
>  .BR dlsym ()
> -may return NULL as the value of a symbol.
> -For example, the symbol value may be the result of
> -a GNU indirect function (IFUNC) resolver function that returns
> -NULL as the resolved value.
> +fails and
> +.BR dlerror ()
> +indicates a lookup error.
>  .\"
>  .SS History
>  The
> 


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-19 20:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-16 10:02 [PATCH] dlsym.3: Extend discussion of NULL symbol values Alexander Monakov
2020-05-19 20:21 ` Michael Kerrisk (man-pages)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).