Mark __tunables_init hidden and avoid PLT

Message ID 20170524191726.GA27395@lucon.org
State New, archived
Headers

Commit Message

Lu, Hongjiu May 24, 2017, 7:17 p.m. UTC
  Since __tunables_init is internal to ld.so, we should mark it hidden
to avoid PLT.  We should also avoid PLT when calling __tunable_set_val
within ld.so.

Any comments?

H.J.
---
	* elf/dl-tunables.c (__tunables_init): Mark hidden.
	(__rtld_tunable_set_val): Add a hidden alias for
	__tunable_set_val.
	* elf/dl-tunables.h (__tunables_init): Mark hidden.
	(__rtld_tunable_set_val): New.
	(DL_TUNABLE_SET_VAL): Likewise.
	(TUNABLE_SET_VAL): Replace __tunable_set_val with
	DL_TUNABLE_SET_VAL.
	(TUNABLE_SET_VAL_WITH_CALLBACK): Likewise.
---
 elf/dl-tunables.c |  5 +++++
 elf/dl-tunables.h | 16 +++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
  

Comments

Siddhesh Poyarekar May 25, 2017, 5:57 a.m. UTC | #1
On Thursday 25 May 2017 12:47 AM, H.J. Lu wrote:
> Since __tunables_init is internal to ld.so, we should mark it hidden
> to avoid PLT.  We should also avoid PLT when calling __tunable_set_val
> within ld.so.

We don't export __tunables_init, so it shouldn't have a PLT anyway.  As
for __tunable_set_val, I have it in my patch 3/5:

https://sourceware.org/ml/libc-alpha/2017-05/msg00654.html

which needs minor rework before pushing.

Siddhesh
  

Patch

diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
index 8d72e26..d6f3309 100644
--- a/elf/dl-tunables.c
+++ b/elf/dl-tunables.c
@@ -344,6 +344,7 @@  maybe_enable_malloc_check (void)
 /* Initialize the tunables list from the environment.  For now we only use the
    ENV_ALIAS to find values.  Later we will also use the tunable names to find
    values.  */
+__attribute__ ((visibility ("hidden")))
 void
 __tunables_init (char **envp)
 {
@@ -423,6 +424,10 @@  __tunables_init (char **envp)
     }
 }
 
+extern void __rtld_tunable_set_val (tunable_id_t, void *,
+				    tunable_callback_t)
+  __attribute__ ((alias ("__tunable_set_val"), visibility ("hidden")));
+
 /* Set the tunable value.  This is called by the module that the tunable exists
    in. */
 void
diff --git a/elf/dl-tunables.h b/elf/dl-tunables.h
index f33adfb..713a42e 100644
--- a/elf/dl-tunables.h
+++ b/elf/dl-tunables.h
@@ -66,14 +66,24 @@  typedef struct _tunable tunable_t;
 
 # include "dl-tunable-list.h"
 
-extern void __tunables_init (char **);
+extern void __tunables_init (char **)
+  __attribute__ ((visibility ("hidden")));
 extern void __tunable_set_val (tunable_id_t, void *, tunable_callback_t);
+extern void __rtld_tunable_set_val (tunable_id_t, void *, tunable_callback_t)
+  __attribute__ ((visibility ("hidden")));
+
+/* Avoid PLT when calling __tunable_set_val within ld.so.  */
+#if IS_IN (rtld)
+# define DL_TUNABLE_SET_VAL	__rtld_tunable_set_val
+#else
+# define DL_TUNABLE_SET_VAL	__tunable_set_val
+#endif
 
 /* Check if the tunable has been set to a non-default value and if it is, copy
    it over into __VAL.  */
 # define TUNABLE_SET_VAL(__id,__val) \
 ({									      \
-  __tunable_set_val							      \
+  DL_TUNABLE_SET_VAL							      \
    (TUNABLE_ENUM_NAME (TOP_NAMESPACE, TUNABLE_NAMESPACE, __id), (__val),      \
     NULL);								      \
 })
@@ -81,7 +91,7 @@  extern void __tunable_set_val (tunable_id_t, void *, tunable_callback_t);
 /* Same as TUNABLE_SET_VAL, but also call the callback function __CB.  */
 # define TUNABLE_SET_VAL_WITH_CALLBACK(__id,__val,__cb) \
 ({									      \
-  __tunable_set_val							      \
+  DL_TUNABLE_SET_VAL							      \
    (TUNABLE_ENUM_NAME (TOP_NAMESPACE, TUNABLE_NAMESPACE, __id), (__val),      \
     DL_TUNABLE_CALLBACK (__cb));					      \
 })