From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id 4420A3856DC2; Wed, 12 Oct 2022 14:18:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4420A3856DC2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665584297; bh=SiumJ6r+F8GK62Yhto8Jrd1AYpxxcy4uEqZSzEJdZ6s=; h=From:To:Subject:Date:From; b=wqkLDGCDkm+ri1vbKIj/ME6WVNPMXgaM4fHAB1HHEMyzK1P2ggU7mrIu0jww4jfqr dG2C7qmzztJUbA2pjEmjY28vKT44bNY8LbSTEtemGmkBAmcoVt2/8eR95FQpfuD50M pbRqHakdIxGpXHJmM3HA1tw73Y6Eb4O0iphWavv8= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Szabolcs Nagy To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] cheri: elf: Turn l_addr back to ElfW(Addr) X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: 9c11d64d6d6fcd5ef2fc1acb623744ab6f7099b5 X-Git-Newrev: 4d7cf069eea6761b9ffceaac6a8be2ad970f4413 Message-Id: <20221012141817.4420A3856DC2@sourceware.org> Date: Wed, 12 Oct 2022 14:18:17 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=4d7cf069eea6761b9ffceaac6a8be2ad970f4413 commit 4d7cf069eea6761b9ffceaac6a8be2ad970f4413 Author: Szabolcs Nagy 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) {