From patchwork Thu Mar 1 16:43:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Sverdlin X-Patchwork-Id: 10251981 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 3377E602B5 for ; Thu, 1 Mar 2018 16:46:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2281228610 for ; Thu, 1 Mar 2018 16:46:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 172FC2867F; Thu, 1 Mar 2018 16:46:08 +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 0206628610 for ; Thu, 1 Mar 2018 16:46:07 +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=F04g5yCLxjWAgoW7OvQrD3GZn1z1U1NOBcPJPuQDP/8=; b=l3PwiZBsIYzTKI lZdUD2Xhu4kr9k0DTn0ytyeeJ64Em+NpGPw4dGkIO3umdGCTSY8gO0FblbcVKlzhEwTXRmOLhGkj3 9M2rQ8hFCsn3QfNrHUUoSZIVS7hEN364Vsv55bg2HWN1OqwBG6QPxiHuUEZuiN5FIcEXVOb0XjwoT CHmhnz+a+K5kGm7FebcuQTA0SRk0v5ZTleEVUcvXkCXB4poOI2JDXkhmuHPVtuLwZ3Y1ploRQ+9rF 33Jj/yqFFANFVSVPZ64Y+PNkbqfcRGVYrXqex6QPDSpJDVla9vvUpnL9OE428eT80FGiZh/zjYdlr QoKRxIoSVx7+eHT4CW9Q==; 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 1erRL9-0006Np-P3; Thu, 01 Mar 2018 16:45:55 +0000 Received: from mail-he1eur01on0094.outbound.protection.outlook.com ([104.47.0.94] helo=EUR01-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1erRJr-0004BX-Bn for linux-arm-kernel@lists.infradead.org; Thu, 01 Mar 2018 16:44:47 +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=QV3ZDtw0iWgKbFxx2atfMCJyyyEUtJHXyH4itPwOxZU=; b=DebndSAj4zko+2DlbBZdmmoslGYGPHUSdOIFxbHwtp+oeQvyYxmri+5jV15XJ0ttu+v2kQwl/vDt2jBEnHdenqgRZwz4ex3rPUUxUFl4Ww0nFtSBDnNuTX7GBlXyTwQLHoX+fyZTXsQK1YdHnBxqF2g7BGTPpDfthAlNwfJaKLA= 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 DB5PR07MB1320.eurprd07.prod.outlook.com (2a01:111:e400:599b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.5; Thu, 1 Mar 2018 16:44:07 +0000 From: Alexander Sverdlin To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 2/2] ARM: ftrace: Add MODULE_PLTS support Date: Thu, 1 Mar 2018 17:43:43 +0100 Message-Id: <20180301164343.5794-3-alexander.sverdlin@nokia.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20180301164343.5794-1-alexander.sverdlin@nokia.com> References: <20180301164343.5794-1-alexander.sverdlin@nokia.com> MIME-Version: 1.0 X-Originating-IP: [131.228.2.20] X-ClientProxiedBy: VI1PR08CA0129.eurprd08.prod.outlook.com (2603:10a6:800:d4::31) To DB5PR07MB1320.eurprd07.prod.outlook.com (2a01:111:e400:599b::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 048ffcb4-382a-43fa-48d0-08d57f93a6e4 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603307)(7193020); SRVR:DB5PR07MB1320; X-Microsoft-Exchange-Diagnostics: 1; DB5PR07MB1320; 3:s+m0YmVHU/zV8SPN00tJopAszdj0whLiF3jLjnRQPiFRJgYcwk1Gq8lb4H2c0nr1Lo9THeuotiDru36DHPL6m1Pyqrd6AkRYfNDMM2P7n9oQZXX0cYfNmoANsSIdRB7m3j/7Wu1o561soiqfALpY4miLwToPU9932dNJZluHZQZIhXwgG/+Qb8W9Iajyyz1LOauF0nM/WD3ZLYcLTemNyWseAwE/aOiJi/ISIif2Dj7GdigSUOd6gwutKa/XNERh; 25:JIrPLhLXy2uBlZZV2UD7DQoV17D3hE6tS2Gk5kMj3b1EVqV9K6MfTuT/gBuE4lSb00hKeDWKwDq+ovmqCRx+6H4gVti2Drpd4fNwRjUEBJbh2Y9t0qluDNuJC8EtG8j7CGW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Hr2EtB7NUHsJ4xgPbMjVj+4ulqG/bHJgDt/2Z0C6xOMGzhKyuB+uokBmaAthc6U=; 4:kujFOLTNMOCxcpqOVhEhGYBZdXkX7Nv0lnQmJ9qYNP5UgIOzfXm28bcJfhvAxnTsSoebqNtzC3mQUO6MvVU9SAOOyiByU7yhtWn3J8crrcx1m/RutdHvux4r94xyoqtsEiGQbcW2Wa3a5+tw6fgnUtupHxVucVViM4YENwJsItectinrZpbQrDZq6F95FHgJXLqXMwepmUrQns2XkDXyW5YVdcrmxKDUVd3zwk3j9Fx3JJtLRZ47UnTXVt0TRqab2k7kOxCgr1p8bLg+RSD22Nj0XD7QEt77wt5esKe5YN7mDqDZEczyH+Enf0X7DcWT X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(82608151540597); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231220)(11241501184)(806099)(944501229)(52105095)(6055026)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123562045)(20161123560045)(6072148)(201708071742011); SRVR:DB5PR07MB1320; BCL:0; PCL:0; RULEID:; SRVR:DB5PR07MB1320; X-Forefront-PRVS: 05986C03E0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(39380400002)(346002)(396003)(366004)(39860400002)(376002)(189003)(199004)(50466002)(68736007)(25786009)(105586002)(6486002)(305945005)(2950100002)(7736002)(6916009)(6666003)(53936002)(16526019)(478600001)(54906003)(52116002)(76176011)(26005)(16586007)(51416003)(6506007)(36756003)(386003)(5660300001)(47776003)(66066001)(106356001)(59450400001)(186003)(86362001)(316002)(6116002)(1076002)(81156014)(6512007)(8676002)(48376002)(97736004)(8936002)(50226002)(2351001)(2361001)(4326008)(81166006)(3846002)(2906002); DIR:OUT; SFP:1102; SCL:1; SRVR:DB5PR07MB1320; H:ulegcpsvdell.emea.nsn-net.net; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; DB5PR07MB1320; 23:rjY9fx2pmXS15sUu/PtNieoDo7UAsJNqOBIM5WC1d?= =?us-ascii?Q?Yw1opX8PY02obOnhHPhmEyoVAVDZKIGep2EHpbnSYfSxL1qxr/tLB3VfR1jC?= =?us-ascii?Q?ixvIF4/tXR/H+XfvCYRjqQ7NHi/x5x+ANoFG/vytsIE+AbcIQ+eth45i4fs8?= =?us-ascii?Q?hxgny6jxsvO0vyK+mDacQ4mQ6Ho9gSQJSENpsA1h3Jh/GWyG8zenSOCPjTOC?= =?us-ascii?Q?UuDsIj20Q9EE0JEkitygYJGsajTLA6v49SF3q+iEb+Cw+VMh9B8QWlqgQ5A1?= =?us-ascii?Q?Kfw0IQj2vsV2Rp1wnd1W5asmO3p0QjcEpe95rCJ9c27oudzIRXiFFyzQBmTT?= =?us-ascii?Q?y56gN0Ow2R0y9EWZ5LzmiwgXEabIrvvwHd8mHQTFn7kUO1BTMd/8fpkTWK7d?= =?us-ascii?Q?hdhWTM+n09TJ2Nz2kimxnVwA3Fc2IWvpiwfB4VYV7meU5NPEt3G7h1jU0Pus?= =?us-ascii?Q?xyHta7utaLwYQKDCS/Nvo7VMneugQrnIWwcSJJD+XeefuAEtKXx0O7B3foKA?= =?us-ascii?Q?vm+pgrGegDW/7NtcAIzD0CvmK22Y/vISnqKb1Tepzm5l08IV6c2APQtOGwXr?= =?us-ascii?Q?Rveq1DoXVg+CrMEl34PPxTNPppKE8qAs4w3XMPhf6+bZDZ4dCYHAJezZ02Cy?= =?us-ascii?Q?y9oxFeuYwODZH56YI+ATzX3ZCGlpb6AgUR6j3AbQnspS/SyuDceeUIa/khjo?= =?us-ascii?Q?txejbJ9O8GaeO52f1oOKyqR+fS+8QNScMdwVTN1NrB2tUMmdCQTk8s4ze/o6?= =?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c=; 5:A5ppjwNbJwM6s5F0tQuni6GPvXGbUNTCBiu4Fef+QplpotI3B9JY4z2gBT3YCRMjs5h/zJwfTRVTGjoMZbhddCJz+nGAfGgaDzTwVsOQZzirNOE27CY37Lmn1+elHNJDeNKCVSK+rDT6yHw4CLKw/3UOij3L+1K1rWhgdlsC7o0=; 24:z18ziP+ZUwBkpHtxq032kC5O6CxrA5BU74ALh4vYr5DDM04IyxEHxLIwrQVb1gBZi/ton9Q1UMaAnlWZRYrRxfrRXI/DHiSGf5OLQ3/wJLo=; 7:1t/6s3vhw8csMm3DwSR4JH0rKw/X5gyEFmu6thyDP9D/xTHuoyORWQcFtDE51uGRvwlKvrhYrsk/dcitFvsl3EpvWCv8LFWNra0MQy8FYCgzKBsITeKILr7pm9l/UsBNZYhW6RjAwkp70u71po97FgktHNWNqt5oiRT1z9v8TtUlczS7n/D9CcfPqNIqaDhrR3htktoOmHVIXifuRQUApgs+H/8Dp+EDgbCLJKGxa1SUiZ+PACjWgiVzig9gWesv SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2018 16:44:07.0763 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 048ffcb4-382a-43fa-48d0-08d57f93a6e4 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR07MB1320 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180301_084436_159039_3A40BEC3 X-CRM114-Status: GOOD ( 18.99 ) 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 | 1 + arch/arm/include/asm/module.h | 1 + arch/arm/kernel/ftrace.c | 60 ++++++++++++++++++++++++++++++++++++------- arch/arm/kernel/module-plts.c | 53 ++++++++++++++++++++++++++++---------- 4 files changed, 93 insertions(+), 22 deletions(-) diff --git a/arch/arm/include/asm/ftrace.h b/arch/arm/include/asm/ftrace.h index 9e842ff..3e663f9 100644 --- a/arch/arm/include/asm/ftrace.h +++ b/arch/arm/include/asm/ftrace.h @@ -19,6 +19,7 @@ struct dyn_arch_ftrace { #ifdef CONFIG_OLD_MCOUNT bool old_mcount; #endif + struct module *mod; }; 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..eff306c 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,37 @@ 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); + /* mod is only supplied during module loading */ + if (!mod) + mod = rec->arch.mod; + else + rec->arch.mod = mod; -#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;