public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/arm/morello/main] cheri: elf: Turn l_addr back to ElfW(Addr)
@ 2022-10-12 14:18 Szabolcs Nagy
  0 siblings, 0 replies; only message in thread
From: Szabolcs Nagy @ 2022-10-12 14:18 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=4d7cf069eea6761b9ffceaac6a8be2ad970f4413

commit 4d7cf069eea6761b9ffceaac6a8be2ad970f4413
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Sep 7 16:45:18 2022 +0100

    cheri: elf: Turn l_addr back to ElfW(Addr)
    
    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.

Diff:
---
 elf/dl-map-segments.h                | 14 +++-----------
 elf/dl-support.c                     |  8 --------
 elf/do-rel.h                         |  2 +-
 elf/dynamic-link.h                   |  6 +++---
 elf/rtld.c                           |  5 -----
 include/link.h                       |  2 +-
 sysdeps/aarch64/morello/dl-machine.h |  2 +-
 7 files changed, 9 insertions(+), 30 deletions(-)

diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h
index 4ba1c71c73..ce51585ce4 100644
--- a/elf/dl-map-segments.h
+++ b/elf/dl-map-segments.h
@@ -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));
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 8551e18eb2..ffc1d8d01b 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -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
diff --git a/elf/do-rel.h b/elf/do-rel.h
index 0a2eddf737..219fad2318 100644
--- a/elf/do-rel.h
+++ b/elf/do-rel.h
@@ -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]);
 
diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h
index 86105714bb..e189de49eb 100644
--- a/elf/dynamic-link.h
+++ b/elf/dynamic-link.h
@@ -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
diff --git a/elf/rtld.c b/elf/rtld.c
index 82e40e8201..753211772c 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -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,
diff --git a/include/link.h b/include/link.h
index e1dca89762..67045a79ee 100644
--- a/include/link.h
+++ b/include/link.h
@@ -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.  */
diff --git a/sysdeps/aarch64/morello/dl-machine.h b/sysdeps/aarch64/morello/dl-machine.h
index 1ca4cd0277..5169a48fce 100644
--- a/sysdeps/aarch64/morello/dl-machine.h
+++ b/sysdeps/aarch64/morello/dl-machine.h
@@ -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)
 {

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-12 14:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12 14:18 [glibc/arm/morello/main] cheri: elf: Turn l_addr back to ElfW(Addr) Szabolcs Nagy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).