From patchwork Mon Jan 25 14:19:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 60365 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp1385303lbb; Mon, 25 Jan 2016 06:20:08 -0800 (PST) X-Received: by 10.66.129.232 with SMTP id nz8mr26254486pab.102.1453731608305; Mon, 25 Jan 2016 06:20:08 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sl3si7058434pac.220.2016.01.25.06.20.07; Mon, 25 Jan 2016 06:20:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756826AbcAYOUB (ORCPT + 30 others); Mon, 25 Jan 2016 09:20:01 -0500 Received: from mail-wm0-f49.google.com ([74.125.82.49]:34577 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756596AbcAYOTx (ORCPT ); Mon, 25 Jan 2016 09:19:53 -0500 Received: by mail-wm0-f49.google.com with SMTP id u188so67704465wmu.1 for ; Mon, 25 Jan 2016 06:19:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RClpHjO/lJNEPR4iBaCm/Omv1NFNJ/KGUeYGa6iZl0Q=; b=bpdGx2iEQURZYwE3csxCm7pQDimQz5autLaGP5nlU+09/DxveQZX0lIDTfrXamzNvV MogRrLgq0PtqKDTWTj5G5u5l6gVq5Xc2av7x7aZ1lublD7DBdu/6YbvNcEGuKArvEa2l 1eEA+KKBg9M50n0J3w0cqbumOw/D3INJwjJcA= 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:in-reply-to :references; bh=RClpHjO/lJNEPR4iBaCm/Omv1NFNJ/KGUeYGa6iZl0Q=; b=dyf1+8iCZsdw1+xrk6+W3qq5qtpqTi9JwHq+iKhHz4U615D9w99htR6l5Za2UVToXm ujsx27yp1NE4VXQojwj0EOrbMTNFwhIqy+YlSTXLODKx1JesttuJpkfMn5GfLaM0NUfc 4WjkW77LDghycH4ONhJh3FyJ5dVW4KKq48oJivm4wOV9MylEboIzvvIxXR95tvIzWMfY bRfy5XNG/Vgkeqi5VdQ6rnvPhWM7Z75CVYj7Vjx/oLK2Ivk+fwVhVzNE7bu/MZvQoPIR w1wlLjuFomBbmdmq+1EL40QCDfOMatMzbrrlReJMDecOHWm5SIS2jImO3QMt7xyjrbZ9 B2ZA== X-Gm-Message-State: AG10YORJunDa83wsm3nYULrNrjHSf/eaY8SmQ008Z8kXOLkgbwGD9huVebGGwEiJRNkEsmEu X-Received: by 10.28.48.131 with SMTP id w125mr17472323wmw.18.1453731591638; Mon, 25 Jan 2016 06:19:51 -0800 (PST) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id c15sm16425805wmd.19.2016.01.25.06.19.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Jan 2016 06:19:50 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, keescook@chromium.org, akpm@linux-foundation.org, mingo@kernel.org, hpa@zytor.com, heiko.carstens@de.ibm.com, benh@kernel.crashing.org, mpe@ellerman.id.au, mmarek@suse.cz, rusty@rustcorp.com.au, arnd@arndb.de, linux-arch@vger.kernel.org, linux@roeck-us.net Cc: Ard Biesheuvel Subject: [PATCH v4 2/3] kallsyms: don't overload absolute symbol type for percpu symbols Date: Mon, 25 Jan 2016 15:19:31 +0100 Message-Id: <1453731572-18448-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1453731572-18448-1-git-send-email-ard.biesheuvel@linaro.org> References: <1453731572-18448-1-git-send-email-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit c6bda7c988a5 ("kallsyms: fix percpu vars on x86-64 with relocation") overloaded the 'A' (absolute) symbol type to signify that a symbol is not subject to dynamic relocation. However, the original A type does not imply that at all, and depending on the version of the toolchain, many A type symbols are emitted that are in fact relative to the kernel text, i.e., if the kernel is relocated at runtime, these symbols should be updated as well. For instance, on sparc32, the following symbols are emitted as absolute (kindly provided by Guenter Roeck): f035a420 A _etext f03d9000 A _sdata f03de8c4 A jiffies f03f8860 A _edata f03fc000 A __init_begin f041bdc8 A __init_text_end f0423000 A __bss_start f0423000 A __init_end f044457d A __bss_stop f044457d A _end On x86_64, similar behavior can be observed: ffffffff81a00000 A __end_rodata_hpage_align ffffffff81b19000 A __vvar_page ffffffff81d3d000 A _end Even if only a couple of them pass the symbol range check that results in them to be taken into account for the final kallsyms symbol table, it is obvious that 'A' does not mean the symbol does not need to be updated at relocation time, and overloading its meaning to signify that is perhaps not a good idea. So instead, add a new percpu_absolute member to struct sym_entry, and when --absolute-percpu is in effect, use it to record symbols whose addresses should be emitted as final values rather than values that still require relocation at runtime. That way, we can drop the check against the 'A' type. Signed-off-by: Ard Biesheuvel --- scripts/kallsyms.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) -- 2.5.0 diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 8fa81e84e295..d39a1eeb080e 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -34,6 +34,7 @@ struct sym_entry { unsigned int len; unsigned int start_pos; unsigned char *sym; + unsigned int percpu_absolute; }; struct addr_range { @@ -171,6 +172,8 @@ static int read_symbol(FILE *in, struct sym_entry *s) strcpy((char *)s->sym + 1, str); s->sym[0] = stype; + s->percpu_absolute = 0; + /* Record if we've found __per_cpu_start/end. */ check_symbol_range(sym, s->addr, &percpu_range, 1); @@ -325,7 +328,7 @@ static int expand_symbol(unsigned char *data, int len, char *result) static int symbol_absolute(struct sym_entry *s) { - return toupper(s->sym[0]) == 'A'; + return s->percpu_absolute; } static void write_src(void) @@ -681,8 +684,15 @@ static void make_percpus_absolute(void) unsigned int i; for (i = 0; i < table_cnt; i++) - if (symbol_in_range(&table[i], &percpu_range, 1)) + if (symbol_in_range(&table[i], &percpu_range, 1)) { + /* + * Keep the 'A' override for percpu symbols to + * ensure consistent behavior compared to older + * versions of this tool. + */ table[i].sym[0] = 'A'; + table[i].percpu_absolute = 1; + } } int main(int argc, char **argv)