From patchwork Fri Mar 9 08:41:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Sverdlin X-Patchwork-Id: 10269891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8A08F6016D for ; Fri, 9 Mar 2018 08:43:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 730F529D86 for ; Fri, 9 Mar 2018 08:43:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 678AC29D8A; Fri, 9 Mar 2018 08:43:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A87D229D86 for ; Fri, 9 Mar 2018 08:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0ifXxAYgFO17qoCC0q8tl/XorqhhgLRmr6ql8xYWh3g=; b=eozSNIH2OmBdFz 6hwUI5dWir6YQOkeY4zF7Qf9PMrIdw65RZGUXMtRnnba6+1jmDYS1c3tp0Ks6XKp1+9LrJghlH3sH BPTAayXX99zfzWSqcmjUU2FbdHZyEb1q0KNSTQMff9MyDOWcBKzZkUuSygRSkH9Ah5QVl7XkkIYqC CG6AJ3n7rX4O+TC2zLxIe2kg8fuJhIYf00JNq/QqLh2atwPWxIplhRFFTl14g5rDjD1GSqffeNH/N Vw7e7TGbaIV/FVmL9AIcHyqkvMCWl3V8D0v7RQoeGOkC+o/IwYNfBgp2sh280PiQp0s1GpSqbposS 24Z7xxU54Xfuj58rnALQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1euDcp-0006Ms-2X; Fri, 09 Mar 2018 08:43:39 +0000 Received: from mail-he1eur02on0705.outbound.protection.outlook.com ([2a01:111:f400:fe05::705] helo=EUR02-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1euDbk-0005h4-1B for linux-arm-kernel@lists.infradead.org; Fri, 09 Mar 2018 08:42:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.onmicrosoft.com; s=selector1-nokia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=h7WWalSDuqZykxYYNUP4HQiz59fPUcgou8HT2S11hpE=; b=gM76WHRgrbFO7BmswUAathzOj6R5g4LeGBnj0623nF+j2rdf5QmblyGRKR9DfY1V4w/JxLIBUBQUrmhv7RkdpcffOqNIzhgYW6jvmlzWbK8T/Pllfs3s4IaRn8gkYjPmyc6VnOfTOjCAakSM7Ys6H+hemXtE0hqWzqjuYdwLZKE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=alexander.sverdlin@nokia.com; Received: from ulegcpsvdell.emea.nsn-net.net (131.228.2.20) by VI1PR07MB1328.eurprd07.prod.outlook.com (2a01:111:e400:5a03::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.6; Fri, 9 Mar 2018 08:42:11 +0000 From: Alexander Sverdlin To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 2/2] ARM: ftrace: Add MODULE_PLTS support Date: Fri, 9 Mar 2018 09:41:51 +0100 Message-Id: <20180309084151.2379-3-alexander.sverdlin@nokia.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20180309084151.2379-1-alexander.sverdlin@nokia.com> References: <20180309084151.2379-1-alexander.sverdlin@nokia.com> MIME-Version: 1.0 X-Originating-IP: [131.228.2.20] X-ClientProxiedBy: HE1P192CA0018.EURP192.PROD.OUTLOOK.COM (2603:10a6:3:fe::28) To VI1PR07MB1328.eurprd07.prod.outlook.com (2a01:111:e400:5a03::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1a679d04-f651-4ae8-bce5-08d58599a6c0 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020); SRVR:VI1PR07MB1328; X-Microsoft-Exchange-Diagnostics: 1; VI1PR07MB1328; 3:HI36nfah/OJy8JJ1tmKODb684R3liYObcDYnO1gRp7VCf1YhNDKr0XFpqKVQP+Q6XAG629zA1UapRZE54eqoq6dQPxCJx4MRyqGcxkYGkPtf1/JQd0gNa1C/iE9GcfuLdS4MsY6ZzBk0KYWUEPjOanlE7+HHHgntlrmqFow0tLWdSPwvQAJ7oYw2vfG0PVd+uEftstMo7aPyfhj+mcMvipbXPWqT0dYdks+kCkzGKTLN7IZH5qixZj5LLZ73/cA1; 25:4XsI8xX/41mSfhX/UrwxTrVHFtOGUiMrHCJz8J+/fb51WSYB/l7otv0B+ev0aFWf7Tn7mvIb7T+Aidd2LFgloBCRDVLi8T4dfAwKx38i+8II4jyCqvJbbOptZR5x4jczqxXF3k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YCPOI/8axS3Nyl/Z4UCRBsXSka5ufMkfHyNNuJwOk2Bx7+H+wBgbeCtKraAC9nQnSSEns7Xt8R9Yw=; 4:TVRM7LhAvGZCRq6jww9Hor5bP7i73IC5nOOZpfG94e1Z9pGoBca7Cpt9WWYbcMmSnlYJLjMmypHZHqOFru2xqbHEYyIQnScmq/eLe75fnQod6ZWryU9k0fJaPjVDz6NmdA4kVcSgMKcfHGqw8VUV3IkRkOR7mPKa5PRRCJxbCTQqFbbqe/1BojjAnvv6UgB7nHZah3ggejWuyTiAfmSkhdYDCiVcb769S7n9A9wbitNoh4+CqRtVZeDh/Hnf6fCIUGLiJtDpCX0HXhcXZF6lg305Sla89OSMhEy8dKo5jHQzhIxtbaY6+bb7vXA8PcVs X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(82608151540597); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(3231220)(11241501184)(806099)(944501244)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041310)(20161123562045)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011); SRVR:VI1PR07MB1328; BCL:0; PCL:0; RULEID:; SRVR:VI1PR07MB1328; X-Forefront-PRVS: 0606BBEB39 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(366004)(39860400002)(396003)(376002)(346002)(39380400002)(199004)(189003)(48376002)(4326008)(36756003)(86362001)(106356001)(6486002)(25786009)(97736004)(105586002)(51416003)(16526019)(50466002)(59450400001)(50226002)(52116002)(386003)(26005)(76176011)(7736002)(305945005)(186003)(6506007)(8936002)(54906003)(3846002)(6116002)(6666003)(8676002)(16586007)(68736007)(316002)(66066001)(1076002)(2361001)(5660300001)(81166006)(6512007)(2351001)(478600001)(47776003)(2950100002)(81156014)(6916009)(2906002)(53936002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR07MB1328; H:ulegcpsvdell.emea.nsn-net.net; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: nokia.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR07MB1328; 23:ii2rWmjN4XWAp9S0fy5dMA14MbqNJ3dYzKxViBJ+v?= =?us-ascii?Q?VLeH1ND1QONF/aMTC2DAVSHvUP/05Ocupnr3InW1RHWZp/zsgu5ZOL+eM3Fp?= =?us-ascii?Q?atBw4LE/yG4D5BV3ik8ULl1BUt+1KJ+3mByqywhHFkPogv7Tiv/PS8STuQb/?= =?us-ascii?Q?b7C01mT2qhC6rjAk1VMSO+PSIlNr9S5DZGc/jYxshDAgjdNi7SG8qyzcnWOn?= =?us-ascii?Q?+CbCy6hK+kmopBB88SaBdZ6PqngOGZESUDvXrWTw7HgjihyEwNF+1R7HGQAL?= =?us-ascii?Q?H8KMAIi2UtyUkMJOi6j56lURGilzlM8M6anh6F6gnZ8w7ME5/VZ7g5QpI3Nl?= =?us-ascii?Q?3HMdD2RUQCwz287fWT8pDhujHFIJ2f/4D4escs7QOhmMSK1APmx0ZMHPMr64?= =?us-ascii?Q?sPth3zaDhCJS9Aod4KFRJNpinZSuBsLCJTOjQHFKkfrO1oLRHYvESFdptBbq?= =?us-ascii?Q?kDOw9zoJQJ/YgG9pQ2kiq5JGISrcY1YsUwi2h3LXht9sl+s40w7iwiRoL9GP?= =?us-ascii?Q?5NvE+Z6129KkOYCzDBC94V2+CS4N9J0/329I4d47I921iMBgL2pjwtp0z2+A?= =?us-ascii?Q?6tGfIMxONcVdPdnd0znDffOeML/KYxvHXVQXy/de3hWcLcUyahvmByb+6f+X?= =?us-ascii?Q?EPnRW10KkpXwsVb5Y/YczD9L4y7bc5eRQbQ5XiYTB3vbPrwk1HSp5re6aKcL?= =?us-ascii?Q?eg0YGFLEeQRTHURo37mPamkLjjBxOF2GGcHskW/fk/21ny5GJU00nfnTS+sj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eW6sKbKWWlxzdKPj8tXjbDefI7sWoSsiDAtxKFkJSrh2qq09mjmwKiQYwIp3lKwQosdCGY252EyaeLFLEuD4hK7zMjIAGlgBC5hpA23W9ID4WqZqkhV9fFADiqHevoA9tDISz3OoKNZKm0PAPLpoXY=; 5:ARjtLKNho/5VzVsvgmk92Y0RT+c8Is9limuHcxk+Hx9fv2ra3UKOHoRhLtcqBzgGY0ikf4A3mFVUbFk1px5gPewCREeLQD/u/WlVw0bDEKMgafZC1mnkwWf97I1AFdaGZS1EiAJHo+IVaTp71A70d8BUby9rdq3na0YJ2mXImtw=; 24:NTz5gW8qGBB69lVoi13CVjKx0QqSBFo51kpukJXwsCFehV46/Z4yph/3YAsgLHKwsjmVfBy3Evy58OvnL2gb2uMqdetymvPO8y/sQDyoYzg=; 7:j5dfslCjA4k2EzaXLDWM+gnPnpG5c2B9W3QbvlY2MkmVbjro+Do55c49z+sbRC3ExjZRc3bhxubUAtVWHG4+TB6+tSEVPvzaA4LKUfyZzK93IEuJNkr0RSLqKneatJgSYFo7kaod0Y6mOQBmPuijyvYWG3i4UV52LrEJYV6AOU8aXwwOWI+9U0q96aOtpTKCKoG1Uy2XQhfz204I1Gw9hyh5bkp4nGW26tJoMZD1vSPat6ZlFybx43SgGNB3P52j SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2018 08:42:11.1038 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a679d04-f651-4ae8-bce5-08d58599a6c0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB1328 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180309_004232_672020_A40A197B X-CRM114-Status: GOOD ( 18.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ingo Molnar , Alexander Sverdlin , linux-kernel@vger.kernel.org, Steven Rostedt , Russell King 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 Teach ftrace_make_call() and ftrace_make_nop() about PLTs. Teach PLT code about FTRACE and all its callbacks. Otherwise the following might happen: ------------[ cut here ]------------ WARNING: CPU: 14 PID: 2265 at .../arch/arm/kernel/insn.c:14 __arm_gen_branch+0x83/0x8c() ... Hardware name: LSI Axxia AXM55XX [] (unwind_backtrace) from [] (show_stack+0x11/0x14) [] (show_stack) from [] (dump_stack+0x81/0xa8) [] (dump_stack) from [] (warn_slowpath_common+0x69/0x90) [] (warn_slowpath_common) from [] (warn_slowpath_null+0x17/0x1c) [] (warn_slowpath_null) from [] (__arm_gen_branch+0x83/0x8c) [] (__arm_gen_branch) from [] (ftrace_make_nop+0xf/0x24) [] (ftrace_make_nop) from [] (ftrace_process_locs+0x27b/0x3e8) [] (ftrace_process_locs) from [] (load_module+0x11e9/0x1a44) [] (load_module) from [] (SyS_finit_module+0x59/0x84) [] (SyS_finit_module) from [] (ret_fast_syscall+0x1/0x18) ---[ end trace e1b64ced7a89adcc ]--- ------------[ cut here ]------------ WARNING: CPU: 14 PID: 2265 at .../kernel/trace/ftrace.c:1979 ftrace_bug+0x1b1/0x234() ... Hardware name: LSI Axxia AXM55XX [] (unwind_backtrace) from [] (show_stack+0x11/0x14) [] (show_stack) from [] (dump_stack+0x81/0xa8) [] (dump_stack) from [] (warn_slowpath_common+0x69/0x90) [] (warn_slowpath_common) from [] (warn_slowpath_null+0x17/0x1c) [] (warn_slowpath_null) from [] (ftrace_bug+0x1b1/0x234) [] (ftrace_bug) from [] (ftrace_process_locs+0x285/0x3e8) [] (ftrace_process_locs) from [] (load_module+0x11e9/0x1a44) [] (load_module) from [] (SyS_finit_module+0x59/0x84) [] (SyS_finit_module) from [] (ret_fast_syscall+0x1/0x18) ---[ end trace e1b64ced7a89adcd ]--- ftrace failed to modify [] 0xe9ef7006 actual: 02:f0:3b:fa ftrace record flags: 0 (0) expected tramp: c0314265 Signed-off-by: Alexander Sverdlin --- arch/arm/include/asm/ftrace.h | 3 +++ arch/arm/include/asm/module.h | 1 + arch/arm/kernel/ftrace.c | 62 ++++++++++++++++++++++++++++++++++++------- arch/arm/kernel/module-plts.c | 53 +++++++++++++++++++++++++++--------- 4 files changed, 97 insertions(+), 22 deletions(-) diff --git a/arch/arm/include/asm/ftrace.h b/arch/arm/include/asm/ftrace.h index 9e842ff..faeb6b1 100644 --- a/arch/arm/include/asm/ftrace.h +++ b/arch/arm/include/asm/ftrace.h @@ -19,6 +19,9 @@ struct dyn_arch_ftrace { #ifdef CONFIG_OLD_MCOUNT bool old_mcount; #endif +#ifdef CONFIG_ARM_MODULE_PLTS + struct module *mod; +#endif }; static inline unsigned long ftrace_call_adjust(unsigned long addr) diff --git a/arch/arm/include/asm/module.h b/arch/arm/include/asm/module.h index 6996405..e3d7a51 100644 --- a/arch/arm/include/asm/module.h +++ b/arch/arm/include/asm/module.h @@ -30,6 +30,7 @@ struct plt_entries { struct mod_plt_sec { struct elf32_shdr *plt; + struct plt_entries *plt_ent; int plt_count; }; diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c index 5617932..b55355f 100644 --- a/arch/arm/kernel/ftrace.c +++ b/arch/arm/kernel/ftrace.c @@ -98,6 +98,19 @@ int ftrace_arch_code_modify_post_process(void) static unsigned long ftrace_call_replace(unsigned long pc, unsigned long addr) { + s32 offset = addr - pc; + s32 blim = 0xfe000008; + s32 flim = 0x02000004; + + if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) { + blim = 0xff000004; + flim = 0x01000002; + } + + if (IS_ENABLED(CONFIG_ARM_MODULE_PLTS) && + (offset < blim || offset > flim)) + return 0; + return arm_gen_branch_link(pc, addr); } @@ -166,10 +179,22 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) { unsigned long new, old; unsigned long ip = rec->ip; + unsigned long aaddr = adjust_address(rec, addr); old = ftrace_nop_replace(rec); - new = ftrace_call_replace(ip, adjust_address(rec, addr)); + new = ftrace_call_replace(ip, aaddr); + +#ifdef CONFIG_ARM_MODULE_PLTS + if (!new) { + struct module *mod = rec->arch.mod; + + if (mod) { + aaddr = get_module_plt(mod, ip, aaddr); + new = ftrace_call_replace(ip, aaddr); + } + } +#endif return ftrace_modify_code(rec->ip, old, new, true); } @@ -199,20 +224,39 @@ int ftrace_make_nop(struct module *mod, unsigned long new; int ret; - old = ftrace_call_replace(ip, adjust_address(rec, addr)); - new = ftrace_nop_replace(rec); - ret = ftrace_modify_code(ip, old, new, true); +#ifdef CONFIG_ARM_MODULE_PLTS + /* mod is only supplied during module loading */ + if (!mod) + mod = rec->arch.mod; + else + rec->arch.mod = mod; +#endif -#ifdef CONFIG_OLD_MCOUNT - if (ret == -EINVAL && addr == MCOUNT_ADDR) { - rec->arch.old_mcount = true; + for (;;) { + unsigned long aaddr = adjust_address(rec, addr); + + old = ftrace_call_replace(ip, aaddr); + +#ifdef CONFIG_ARM_MODULE_PLTS + if (!old && mod) { + aaddr = get_module_plt(mod, ip, aaddr); + old = ftrace_call_replace(ip, aaddr); + } +#endif - old = ftrace_call_replace(ip, adjust_address(rec, addr)); new = ftrace_nop_replace(rec); ret = ftrace_modify_code(ip, old, new, true); - } + +#ifdef CONFIG_OLD_MCOUNT + if (ret == -EINVAL && !rec->arch.old_mcount) { + rec->arch.old_mcount = true; + continue; + } #endif + break; + } + return ret; } diff --git a/arch/arm/kernel/module-plts.c b/arch/arm/kernel/module-plts.c index f272711..a216256 100644 --- a/arch/arm/kernel/module-plts.c +++ b/arch/arm/kernel/module-plts.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -22,6 +23,15 @@ (PLT_ENT_STRIDE - 8)) #endif +static u32 fixed_plts[] = { + FTRACE_ADDR, + MCOUNT_ADDR, +#ifdef CONFIG_OLD_MCOUNT + (unsigned long)ftrace_caller_old, + (unsigned long)mcount, +#endif +}; + static bool in_init(const struct module *mod, unsigned long loc) { return loc - (u32)mod->init_layout.base < mod->init_layout.size; @@ -31,26 +41,43 @@ u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val) { struct mod_plt_sec *pltsec = !in_init(mod, loc) ? &mod->arch.core : &mod->arch.init; + int idx; + struct plt_entries *plt; + + /* Pre-allocate entries in the first plt */ + if (!pltsec->plt_count) { + plt = (struct plt_entries *)pltsec->plt->sh_addr; + for (idx = 0; idx < ARRAY_SIZE(plt->ldr); ++idx) + plt->ldr[idx] = PLT_ENT_LDR; + memcpy(plt->lit, fixed_plts, sizeof(fixed_plts)); + pltsec->plt_count = ARRAY_SIZE(fixed_plts); + /* + * cache the address, + * ELF header is available only during module load + */ + pltsec->plt_ent = plt; + } + plt = pltsec->plt_ent; - struct plt_entries *plt = (struct plt_entries *)pltsec->plt->sh_addr; - int idx = 0; + idx = ARRAY_SIZE(fixed_plts); + while (idx) + if (plt->lit[--idx] == val) + return (u32)&plt->ldr[idx]; /* * Look for an existing entry pointing to 'val'. Given that the * relocations are sorted, this will be the last entry we allocated. * (if one exists). */ - if (pltsec->plt_count > 0) { - plt += (pltsec->plt_count - 1) / PLT_ENT_COUNT; - idx = (pltsec->plt_count - 1) % PLT_ENT_COUNT; + plt += (pltsec->plt_count - 1) / PLT_ENT_COUNT; + idx = (pltsec->plt_count - 1) % PLT_ENT_COUNT; - if (plt->lit[idx] == val) - return (u32)&plt->ldr[idx]; + if (plt->lit[idx] == val) + return (u32)&plt->ldr[idx]; - idx = (idx + 1) % PLT_ENT_COUNT; - if (!idx) - plt++; - } + idx = (idx + 1) % PLT_ENT_COUNT; + if (!idx) + plt++; pltsec->plt_count++; BUG_ON(pltsec->plt_count * PLT_ENT_SIZE > pltsec->plt->sh_size); @@ -182,8 +209,8 @@ static unsigned int count_plts(const Elf32_Sym *syms, Elf32_Addr base, int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings, struct module *mod) { - unsigned long core_plts = 0; - unsigned long init_plts = 0; + unsigned long core_plts = ARRAY_SIZE(fixed_plts); + unsigned long init_plts = ARRAY_SIZE(fixed_plts); Elf32_Shdr *s, *sechdrs_end = sechdrs + ehdr->e_shnum; Elf32_Sym *syms = NULL;