From patchwork Wed Jul 26 12:46:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 9864737 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 11C5860382 for ; Wed, 26 Jul 2017 12:47:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1076428748 for ; Wed, 26 Jul 2017 12:47:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03ACF28759; Wed, 26 Jul 2017 12:47: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=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 6508328748 for ; Wed, 26 Jul 2017 12:47:10 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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:In-Reply-To: References:List-Owner; bh=OR0JqICxAKfEfsUcg6RiWee0jK8CHW5UwY2PTotc5c4=; b=bbj xRJtU8XzkMHMPbuBA5qg2cFG7tBhBrEtvH7PphXufeAy7A0PNova4cVvSM/7Fhm7EG5IWFAlvWePu gsSgM6OihwrE8hnMpKgjvgnIbc/TX7wAIYTYqVeFiE9xG1MJ0zOSONJfF3yQx/d9A3GdC0XCjhkHE QelLacnf7u0I2hz6of4CQQOW5FL1tsOSt3rOESfhKLqdjM8spVOZF1n25plJofSpb92PxM948Dox+ ILDhpQTGHsD7peaYFPWsv7LSwjCR1MadVXfI1jcsM6g+dp9Nuf9TVO8ff2ZuDSA6n7grLBgoMkek+ JxiRSPLZio0SPqhhog5HKIiVaT8n6Zg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1daLiT-0001W2-Jy; Wed, 26 Jul 2017 12:47:05 +0000 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1daLiO-0001M6-Uj for linux-arm-kernel@lists.infradead.org; Wed, 26 Jul 2017 12:47:03 +0000 Received: by mail-pf0-x241.google.com with SMTP id g69so6418538pfe.1 for ; Wed, 26 Jul 2017 05:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=KdMUtZOLDupSMMvZHNDJXKLVRmUvzzIPNE6gUdPKWBg=; b=l0oohEoouiOvZiuuNmcCNQfUxgYSSjLjXO9j9jtopKIMNOwPg715RUbl8bdWaiDVv1 OeSWDt6TcsBp+1GpHOoH+q1zZlBVDmOoG94u5uXx5Lj/DAavIZwMcjQa/YOMJRwq3hDy mfI1+fTlpmxXxN1UgGxNU+urHcmSL+rfdr4j5v2NwmSiMbFmAoUJ+ybsB2S7GLaJffSG Ncq8DneCszo0wUdAFORI4/kiaSmFTrh4dcTxjvWOwLYgDA3duQ9QNssOHUUHLfXMRlUB IY3NBL0kb6JimDgYXL035Ub9wsePI++i8fGcqphdfJ4gLB4tOsQ6aTVNW65YFfnjGuXX YhTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=KdMUtZOLDupSMMvZHNDJXKLVRmUvzzIPNE6gUdPKWBg=; b=el8nQ+Tg2jbC72vNEqx0WYeSNh8meYjm18hT7fmQyOGhgKnQM4NSAr9f3X7QCTSkOu C2iHCPbcY/4zQfl3W6o4ssSj3gUsmyM1hP5zrLjeB51dAheCzRQ+4HggUMUkD1YafLya BLquh+zk1iLOGqEmXIe6hZ9DfqOh40ku1d0kVO28cmtUD5PGc+ZqGnB7pZzY7J8Ic4Jk 9QUglhRpl3DI2HZFzUJGHmYFb9x8omwgwUtmLETgEmTDnFcvmtqDakTIXd6dfBFt96pw e2Q2MmjIwzzTmcs49DuJRvalGxgLp7XrSopZMtXaoiGPYhXRtKTBekf4Vng47zS/nXQz S2tg== X-Gm-Message-State: AIVw110J9cv+MFtkJGh08KA2gOQgfcfgFCVAAtzHrooYZFDqD1tfeGnn RIdJIzD3dFtUKA== X-Received: by 10.98.110.65 with SMTP id j62mr734578pfc.115.1501073199853; Wed, 26 Jul 2017 05:46:39 -0700 (PDT) Received: from roar.au.ibm.com (203-219-56-202.tpgi.com.au. [203.219.56.202]) by smtp.gmail.com with ESMTPSA id y14sm28093590pfa.52.2017.07.26.05.46.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Jul 2017 05:46:38 -0700 (PDT) From: Nicholas Piggin To: Masahiro Yamada Subject: [PATCH] kbuild: linker script do not match C names unless LD_DEAD_CODE_DATA_ELIMINATION is configured Date: Wed, 26 Jul 2017 22:46:27 +1000 Message-Id: <20170726124627.32144-1-npiggin@gmail.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170726_054701_156255_6CC5590B X-CRM114-Status: GOOD ( 14.61 ) 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: linux-kbuild@vger.kernel.org, Russell King - ARM Linux , stable@vger.kernel.org, Michal Marek , Nicholas Piggin , 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 The .data and .bss sections were modified in the generic linker script to pull in sections named .data., which are generated by gcc with -ffunction-sections and -fdata-sections options. The problem with this pattern is it can also match section names that Linux defines explicitly, e.g., .data.unlikely. This can cause Linux sections to get moved into the wrong place. The way to avoid this is to use ".." separators for explicit section names (the dot character is valid in a section name but not a C identifier). However currently there are sections which don't follow this rule, so for now just disable the wild card by default. Example: http://marc.info/?l=linux-arm-kernel&m=150106824024221&w=2 Cc: # 4.9 Fixes: b67067f1176df ("kbuild: allow archs to select link dead code/data elimination") Signed-off-by: Nicholas Piggin --- include/asm-generic/vmlinux.lds.h | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index da0be9a8d1de..9623d78f8494 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -60,6 +60,22 @@ #define ALIGN_FUNCTION() . = ALIGN(8) /* + * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which + * generates .data.identifier sections, which need to be pulled in with + * .data. We don't want to pull in .data..other sections, which Linux + * has defined. Same for text and bss. + */ +#ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION +#define TEXT_MAIN .text .text.[0-9a-zA-Z_]* +#define DATA_MAIN .data .data.[0-9a-zA-Z_]* +#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* +#else +#define TEXT_MAIN .text +#define DATA_MAIN .data +#define BSS_MAIN .bss +#endif + +/* * Align to a 32 byte boundary equal to the * alignment gcc 4.5 uses for a struct */ @@ -198,12 +214,9 @@ /* * .data section - * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections generates - * .data.identifier which needs to be pulled in with .data, but don't want to - * pull in .data..stuff which has its own requirements. Same for bss. */ #define DATA_DATA \ - *(.data .data.[0-9a-zA-Z_]*) \ + *(DATA_MAIN) \ *(.ref.data) \ *(.data..shared_aligned) /* percpu related */ \ MEM_KEEP(init.data) \ @@ -434,16 +447,17 @@ VMLINUX_SYMBOL(__security_initcall_end) = .; \ } -/* .text section. Map to function alignment to avoid address changes +/* + * .text section. Map to function alignment to avoid address changes * during second ld run in second ld pass when generating System.map - * LD_DEAD_CODE_DATA_ELIMINATION option enables -ffunction-sections generates - * .text.identifier which needs to be pulled in with .text , but some - * architectures define .text.foo which is not intended to be pulled in here. - * Those enabling LD_DEAD_CODE_DATA_ELIMINATION must ensure they don't have - * conflicting section names, and must pull in .text.[0-9a-zA-Z_]* */ + * + * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead + * code elimination is enabled, so these sections should be converted + * to use ".." first. + */ #define TEXT_TEXT \ ALIGN_FUNCTION(); \ - *(.text.hot .text .text.fixup .text.unlikely) \ + *(.text.hot TEXT_MAIN .text.fixup .text.unlikely) \ *(.ref.text) \ MEM_KEEP(init.text) \ MEM_KEEP(exit.text) \ @@ -613,7 +627,7 @@ BSS_FIRST_SECTIONS \ *(.bss..page_aligned) \ *(.dynbss) \ - *(.bss .bss.[0-9a-zA-Z_]*) \ + *(BSS_MAIN) \ *(COMMON) \ }