about summary refs log tree commit diff
path: root/elf/dl-load.c
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2020-10-29 13:29:15 +0000
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2020-12-11 15:45:19 +0000
commit38a3836011f3fe3290a94ab136dcb5f3c5c9f4e2 (patch)
treeb5ae7f354ce486f1ffd69ab5c1a869be2580b1b4 /elf/dl-load.c
parent8b8f616e6a594b91d0afb152384bf2a9f72b7288 (diff)
downloadglibc-38a3836011f3fe3290a94ab136dcb5f3c5c9f4e2.tar.gz
glibc-38a3836011f3fe3290a94ab136dcb5f3c5c9f4e2.tar.xz
glibc-38a3836011f3fe3290a94ab136dcb5f3c5c9f4e2.zip
elf: Move note processing after l_phdr is updated
Program headers are processed in two pass: after the first pass
load segments are mmapped so in the second pass target specific
note processing logic can access the notes.

The second pass is moved later so various link_map fields are
set up that may be useful for note processing such as l_phdr.
The second pass should be before the fd is closed so that is
available.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'elf/dl-load.c')
-rw-r--r--elf/dl-load.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 9020f1646f..a21bdeb5c3 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1386,6 +1386,21 @@ cannot enable executable stack as shared object requires");
   if (l->l_tls_initimage != NULL)
     l->l_tls_initimage = (char *) l->l_tls_initimage + l->l_addr;
 
+  /* Process program headers again after load segments are mapped in
+     case processing requires accessing those segments.  Scan program
+     headers backward so that PT_NOTE can be skipped if PT_GNU_PROPERTY
+     exits.  */
+  for (ph = &l->l_phdr[l->l_phnum]; ph != l->l_phdr; --ph)
+    switch (ph[-1].p_type)
+      {
+      case PT_NOTE:
+	_dl_process_pt_note (l, &ph[-1]);
+	break;
+      case PT_GNU_PROPERTY:
+	_dl_process_pt_gnu_property (l, &ph[-1]);
+	break;
+      }
+
   /* We are done mapping in the file.  We no longer need the descriptor.  */
   if (__glibc_unlikely (__close_nocancel (fd) != 0))
     {