[v3,2/9] elf: Parse gnu properties for static linked binaries

Message ID 20240930200831.1669010-3-adhemerval.zanella@linaro.org
State New
Headers
Series Add support for memory sealing |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed

Commit Message

Adhemerval Zanella Netto Sept. 30, 2024, 8:08 p.m. UTC
  So the static binary can opt-in of memory sealing.

Checked on x86_64-linux-gnu.
---
 elf/dl-support.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
  

Patch

diff --git a/elf/dl-support.c b/elf/dl-support.c
index 451932dd03..bd02a77d1a 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -45,6 +45,7 @@ 
 #include <dl-find_object.h>
 #include <array_length.h>
 #include <dl-symbol-redir-ifunc.h>
+#include <dl-prop.h>
 
 extern char *__progname;
 char **_dl_argv = &__progname;	/* This is checked for some error messages.  */
@@ -334,6 +335,18 @@  _dl_non_dynamic_init (void)
 	_dl_main_map.l_relro_size = ph->p_memsz;
 	break;
       }
+  /* Process program headers again, but scan them backwards so
+     that PT_NOTE can be skipped if PT_GNU_PROPERTY exits.  */
+  for (const ElfW(Phdr) *ph = &_dl_phdr[_dl_phnum]; ph != _dl_phdr; --ph)
+    switch (ph[-1].p_type)
+      {
+      case PT_NOTE:
+	_dl_process_pt_note (&_dl_main_map, -1, &ph[-1]);
+	break;
+      case PT_GNU_PROPERTY:
+	_dl_process_pt_gnu_property (&_dl_main_map, -1, &ph[-1]);
+	break;
+      }
 
   call_function_static_weak (_dl_find_object_init);