]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
cheri: elf: Turn l_addr back to ElfW(Addr)
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Wed, 7 Sep 2022 15:45:18 +0000 (16:45 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Wed, 12 Oct 2022 13:22:03 +0000 (14:22 +0100)
Pointers are no longer derived from l_addr, but l_map_start (RX) and
l_rw_start (RW) so it does not have to be a capability.

This also allows removing hacks where l_addr was derived from DDC.

elf/dl-map-segments.h
elf/dl-support.c
elf/do-rel.h
elf/dynamic-link.h
elf/rtld.c
include/link.h
sysdeps/aarch64/morello/dl-machine.h

index 4ba1c71c73e7b900c3c180d7ac4e4a506bb275cc..ce51585ce4e2abae8bf99a94611d4f7c67203dc4 100644 (file)
@@ -123,7 +123,7 @@ _dl_map_segments (struct link_map *l, int fd,
                                c->mapend))
            return N_("ELF load command address/offset not page-aligned");
           if (__glibc_unlikely
-              (__mprotect ((caddr_t) (l->l_addr + c->mapend),
+              (__mprotect ((caddr_t) dl_rx_ptr (l, c->mapend),
                            loadcmds[nloadcmds - 1].mapstart - c->mapend,
                            PROT_NONE) < 0))
             return DL_MAP_SEGMENTS_ERROR_MPROTECT;
@@ -146,14 +146,6 @@ _dl_map_segments (struct link_map *l, int fd,
       l->l_map_end = l->l_map_start + maplength;
       l->l_contiguous = !has_holes;
 
-      /* TODO: l_addr is 0 in an exe, but it should cover the load segments.  */
-      uintptr_t l_addr = 0;
-      unsigned long allocend = ALIGN_UP (loadcmds[nloadcmds - 1].allocend,
-                                        GLRO(dl_pagesize));
-      asm volatile ("cvtd %0, %x0" : "+r"(l_addr));
-      asm volatile ("scbnds %0, %0, %x1" : "+r"(l_addr) : "r"(allocend));
-      l->l_addr = l_addr;
-
       goto postmap;
     }
 #endif
@@ -167,7 +159,7 @@ _dl_map_segments (struct link_map *l, int fd,
     {
       if (c->dataend > c->mapstart
           /* Map the segment contents from the file.  */
-          && (__mmap ((void *) (l->l_addr + c->mapstart),
+          && (__mmap ((void *) dl_rx_ptr (l, c->mapstart),
                       c->dataend - c->mapstart, c->prot,
                       MAP_FIXED|MAP_COPY|MAP_FILE,
                       fd, c->mapoff)
@@ -198,7 +190,7 @@ _dl_map_segments (struct link_map *l, int fd,
              after the data mapped from the file.   */
          elfptr_t zero, zeroend, zeropage;
 
-          zero = l->l_addr + c->dataend;
+          zero = dl_rx_ptr (l, c->dataend);
           zeroend = l->l_addr + c->allocend;
           zeropage = ((zero + GLRO(dl_pagesize) - 1)
                       & ~(GLRO(dl_pagesize) - 1));
index 8551e18eb2b5a6263023303bd54db40cf2bb214e..ffc1d8d01b21c92ebff95b79c9149a2ff21f3dd0 100644 (file)
@@ -248,14 +248,6 @@ _dl_aux_init (ElfW(auxv_t) *av)
   GL(dl_sysinfo) = DL_SYSINFO_DEFAULT;
 #endif
 
-#ifdef __CHERI_PURE_CAPABILITY__
-  /* Base is 0 in non-pie static executable, but it needs to be a valid
-     capability. Use the zero capability instead of AT_BASE.  */
-  elfptr_t zerocap;
-  asm volatile ("cvtd %0,xzr" : "=r"(zerocap));
-  _dl_main_map.l_addr = zerocap;
-#endif
-
   _dl_auxv = av;
   dl_parse_auxv_t auxv_values;
   /* Use an explicit initialization loop here because memset may not
index 0a2eddf73710f4afa9e8d520e2f71e2519ec6ada..219fad23183979ec42b6d65e7e383049a2e4a175 100644 (file)
@@ -48,7 +48,7 @@ elf_dynamic_do_Rel (struct link_map *map, struct r_scope_elem *scope[],
   const ElfW(Rel) *relative = (const void *) reladdr;
   const ElfW(Rel) *r = relative + nrelative;
   const ElfW(Rel) *end = (const void *) (reladdr + relsize);
-  elfptr_t l_addr = map->l_addr;
+  ElfW(Addr) l_addr = map->l_addr;
   const ElfW(Sym) *const symtab
       = (const void *) D_PTR (map, l_info[DT_SYMTAB]);
 
index 86105714bbfa0fd4f8df120de4e516125aef7008..e189de49ebb94236e70ede888b2199f5cc23f117 100644 (file)
@@ -37,7 +37,7 @@ elf_machine_rel (struct link_map *map, struct r_scope_elem *scope[],
                 const struct r_found_version *version,
                 void *const reloc_addr, int skip_ifunc);
 static inline void __attribute__((always_inline))
-elf_machine_rel_relative (elfptr_t l_addr, const ElfW(Rel) *reloc,
+elf_machine_rel_relative (ElfW(Addr) l_addr, const ElfW(Rel) *reloc,
                          void *const reloc_addr);
 # endif
 # if ! ELF_MACHINE_NO_RELA
@@ -58,12 +58,12 @@ elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
 # if ELF_MACHINE_NO_RELA || defined ELF_MACHINE_PLT_REL
 static inline void __attribute__((always_inline))
 elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
-                     elfptr_t l_addr, const ElfW(Rel) *reloc,
+                     ElfW(Addr) l_addr, const ElfW(Rel) *reloc,
                      int skip_ifunc);
 # else
 static inline void __attribute__((always_inline))
 elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
-                     elfptr_t l_addr, const ElfW(Rela) *reloc,
+                     ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
                      int skip_ifunc);
 # endif
 #endif
index 82e40e82013ad0c3611fc22c1c3b72f6fae98ca3..753211772c8eb1d6c9de2014eee55dd9864e1c03 100644 (file)
@@ -553,7 +553,6 @@ _dl_start (void *arg)
 
 #ifdef __CHERI_PURE_CAPABILITY__
   elf_machine_rtld_base_setup (&bootstrap_map, arg);
-  bootstrap_map.l_addr = elf_machine_load_address_from_args (arg);
   bootstrap_map.l_ld = elf_machine_runtime_dynamic ();
 #else
   /* Figure out the run-time load address of the dynamic linker itself.  */
@@ -1172,10 +1171,6 @@ rtld_setup_main_map (struct link_map *main_map)
       case PT_PHDR:
        /* Find out the load address.  */
        main_map->l_addr = (elfptr_t) phdr - ph->p_vaddr;
-#ifdef __CHERI_PURE_CAPABILITY__
-       // TODO: we still need laddr
-       asm volatile ("cvtd %0, %x0" : "+r"(main_map->l_addr));
-#endif
        break;
       case PT_DYNAMIC:
        /* This tells us where to find the dynamic section,
index e1dca89762c45a96f792bb115f3c928a7ae084e5..67045a79ee13e9851398bf41a2408181005965fc 100644 (file)
@@ -97,7 +97,7 @@ struct link_map
   {
     /* These first few members are part of the protocol with the debugger.
        This is the same format used in SVR4.  */
-    elfptr_t l_addr;           /* Difference between the address in the ELF
+    ElfW(Addr) l_addr;         /* Difference between the address in the ELF
                                   file and the addresses in memory.  */
 
     char *l_name;              /* Absolute file name object was found in.  */
index 1ca4cd027707e75935aafcf30071b1b7097e1da7..5169a48fce027ab5d486c1f96b8fc51b9937fbaa 100644 (file)
@@ -440,7 +440,7 @@ elf_machine_rela_relative (struct link_map *map, const ElfW(Rela) *reloc)
 static inline void
 __attribute__ ((always_inline))
 elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
-                     uintptr_t l_addr,
+                     ElfW(Addr) l_addr,
                      const ElfW(Rela) *reloc,
                      int skip_ifunc)
 {