[RFC,v1,2/5] include/link.h: Update the link_map struct to allow clones

Message ID 20180516171124.24962-3-vivek@collabora.com
State New
Headers show
Series
  • Proof-of-Concept implementation of RTLD_SHARED for dlmopen
Related show

Commit Message

Vivek Das Mohapatra May 16, 2018, 5:11 p.m.
From: Vivek Das Mohapatra <vivek@collabora.co.uk>

We already have an l_real pointer, used for a similar purpose by
the linker for copies of ld.so in secondary namespaces. Update its
documentation and add a bitfield to indicate when link_map entry
is a clone.
---
 include/link.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Carlos O'Donell May 18, 2018, 6:47 p.m. | #1
On 05/16/2018 01:11 PM, Vivek Das Mohapatra wrote:
> From: Vivek Das Mohapatra <vivek@collabora.co.uk>
> 
> We already have an l_real pointer, used for a similar purpose by
> the linker for copies of ld.so in secondary namespaces. Update its
> documentation and add a bitfield to indicate when link_map entry
> is a clone.

I would avoid calling this a "clone" because it implies a direct
copy that is mutable.

This is just bikeshedding but I think 'l_proxy' might be more accurate?

That way we can talk about inserting a proxy object into a namespace
and know that the proxy is just that, a thin proxy which points to
complete link map.

> ---
>  include/link.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/include/link.h b/include/link.h
> index 5924594548..e051b5cd36 100644
> --- a/include/link.h
> +++ b/include/link.h
> @@ -104,8 +104,9 @@ struct link_map
>         They may change without notice.  */
>  
>      /* This is an element which is only ever different from a pointer to
> -       the very same copy of this type for ld.so when it is used in more
> -       than one namespace.  */
> +       the very same copy of this type when:
> +       - A shallow copy of ld.so is placed in namespaces other than LM_ID_BASE.
> +       - An object is cloned into a namespace by dlmopen with RTLD_SHARED.  */

OK.

>      struct link_map *l_real;
>  
>      /* Number of the namespace this link map belongs to.  */
> @@ -177,6 +178,7 @@ struct link_map
>      unsigned int l_relocated:1;	/* Nonzero if object's relocations done.  */
>      unsigned int l_init_called:1; /* Nonzero if DT_INIT function called.  */
>      unsigned int l_global:1;	/* Nonzero if object in _dl_global_scope.  */
> +    unsigned int l_clone:1;    /* Nonzero if object is a clone.  */

Suggest l_proxy:1;  /* Nonzero if object is a proxy.  */

>      unsigned int l_reserved:2;	/* Reserved for internal use.  */
>      unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed
>  					to by `l_phdr' is allocated.  */
>
Vivek Das Mohapatra May 18, 2018, 7:32 p.m. | #2
> This is just bikeshedding but I think 'l_proxy' might be more accurate?

Sounds good. I initially named it clone before I'd fully dug into
the implementation details.

> That way we can talk about inserting a proxy object into a namespace
> and know that the proxy is just that, a thin proxy which points to
> complete link map.

Sounds good to me.

Patch

diff --git a/include/link.h b/include/link.h
index 5924594548..e051b5cd36 100644
--- a/include/link.h
+++ b/include/link.h
@@ -104,8 +104,9 @@  struct link_map
        They may change without notice.  */
 
     /* This is an element which is only ever different from a pointer to
-       the very same copy of this type for ld.so when it is used in more
-       than one namespace.  */
+       the very same copy of this type when:
+       - A shallow copy of ld.so is placed in namespaces other than LM_ID_BASE.
+       - An object is cloned into a namespace by dlmopen with RTLD_SHARED.  */
     struct link_map *l_real;
 
     /* Number of the namespace this link map belongs to.  */
@@ -177,6 +178,7 @@  struct link_map
     unsigned int l_relocated:1;	/* Nonzero if object's relocations done.  */
     unsigned int l_init_called:1; /* Nonzero if DT_INIT function called.  */
     unsigned int l_global:1;	/* Nonzero if object in _dl_global_scope.  */
+    unsigned int l_clone:1;    /* Nonzero if object is a clone.  */
     unsigned int l_reserved:2;	/* Reserved for internal use.  */
     unsigned int l_phdr_allocated:1; /* Nonzero if the data structure pointed
 					to by `l_phdr' is allocated.  */