From patchwork Thu Jun 30 16:28:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 642682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rgQ2k45jwz9sdQ for ; Fri, 1 Jul 2016 02:28:30 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=tolC2QNY; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=l2NfbR5sl+ZJI6x7XZB2j8l1DSR6+ G4FRQUpZ70hGMHmvxFi7z0A7UAXrbZL1GMqJH36Gh74qr8GfC52JcfxCwRhy/IGT cxVc8dt9ZhSk4mSBjzAfVij5oeG9VTOE6ON7+duuU+zPX9Ngf85Lmraiyf8Nge8D qn4Vhkk4cH9ebM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:date:message-id:mime-version :content-type; s=default; bh=Nt3k37nNc/Ena3tcwiqPY+VWeSw=; b=tol C2QNYVDu1ekWlX+D76pExS5yGXg2CxA1/6n5CDYcWjCYKGmdTgcJLGHhcIEh0CWG iWyM0wJhTp679yA7faViSDPSpXSWbJKtW0x8LC/aof/sLIcJNX0KVEGbHCMm/7YP gcEJ/0orZmRJ2RS2L8lx5SqTxtGjp8r84ZyyCKB0= Received: (qmail 63634 invoked by alias); 30 Jun 2016 16:28:24 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 63625 invoked by uid 89); 30 Jun 2016 16:28:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=undo, bye, reserved X-HELO: plane.gmane.org To: libc-alpha@sourceware.org From: Stefan Liebler Subject: [PATCH] S390: Use DT_JUMPREL in prelink undo code. Date: Thu, 30 Jun 2016 18:28:10 +0200 Lines: 117 Message-ID: Mime-Version: 1.0 X-Mozilla-News-Host: news://news.gmane.org:119 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 Hi, on s390, the current prelink undo code in elf_machine_lazy_rel() has the requirement, that the plt stubs use the first got slots after the 3 reserved ones. In case of undoing prelink, the plt got slots are reset to the correct addresses whithin the corresponding plt-stub. Therefore the address is calculated by the address of the first plt-stub-address which was written by prelink (see l->l_mach.plt) to got[1] and index of current relocation multiplied with 32 (=size of one plt slot). The index was calculated with ¤t-got-slot - &got[3]. This patch removes the requirement, that the plt-got-slots are starting at got[3]. The index is now calculated with ¤t-reloc - &reloc[0]. The first struct Elf64_Rela is stored at DT_JMPREL. This patch is needed to prepare for partial relro support. Ulrich Weigand suggested this approach to use DT_JMPREL - Thanks. Okay to commit? Bye Stefan ChangeLog: * sysdeps/s390/linkmap.h (struct link_map_machine): Remove member gotplt and add member jmprel. * sysdeps/s390/s390-32/dl-machine.h (elf_machine_runtime_setup): Setup member jmprel with DT_JMPREL instead of gotplt with &got[3]. (elf_machine_lazy_rel): Calculate address with reloc and jmprel. * sysdeps/s390/s390-64/dl-machine.h: Likewise. diff --git a/sysdeps/s390/linkmap.h b/sysdeps/s390/linkmap.h index fc1fba3..283615b 100644 --- a/sysdeps/s390/linkmap.h +++ b/sysdeps/s390/linkmap.h @@ -2,12 +2,12 @@ struct link_map_machine { Elf64_Addr plt; /* Address of .plt + 0x2e */ - Elf64_Addr gotplt; /* Address of .got + 0x18 */ + const Elf64_Rela *jmprel; /* Address of first JMP_SLOT reloc */ }; #else struct link_map_machine { Elf32_Addr plt; /* Address of .plt + 0x2c */ - Elf32_Addr gotplt; /* Address of .got + 0x0c */ + const Elf32_Rela *jmprel; /* Address of first JMP_SLOT reloc */ }; #endif diff --git a/sysdeps/s390/s390-32/dl-machine.h b/sysdeps/s390/s390-32/dl-machine.h index ec0ae4a..0a58897 100644 --- a/sysdeps/s390/s390-32/dl-machine.h +++ b/sysdeps/s390/s390-32/dl-machine.h @@ -109,7 +109,7 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile) if (got[1]) { l->l_mach.plt = got[1] + l->l_addr; - l->l_mach.gotplt = (Elf32_Addr) &got[3]; + l->l_mach.jmprel = (const Elf32_Rela *) D_PTR (l, l_info[DT_JMPREL]); } got[1] = (Elf32_Addr) l; /* Identify this shared object. */ @@ -506,9 +506,7 @@ elf_machine_lazy_rel (struct link_map *map, if (__builtin_expect (map->l_mach.plt, 0) == 0) *reloc_addr += l_addr; else - *reloc_addr = - map->l_mach.plt - + (((Elf32_Addr) reloc_addr) - map->l_mach.gotplt) * 8; + *reloc_addr = map->l_mach.plt + (reloc - map->l_mach.jmprel) * 32; } else if (__glibc_likely (r_type == R_390_IRELATIVE)) { diff --git a/sysdeps/s390/s390-64/dl-machine.h b/sysdeps/s390/s390-64/dl-machine.h index 9ee7c92..6e5ee1e 100644 --- a/sysdeps/s390/s390-64/dl-machine.h +++ b/sysdeps/s390/s390-64/dl-machine.h @@ -98,7 +98,7 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile) if (got[1]) { l->l_mach.plt = got[1] + l->l_addr; - l->l_mach.gotplt = (Elf64_Addr) &got[3]; + l->l_mach.jmprel = (const Elf64_Rela *) D_PTR (l, l_info[DT_JMPREL]); } got[1] = (Elf64_Addr) l; /* Identify this shared object. */ @@ -460,9 +460,7 @@ elf_machine_lazy_rel (struct link_map *map, if (__builtin_expect (map->l_mach.plt, 0) == 0) *reloc_addr += l_addr; else - *reloc_addr = - map->l_mach.plt - + (((Elf64_Addr) reloc_addr) - map->l_mach.gotplt) * 4; + *reloc_addr = map->l_mach.plt + (reloc - map->l_mach.jmprel) * 32; } else if (__glibc_likely (r_type == R_390_IRELATIVE)) {