From patchwork Fri Jan 9 12:55:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 427064 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hemlock.osuosl.org (hemlock.osuosl.org [140.211.166.133]) by ozlabs.org (Postfix) with ESMTP id D1CF7140182 for ; Fri, 9 Jan 2015 23:55:58 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 06739920EF; Fri, 9 Jan 2015 12:55:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id som+wnywBNrB; Fri, 9 Jan 2015 12:55:55 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 4C82A920AA; Fri, 9 Jan 2015 12:55:55 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 648D81C2357 for ; Fri, 9 Jan 2015 12:55:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 604378C602 for ; Fri, 9 Jan 2015 12:55:53 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sBY+OuKRTyAs for ; Fri, 9 Jan 2015 12:55:52 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-la0-f45.google.com (mail-la0-f45.google.com [209.85.215.45]) by whitealder.osuosl.org (Postfix) with ESMTPS id 92A748BF27 for ; Fri, 9 Jan 2015 12:55:52 +0000 (UTC) Received: by mail-la0-f45.google.com with SMTP id gq15so14362338lab.4 for ; Fri, 09 Jan 2015 04:55:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=WiPAFwG2dXNP7mYKZU2Ezli/JGgn7/HObwv6+yA01yQ=; b=F5x9by24TJVKeW8Uopef0ePbBvdYRuxWakHzGqsmlK6vvGAuWjm68DqZsGZIM7UFLX 9qZE9ZWwrYU9YiFbNFdlerLvZCxh1puZWzRXfMDwvIXIO+wC7CNI+ayJqZAcSX+Ea3Ws HQLj5WmROMhx8kVwu8THLLJ4WGR5cGLldSvOZVoiE8AwM+vbTZRcRMxepky38JoeVlYJ S9+ILu5CVyX1M/hohVJn0iUBZFABuftw1WCYfa4iCgGw53s2jbvbC4RqDfI+l7hbYKf4 b9Q5CN1dRD8FNe7dl/DN4YLZk+9pimOWMJJ4CDLLsYZ+AcT51m5z3rHkUXFpTu8++Yrn ZvXQ== X-Received: by 10.112.164.102 with SMTP id yp6mr20917978lbb.15.1420808150822; Fri, 09 Jan 2015 04:55:50 -0800 (PST) Received: from octofox.metropolis ([5.19.183.212]) by mx.google.com with ESMTPSA id 8sm1846390las.27.2015.01.09.04.55.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Jan 2015 04:55:49 -0800 (PST) From: Max Filippov To: uclibc@uclibc.org Subject: [PATCH] xtensa: ldso: coalesce dl_mprotect address ranges Date: Fri, 9 Jan 2015 15:55:35 +0300 Message-Id: <1420808135-4282-1-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 1.8.1.4 Cc: linux-xtensa@linux-xtensa.org X-BeenThere: uclibc@uclibc.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "Discussion and development of uClibc \(the embedded C library\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: uclibc-bounces@uclibc.org Sender: "uClibc" This noticeably lowers the number of mprotect calls at program startup, e.g. for busybox: 7 calls vs 1835 calls. Signed-off-by: Max Filippov --- ldso/ldso/xtensa/dl-startup.h | 18 +++++++++++++++++- ldso/ldso/xtensa/dl-sysdep.h | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/ldso/ldso/xtensa/dl-startup.h b/ldso/ldso/xtensa/dl-startup.h index b135a4c..c60c9cf 100644 --- a/ldso/ldso/xtensa/dl-startup.h +++ b/ldso/ldso/xtensa/dl-startup.h @@ -83,6 +83,7 @@ do { \ unsigned long l_addr = tpnt->loadaddr; \ Elf32_Word relative_count; \ unsigned long rel_addr; \ + Elf32_Addr prev_got_start = 0, prev_got_end = 0; \ int x; \ \ got_loc = (xtensa_got_location *) \ @@ -93,7 +94,22 @@ do { \ got_start = got_loc[x].offset & ~(PAGE_SIZE - 1); \ got_end = ((got_loc[x].offset + got_loc[x].length + PAGE_SIZE - 1) \ & ~(PAGE_SIZE - 1)); \ - _dl_mprotect ((void *)(got_start + l_addr), got_end - got_start, \ + if (got_start >= prev_got_start && got_start <= prev_got_end) { \ + if (got_end > prev_got_end) \ + prev_got_end = got_end; \ + continue; \ + } else if (prev_got_start != prev_got_end) { \ + _dl_mprotect ((void *)(prev_got_start + l_addr), \ + prev_got_end - prev_got_start, \ + PROT_READ | PROT_WRITE | PROT_EXEC); \ + } \ + prev_got_start = got_start; \ + prev_got_end = got_end; \ + } \ +\ + if (prev_got_start != prev_got_end) { \ + _dl_mprotect ((void *)(prev_got_start + l_addr), \ + prev_got_end - prev_got_start, \ PROT_READ | PROT_WRITE | PROT_EXEC); \ } \ \ diff --git a/ldso/ldso/xtensa/dl-sysdep.h b/ldso/ldso/xtensa/dl-sysdep.h index a0ed4e5..06113b5 100644 --- a/ldso/ldso/xtensa/dl-sysdep.h +++ b/ldso/ldso/xtensa/dl-sysdep.h @@ -36,6 +36,7 @@ typedef struct xtensa_got_location_struct { do { \ xtensa_got_location *got_loc; \ Elf32_Addr l_addr = MODULE->loadaddr; \ + Elf32_Addr prev_got_start, prev_got_end; \ int x; \ \ got_loc = (xtensa_got_location *) \ @@ -47,7 +48,26 @@ typedef struct xtensa_got_location_struct { got_start = got_loc[x].offset & ~(PAGE_SIZE - 1); \ got_end = ((got_loc[x].offset + got_loc[x].length + PAGE_SIZE - 1) \ & ~(PAGE_SIZE - 1)); \ - _dl_mprotect ((void *)(got_start + l_addr) , got_end - got_start, \ + if (got_start >= prev_got_start && got_start <= prev_got_end) \ + { \ + if (got_end > prev_got_end) \ + prev_got_end = got_end; \ + continue; \ + } \ + else if (prev_got_start != prev_got_end) \ + { \ + _dl_mprotect ((void *)(prev_got_start + l_addr), \ + prev_got_end - prev_got_start, \ + PROT_READ | PROT_WRITE | PROT_EXEC); \ + } \ + prev_got_start = got_start; \ + prev_got_end = got_end; \ + } \ + \ + if (prev_got_start != prev_got_end) \ + { \ + _dl_mprotect ((void *)(prev_got_start + l_addr), \ + prev_got_end - prev_got_start, \ PROT_READ | PROT_WRITE | PROT_EXEC); \ } \ \