diff mbox series

[2/3,RFC] elf: hack up tunables to avoid RELATIVE relocs

Message ID a44d4bd92dfb2ee9a6fac64a6d6b726421c5e07d.1610016590.git.szabolcs.nagy@arm.com
State Superseded
Headers show
Series fix ifunc with static pie [BZ #27072] | expand

Commit Message

Szabolcs Nagy Jan. 7, 2021, 11:01 a.m. UTC
With static pie linking pointers in the tunables list need
RELATIVE relocs since the absolute address is not known at
link time.

This is a hack to avoid relocs in tunables so the static pie
self relocation can be done later.

The longest tunable name is currently
  glibc.elision.skip_trylock_internal_abort
and the longest env var alias is
  MALLOC_MMAP_THRESHOLD_
There are likely ways to have a compact pointer-free tunable
list data structure with more gen-tunables.awk changes, but
before that i would like to get feedback if this approach
for bug 27072 is acceptable.
---
 elf/dl-tunables.h        | 4 ++--
 scripts/gen-tunables.awk | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

Comments

Siddhesh Poyarekar Jan. 7, 2021, 1:50 p.m. UTC | #1
On 1/7/21 4:31 PM, Szabolcs Nagy via Libc-alpha wrote:
> With static pie linking pointers in the tunables list need
> RELATIVE relocs since the absolute address is not known at
> link time.
> 
> This is a hack to avoid relocs in tunables so the static pie
> self relocation can be done later.
> 
> The longest tunable name is currently
>    glibc.elision.skip_trylock_internal_abort
> and the longest env var alias is
>    MALLOC_MMAP_THRESHOLD_
> There are likely ways to have a compact pointer-free tunable
> list data structure with more gen-tunables.awk changes, but
> before that i would like to get feedback if this approach
> for bug 27072 is acceptable.

I think this is a good idea independently of the rest of the patchset. 
The only change I'd like is to make name 64 bytes and env_alias 24 
bytes.  We don't have any additional environment variables to convert 
into tunables, so the max length of MALLOC_MMAP_THRESHOLD_ is about as 
big as it can get.

Siddhesh
diff mbox series

Patch

diff --git a/elf/dl-tunables.h b/elf/dl-tunables.h
index 518342a300..0196867676 100644
--- a/elf/dl-tunables.h
+++ b/elf/dl-tunables.h
@@ -38,7 +38,7 @@  __tunables_init (char **unused __attribute__ ((unused)))
 /* A tunable.  */
 struct _tunable
 {
-  const char *name;			/* Internal name of the tunable.  */
+  const char name[48];			/* Internal name of the tunable.  */
   tunable_type_t type;			/* Data type of the tunable.  */
   tunable_val_t val;			/* The value.  */
   bool initialized;			/* Flag to indicate that the tunable is
@@ -54,7 +54,7 @@  struct _tunable
 					   target module if the value is
 					   considered unsafe.  */
   /* Compatibility elements.  */
-  const char *env_alias;		/* The compatibility environment
+  const char env_alias[32];		/* The compatibility environment
 					   variable name.  */
 };
 
diff --git a/scripts/gen-tunables.awk b/scripts/gen-tunables.awk
index 622199061a..9e7bd24e13 100644
--- a/scripts/gen-tunables.awk
+++ b/scripts/gen-tunables.awk
@@ -57,7 +57,7 @@  $1 == "}" {
       maxvals[top_ns,ns,tunable] = max_of[types[top_ns,ns,tunable]]
     }
     if (!env_alias[top_ns,ns,tunable]) {
-      env_alias[top_ns,ns,tunable] = "NULL"
+      env_alias[top_ns,ns,tunable] = "{0}"
     }
     if (!security_level[top_ns,ns,tunable]) {
       security_level[top_ns,ns,tunable] = "SXID_ERASE"