Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp120737ybi; Fri, 24 May 2019 00:57:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzcnroy6GRatVqgNJVpGL2Qu+OwWqsfIIrG41uAMYyubTmL+X7EIV51tl+gSU4A2nASp2wm X-Received: by 2002:a17:90a:9281:: with SMTP id n1mr6921019pjo.25.1558684659484; Fri, 24 May 2019 00:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558684659; cv=none; d=google.com; s=arc-20160816; b=G0Y4H5P+JSzotWv1Pc1PYApHfOvaVdmN2hQNw+3vMdB1J8DGNqiaOBRdM1ahjxkGo6 4nGphSFaACJ9f4UncCkrmoi+y/vFJrVv//xfXjpnXZctPIDwTqArsklCvY7kvqgfZ19+ O+OxAw8UrFIs7ZTlQUoYjhTtUyuHwkoHE1jqRViaHshB5cAbQ3adwJNGklUa7U+R5pcD JBpUnIVWRlLIKyN86ajJboApZiDFi9OcPUpgMtC9UXQFHwSMJNHkTEiVqPMOGrgE4V/a ZzjcExHcEFxZyfRMQRQQJ7zLYAISRBssPX8Z5NTlAWOvdRntRQSXF8e/vxf02JAS32RI +X1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=7ue/ep41Vyg8fSLSDglj3sGoiM9LEN1HNpkcUicUI6U=; b=DjGjwJdZWbNHTcAJGU4WcGs8Av94j4ZKGZWyqr0kXTWQjycItDEGgHymc3axronXgq bnyt4hzaUHIiqN4fpiLYp4SNJthjy/jTNwGb5RgcXf5t1bbr0U10hsv12rbJ0sv8nxtX C8z5Lc5uo/wHTxuXnn1SVwTHt6+mRHOubVEyZcB6ycA/tGJG7jI8XHu8trUvSuPawskM CA2Un9r7/d2YNOzoTuZJ8XY+/9nwBFlvdFvoQ/6tMRi17LFUwkjwYSp1ikGJnB3qpZEc QjIh1HFqOoUx4XN+K9TkzbVcNAWOimnYEaPNlCaoxTV7Q9sStuiFBEzNbGxw3nz/+Yd1 QWTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=JB5pkOeJ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c3si2854793pgd.148.2019.05.24.00.57.17; Fri, 24 May 2019 00:57:39 -0700 (PDT) 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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=JB5pkOeJ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389108AbfEXHzi (ORCPT + 99 others); Fri, 24 May 2019 03:55:38 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:42570 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388911AbfEXHzh (ORCPT ); Fri, 24 May 2019 03:55:37 -0400 Received: by mail-ed1-f68.google.com with SMTP id l25so13077711eda.9 for ; Fri, 24 May 2019 00:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=7ue/ep41Vyg8fSLSDglj3sGoiM9LEN1HNpkcUicUI6U=; b=JB5pkOeJMcdznnxHA7EyvlDBD8kuWGGxJzJIm6zBQCA95i7RQfE9ZLDn22tH7/SMcx Vjnz8tYhz5v94YKCxoVnrFflGYBMgg0nvsFN34BzF9h7CzAfMI/2ZENpkKZqDOnhnQSP 2CsgEEVbKks4nsSj2EoWh/+np6xjXWKvimIzqqs52FYxkBdnBQzOF3Ym1IFaoOXSipkx 6EEoVeAp7QcSk8XWZgzoRo/8roAdwxxUQDrR99bcuyLQsOl7ybIKfXRYisoeetI5kXh3 vkdfkg2QHppvCqg8UKta4LeMk5nnaeFtH0kySTiw9D6aVrqEBhADcK7J32vZllUWBkOV edXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :mime-version:content-disposition:user-agent; bh=7ue/ep41Vyg8fSLSDglj3sGoiM9LEN1HNpkcUicUI6U=; b=Eug/Zpn8dglKsbBvefx7lBlefHENWNJLoRfLRwNfmvhaCT7Rz56jgdtgXI8F0OQpqy 08+Of16R2UUTa1OVjB1DXY2TeaCoTZlO3L6kGbKZT8HFhcGe+1cg/9gTHM9x/2Q9nysT EbsJoiwi5DpZgk5QlLeFQLOSCZgCxmouinQgP5XVrJ2t5pYmRV92dFomBjxC5KSAQxYB vW6qzodQiqJ8Iq9W8MdrSodox56WeQ11he9frBLru63eBMgm3tIqa5V31DTGb/aHfBUo UE90smg9IjMlQj/w7GvlE8K2g/RpvAdPMSKKEv6JxQIbpr0T3j5GDxQDrqG8xSZ8I7c0 eLoA== X-Gm-Message-State: APjAAAUDw7w480Tf8xuHx0WlMB+tFhhensRX4K8pnQCUnXAvXLyooUrZ p65I+pz0CMsBpiGyVIyyKdLX3QhOHPg= X-Received: by 2002:a17:906:704d:: with SMTP id r13mr19015110ejj.295.1558684536014; Fri, 24 May 2019 00:55:36 -0700 (PDT) Received: from dumbo ([83.137.6.243]) by smtp.gmail.com with ESMTPSA id e33sm538060edd.53.2019.05.24.00.55.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 May 2019 00:55:35 -0700 (PDT) Date: Fri, 24 May 2019 09:55:32 +0200 From: Domenico Andreoli To: Masahiro Yamada , Michal Marek Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2] Improve diagnosis when "Inconsistent kallsyms data" happens Message-ID: <20190524075532.zzya47562tgejgn4@dumbo> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, linking kallsyms into the kernel occasionally triggers edge conditions of the linker heuristic and results in inconsistent System.map generation. This patch adds a first-aid analysis of such inconsistency in form of unified diff between the two generated symbol maps, where every symbol's address is replaced by the offset from the previous symbol. Becomes then trivial to spot symbols reordering without incurring in the noise of other symbols shifting, as shown below. $ make ... LD vmlinux.o MODPOST vmlinux.o KSYM .tmp_kallsyms1.o KSYM .tmp_kallsyms2.o KSYM .tmp_kallsyms3.o LD vmlinux SORTEX vmlinux SYSMAP System.map SYSMAP .tmp_System.map.relative SYSMAP System.map.relative Inconsistent kallsyms data Try "make KALLSYMS_EXTRA_PASS=1" as a workaround ----- .tmp_System.map.relative 2019-05-24 09:43:45.249819728 +0200 +++++ System.map.relative 2019-05-24 09:43:42.196968172 +0200 @@ -7,10 +7,10 @@ 0000000000013cf78 A __rela_size 0000000000012da88 A __pecoff_data_rawsize 0000000000004e600 A __pecoff_data_size -000000000004b7000 A __efistub_stext_offset +000000000004a7000 A __efistub_stext_offset 000000000001719d8 A __rela_offset 0000000000026b628 A _kernel_size_le_lo32 -0ffff00000f4b3000 t __efistub__text +0ffff00000f4c3000 t __efistub__text 00000000000000000 t _head 00000000000000000 T _text 00000000000000040 t pe_header @@ -28619,10 +28619,10 @@ 00000000000000008 r bus_spec.64271 00000000000000008 r str_spec.64272 00000000000000008 R kallsyms_offsets -00000000000019bd0 R kallsyms_relative_base +00000000000019bc8 R kallsyms_relative_base 00000000000000008 R kallsyms_num_syms 00000000000000008 R kallsyms_names -0000000000004c468 R kallsyms_markers +0000000000004c460 R kallsyms_markers 000000000000001a0 R kallsyms_token_table 00000000000000368 R kallsyms_token_index 000000000000838c8 R __start_ro_after_init ... Changes in v2: - *.relative files are generated by a separate function and only when needed, this saves time and does not leave unused files around in case of successful build Signed-off-by: Domenico Andreoli --- scripts/link-vmlinux.sh | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) Index: b/scripts/link-vmlinux.sh =================================================================== --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -126,6 +126,28 @@ mksysmap() ${CONFIG_SHELL} "${srctree}/scripts/mksysmap" ${1} ${2} } +# Replace the symbol's address with the offset from the previous so +# that in case of "Inconsistent kallsyms data" it's easier to spot +# symbols moving around +mksysmap_relative() +{ + local addr + local addr_size + local addr_prev + local remainder + + info SYSMAP ${2} + while read addr remainder; do + if [ -z "${addr_prev}" ]; then + addr_size=`echo ${addr} | wc -c` + addr_prev=${addr} + fi + printf "%0${addr_size}x " $(( 0x${addr} - 0x${addr_prev} )) + echo ${remainder} + addr_prev=${addr} + done <${1} >${2} +} + sortextable() { ${objtree}/scripts/sortextable ${1} @@ -134,10 +156,10 @@ sortextable() # Delete output files in case of error cleanup() { - rm -f .tmp_System.map + rm -f .tmp_System.map* rm -f .tmp_kallsyms* rm -f .tmp_vmlinux* - rm -f System.map + rm -f System.map* rm -f vmlinux rm -f vmlinux.o } @@ -261,8 +283,13 @@ if [ -n "${CONFIG_KALLSYMS}" ]; then mksysmap ${kallsyms_vmlinux} .tmp_System.map if ! cmp -s System.map .tmp_System.map; then + mksysmap_relative .tmp_System.map .tmp_System.map.relative + mksysmap_relative System.map System.map.relative + echo >&2 Inconsistent kallsyms data - echo >&2 Try "make KALLSYMS_EXTRA_PASS=1" as a workaround + echo >&2 Try \"make KALLSYMS_EXTRA_PASS=1\" as a workaround + diff >&2 -u .tmp_System.map.relative System.map.relative + exit 1 fi fi