From patchwork Sat Jan 30 01:18:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 8169341 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B40019FBE9 for ; Sat, 30 Jan 2016 01:19:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CF6F720381 for ; Sat, 30 Jan 2016 01:19:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DE7F5201CD for ; Sat, 30 Jan 2016 01:19:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aPKBM-00011v-Py; Sat, 30 Jan 2016 01:18:32 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aPKBJ-0000w4-0k for linux-arm-kernel@lists.infradead.org; Sat, 30 Jan 2016 01:18:29 +0000 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 8A2416047C; Sat, 30 Jan 2016 01:18:08 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 7D8A86045C; Sat, 30 Jan 2016 01:18:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from sboyd-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: sboyd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id E7F586021E; Sat, 30 Jan 2016 01:18:07 +0000 (UTC) From: Stephen Boyd To: Steven Rostedt Subject: [PATCH] recordmcount: arm: Implement make_nop Date: Fri, 29 Jan 2016 17:18:06 -0800 Message-Id: <1454116686-30190-1-git-send-email-sboyd@codeaurora.org> X-Mailer: git-send-email 2.6.3.369.g91ad409 X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160129_171829_161954_801E640D X-CRM114-Status: GOOD ( 16.02 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rabin Vincent , Russell King , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In similar spirit to x86 and arm64 support, add a make_nop_arm() to replace calls to mcount with a "nop" in sections that aren't traced. Cc: Russell King Cc: Rabin Vincent Signed-off-by: Stephen Boyd --- scripts/recordmcount.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ scripts/recordmcount.h | 3 ++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c index e167592793a7..0b16d14c54fb 100644 --- a/scripts/recordmcount.c +++ b/scripts/recordmcount.c @@ -206,6 +206,52 @@ static int make_nop_x86(void *map, size_t const offset) return 0; } +/* + * Indicates if ARM is using __gnu_mcount_nc or mcount style and if + * we should replace it with a pop or a nop respectively. + */ +static int uses_altmcount; + +static unsigned char ideal_nop4_arm_arm[4] = { 0x00, 0x40, 0xbd, 0xe8 }; +static unsigned char ideal_nop4_arm_thumb[4] = { 0x5d, 0xf8, 0x04, 0xeb }; +static unsigned char ideal_nop4_arm_arm_be[4] = { 0xe8, 0xbd, 0x40, 0x00 }; +static unsigned char ideal_nop4_arm_thumb_be[4] = { 0xf8, 0x5d, 0xeb, 0x04 }; +static unsigned char ideal_nop4_arm_old[4] = { 0x00, 0x00, 0xa0, 0xe1 }; +static unsigned char ideal_nop4_arm_old_be[4] = { 0xe1, 0xa0, 0x00, 0x00 }; + +static unsigned char bl_gnu_mcount_nc_arm[4] = { 0xfe, 0xff, 0xff, 0xeb }; +static unsigned char bl_gnu_mcount_nc_thumb[4] = { 0xff, 0xf7, 0xfe, 0xff }; +static unsigned char bl_gnu_mcount_nc_arm_be[4] = { 0xeb, 0xff, 0xff, 0xfe }; +static unsigned char bl_gnu_mcount_nc_thumb_be[4] = { 0xf7, 0xff, 0xff, 0xfe }; + +static int make_nop_arm(void *map, size_t const offset) +{ + uint32_t *ptr; + + ptr = map + offset; + if (memcmp(ptr, bl_gnu_mcount_nc_arm, 4) == 0) { + if (uses_altmcount) + ideal_nop = ideal_nop4_arm_arm; + else + ideal_nop = ideal_nop4_arm_old; + } else if (memcmp(ptr, bl_gnu_mcount_nc_arm_be, 4) == 0) { + if (uses_altmcount) + ideal_nop = ideal_nop4_arm_arm_be; + else + ideal_nop = ideal_nop4_arm_old_be; + } else if (memcmp(ptr, bl_gnu_mcount_nc_thumb, 4) == 0) + ideal_nop = ideal_nop4_arm_thumb; + else if (memcmp(ptr, bl_gnu_mcount_nc_thumb_be, 4) == 0) + ideal_nop = ideal_nop4_arm_thumb_be; + else + return -1; + + /* Convert to nop */ + ulseek(fd_map, offset, SEEK_SET); + uwrite(fd_map, ideal_nop, 4); + return 0; +} + static unsigned char ideal_nop4_arm64[4] = {0x1f, 0x20, 0x03, 0xd5}; static int make_nop_arm64(void *map, size_t const offset) { @@ -454,6 +500,9 @@ do_file(char const *const fname) break; case EM_ARM: reltype = R_ARM_ABS32; altmcount = "__gnu_mcount_nc"; + make_nop = make_nop_arm; + rel_type_nop = R_ARM_NONE; + ideal_nop = ideal_nop4_arm_arm; break; case EM_AARCH64: reltype = R_AARCH64_ABS64; diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h index b9897e2be404..890f5211745f 100644 --- a/scripts/recordmcount.h +++ b/scripts/recordmcount.h @@ -266,7 +266,8 @@ static unsigned get_mcountsym(Elf_Sym const *const sym0, if (symname[0] == '.') ++symname; /* ppc64 hack */ if (strcmp(mcount, symname) == 0 || - (altmcount && strcmp(altmcount, symname) == 0) || + (altmcount && strcmp(altmcount, symname) == 0 && + (uses_altmcount = 1)) || (strcmp(fentry, symname) == 0)) mcountsym = Elf_r_sym(relp);