From patchwork Tue Nov 1 05:38:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 9406935 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 CFAA960721 for ; Tue, 1 Nov 2016 05:39:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B75E4294BB for ; Tue, 1 Nov 2016 05:39:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A91E7294C5; Tue, 1 Nov 2016 05:39:11 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35AB3294BB for ; Tue, 1 Nov 2016 05:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034611AbcKAFjK (ORCPT ); Tue, 1 Nov 2016 01:39:10 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33374 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1034596AbcKAFjJ (ORCPT ); Tue, 1 Nov 2016 01:39:09 -0400 Received: by mail-pf0-f196.google.com with SMTP id a136so7288683pfa.0; Mon, 31 Oct 2016 22:39:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=33YYJVyNjDW9ZIX9mkR7GHGu4uR4Xqb0aZirnWuni/U=; b=FERctQbg+2Bss4njvMXH9v8jssRZE20H6dFMfcajjWMVMWZXlBUtRTFcfkGQwk6RpX PZ9tpJaQIj186dHqTxFRk2/YOPJITF8DdEplp94QgL9Zrjwegu52AC2n/zYYx6QwyVSg FyCKiOvXB+vxvcwHGeCOGyl4PXj2voZABQZmoXXuVHEogyJ4E+7Wxd2TA32mbpvLIRkJ IUgYothiQLrHiWfd7Dzkt97tuQfjA2jOscjUeuV/k3UqmBFWICRqtOKYanxxXAcrQPSw sBRI7J3Yik0hcgwaUaz3mTXDGUYsl7iYRMPlil1wg4K3mKNZrX0HBcpN0UPa84WFjX98 sb8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=33YYJVyNjDW9ZIX9mkR7GHGu4uR4Xqb0aZirnWuni/U=; b=jYCpr4wrzFe5ItGfWQG1bvNSRkRHGaSGucqjS55PI+oBoVlQxVBo0qtblcHAr6wDLI oAhAoDctlCreW9LCs3vLpjM2TacWQ22ZRM2x+398C3ng2jMPLyCbrkLf7seqQCDOhvtR Wu8mkHeO2Uc9VTrJMzarYguRidgd4LXKiy2e0egwbDG2CRe8IXmAsVKV8IPnOGMdsD/r iq5vjVGpgNTPJRGsIdRwrcmGDOZKvsrp4Uf5/y5wgMduEVQp+Xt5jhnoV6at6JRuOYxv q0RY/zbGA9TrOPXduq2b9+Nf9ITRkccKJGjRX7zmKPfXORy/2kLAPekF52gT8iKpaYU+ JWmg== X-Gm-Message-State: ABUngvesXIc0nk/WvPvyfr95TzAjK+8JkqiNoBrReTxFm7hnwgVawa3UAVCMHJoyi3nqaA== X-Received: by 10.98.29.205 with SMTP id d196mr23745280pfd.111.1477978748642; Mon, 31 Oct 2016 22:39:08 -0700 (PDT) Received: from roar.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id ix3sm25246686pac.17.2016.10.31.22.39.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Oct 2016 22:39:08 -0700 (PDT) From: Nicholas Piggin To: Michal Marek Cc: Nicholas Piggin , linux-kbuild@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH] kbuild: put kallsyms into its own section Date: Tue, 1 Nov 2016 16:38:52 +1100 Message-Id: <20161101053852.2440-1-npiggin@gmail.com> X-Mailer: git-send-email 2.9.3 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP kallsyms gets put into rodata, which can get put into the middle of the object file. This means that when the kallsyms section is linked in, the two halves of the object file get further apart, and that can require new linker stubs to be added (as is the case with very large powerpc64 builds). These new linker stubs add new names, which break kallsyms, resulting in the "inconsistent kallsyms" error. It is possible on powerpc to have the linker not give them names, but that makes disassembly extremely difficult to follow. Doing an extra pass usually solves it, but in theory the next pass could result in slightly larger kallsyms again, which then adds yet another stub name and fails. In general we also would prefer not to add those extra stubs at all. Putting kallsyms right at the end of the image can avoid these problems. So put kallsyms data into its own section, and allow it to be overridden. Signed-off-by: Nicholas Piggin --- arch/powerpc/kernel/vmlinux.lds.S | 6 ++++++ include/asm-generic/vmlinux.lds.h | 12 ++++++++++++ kernel/kallsyms.c | 22 ++++++++++++++-------- scripts/kallsyms.c | 2 +- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 28ebe1a..05f4ae1 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -262,6 +262,15 @@ #define RO_AFTER_INIT_DATA *(.data..ro_after_init) #endif +#ifndef CONFIG_ARCH_PLACES_KALLSYMS +#define KALLSYMS \ + __kallsyms : AT(ADDR(__kallsyms) - LOAD_OFFSET) { \ + KEEP(*(.kallsyms)) \ + } +#else +#define KALLSYMS +#endif + /* * Read only Data */ @@ -419,6 +428,9 @@ . = ALIGN((align)); \ VMLINUX_SYMBOL(__end_rodata) = .; \ } \ + \ + KALLSYMS \ + \ . = ALIGN((align)); /* RODATA & RO_DATA provided for backward compatibility. diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index fafd1a3..311fe07 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -37,24 +37,30 @@ * These will be re-linked against their real values * during the second link stage. */ -extern const unsigned long kallsyms_addresses[] __weak; -extern const int kallsyms_offsets[] __weak; -extern const u8 kallsyms_names[] __weak; +extern const unsigned long kallsyms_addresses[] +__attribute__((weak, section(".kallsyms"))); +extern const int kallsyms_offsets[] +__attribute__((weak, section(".kallsyms"))); +extern const u8 kallsyms_names[] +__attribute__((weak, section(".kallsyms"))); /* * Tell the compiler that the count isn't in the small data section if the arch * has one (eg: FRV). */ extern const unsigned long kallsyms_num_syms -__attribute__((weak, section(".rodata"))); +__attribute__((weak, section(".kallsyms"))); extern const unsigned long kallsyms_relative_base -__attribute__((weak, section(".rodata"))); +__attribute__((weak, section(".kallsyms"))); -extern const u8 kallsyms_token_table[] __weak; -extern const u16 kallsyms_token_index[] __weak; +extern const u8 kallsyms_token_table[] +__attribute__((weak, section(".kallsyms"))); +extern const u16 kallsyms_token_index[] +__attribute__((weak, section(".kallsyms"))); -extern const unsigned long kallsyms_markers[] __weak; +extern const unsigned long kallsyms_markers[] +__attribute__((weak, section(".kallsyms"))); static inline int is_kernel_inittext(unsigned long addr) { diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 1f22a18..4327d80 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -349,7 +349,7 @@ static void write_src(void) printf("#define ALGN .align 4\n"); printf("#endif\n"); - printf("\t.section .rodata, \"a\"\n"); + printf("\t.section .kallsyms, \"a\"\n"); /* Provide proper symbols relocatability by their relativeness * to a fixed anchor point in the runtime image, either '_text'