mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Srikar Dronamraju <srikar@linux.ibm.com>
To: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Brian Johannesmeyer <bjohannesmeyer@gmail.com>,
	Madhavan Srinivasan <maddy@linux.ibm.com>,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Revert "scripts/faddr2line: Combine three readelf calls into one"
Date: Tue, 15 Sep 2026 07:45:37 +0530	[thread overview]
Message-ID: <aqiqScJg8Ey5QnKl@linux.ibm.com> (raw)
In-Reply-To: <aqhDm60zSZIazrnC@jpoimboe>

* Josh Poimboeuf <jpoimboe@kernel.org> [2026-09-14 12:00:26]:

> > It could be a bug in Powerpc readelf that this line doesnt get printed.
> > However since its breaking with existing readelf, its better to be
> > reverted.
> > 
> > With the revert, we end up calling readelf three times but this should
> > still be fine since calling faddr2line is a debug tool.
> > 
> > Fixes: b8d9d9496c1e ("scripts/faddr2line: Combine three readelf calls into one")
> > Signed-off-by: Srikar Dronamraju <srikar@linux.ibm.com>
> 
> Can you run
> 
>   bash -x scripts/faddr2line ./vmlinux need_active_balance+0x1d4/0x21c
> 

+ set -o errexit
+ set -o nounset
+ UTIL_SUFFIX=
+ [[ '' == '' ]]
+ UTIL_PREFIX=
+ READELF=readelf
+ ADDR2LINE=addr2line
+ AWK=awk
+ GREP=grep
+ export LC_ALL=C
+ LC_ALL=C
+ command -v awk
+ command -v readelf
+ command -v addr2line
+ [[ 2 -lt 2 ]]
+ objfile=./vmlinux
+ LIST=0
+ [[ ./vmlinux == \-\-\l\i\s\t ]]
+ [[ ! -f ./vmlinux ]]
+ shift
+ run_readelf ./vmlinux
+ local objfile=./vmlinux
+ local tmpfile
++ mktemp
+ tmpfile=/tmp/tmp.BGkKH2pxoy
+ readelf --file-header --section-headers --symbols --wide ./vmlinux
++ sed -n '/There are [0-9]* section headers, starting at offset\|Section Headers:/q;p' /tmp/tmp.BGkKH2pxoy
+ ELF_FILEHEADER='ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2'\''s complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           PowerPC64
  Version:                           0x1
  Entry point address:               0xc000000000000000
  Start of program headers:          64 (bytes into file)
  Start of section headers:          425572840 (bytes into file)
  Flags:                             0x2, abiv2
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         2
  Size of section headers:           64 (bytes)
  Number of section headers:         61
  Section header string table index: 60'
++ sed -n '/Symbol table .* contains [0-9]* entries:/q;p'
++ sed -n '/There are [0-9]* section headers, starting at offset\|Section Headers:/,$p' /tmp/tmp.BGkKH2pxoy
+ ELF_SECHEADERS='Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .head.text        PROGBITS        c000000000000000 010000 008000 00  AX  0   0 128
  [ 2] .text             PROGBITS        c000000000008000 018000 1474ed4 00  AX  0   0 256
  [ 3] .rodata           PROGBITS        c000000001480000 1490000 6217ce 00  WA  0   0 65536
  [ 4] .pci_fixup        PROGBITS        c000000001aa17d0 1ab17d0 004590 00  WA  0   0  8
  [ 5] .printk_index     PROGBITS        c000000001aa5d60 1ab5d60 00f770 00  WA  0   0  8
  [ 6] __ksymtab         PROGBITS        c000000001ab54d0 1ac54d0 045120 00   A  0   0  8
  [ 7] __kcrctab         PROGBITS        c000000001afa5f0 1b0a5f0 00b830 00   A  0   0  4
  [ 8] __kflagstab       PROGBITS        c000000001b05e20 1b15e20 002e0c 00   A  0   0  1
  [ 9] __ksymtab_strings PROGBITS        c000000001b08c2c 1b18c2c 039a9c 01 AMS  0   0  1
  [10] __param           PROGBITS        c000000001b426c8 1b526c8 002e18 00  WA  0   0  8
  [11] __modver          PROGBITS        c000000001b454e0 1b554e0 0005a0 00  WA  0   0  8
  [12] __ex_table        PROGBITS        c000000001b45a80 1b55a80 002ab8 00   A  0   0  4
  [13] .notes            NOTE            c000000001b48538 1b58538 000088 00   A  0   0  4
  [14] .BTF              PROGBITS        c000000001b50000 1b60000 4d833d 00   A  0   0  1
  [15] .BTF_ids          PROGBITS        c000000002030000 2040000 00138c 00   A  0   0  1
  [16] .branch_lt        PROGBITS        c000000002040000 2050000 003030 00  WA  0   0  8
  [17] .got              PROGBITS        c000000002043100 2053100 000380 08  WA  0   0 256
  [18] __soft_mask_table PROGBITS        c000000002043480 2053480 000080 00   A  0   0  8
  [19] __restart_table   PROGBITS        c000000002043500 2053500 0000c0 00   A  0   0  8
  [20] __stf_entry_barrier_fixup PROGBITS        c0000000020435c0 20535c0 0001e8 00   A  0   0  4
  [21] __uaccess_flush_fixup PROGBITS        c0000000020437a8 20537a8 000008 00   A  0   0  4
  [22] __entry_flush_fixup PROGBITS        c0000000020437b0 20537b0 0001d8 00   A  0   0  4
  [23] __scv_entry_flush_fixup PROGBITS        c000000002043988 2053988 000010 00   A  0   0  4
  [24] __stf_exit_barrier_fixup PROGBITS        c000000002043998 2053998 000060 00   A  0   0  4
  [25] __rfi_flush_fixup PROGBITS        c0000000020439f8 20539f8 000060 00   A  0   0  4
  [26] __spec_barrier_fixup PROGBITS        c000000002043a58 2053a58 000690 00   A  0   0  4
  [27] .init.text        PROGBITS        c000000003000000 3010000 0b0000 00 WAX  0   0 32
  [28] .exit.text        PROGBITS        c0000000030b0000 30c0000 004158 00  AX  0   0 32
  [29] .init.data        PROGBITS        c0000000030c0000 30d0000 1c4580 00  WA  0   0 65536
  [30] __ftr_fixup       PROGBITS        c000000003284580 3294580 00eaf0 00   A  0   0  8
  [31] __mmu_ftr_fixup   PROGBITS        c000000003293070 32a3070 001830 00   A  0   0  8
  [32] __lwsync_fixup    PROGBITS        c0000000032948a0 32a48a0 000dc8 00   A  0   0  4
  [33] .data..percpu     PROGBITS        c0000000032a0000 32b0000 1e0e58 00  WA  0   0 4096
  [34] .machine.desc     PROGBITS        c000000003480e58 3490e58 000410 00  WA  0   0  8
  [35] .dynsym           DYNSYM          c000000003481268 3491268 000048 18   A 36   3  8
  [36] .dynstr           STRTAB          c0000000034812b0 34912b0 000001 00   A  0   0  1
  [37] .dynamic          DYNAMIC         c0000000034812b8 34912b8 000120 10  WA 36   0  8
  [38] .gnu.hash         GNU_HASH        c0000000034813d8 34913d8 00001c 00   A 35   0  8
  [39] .rela.dyn         RELA            c0000000034813f8 34913f8 519030 18   A 35   0  8
  [40] .data             PROGBITS        c0000000039a0000 39b0000 610100 00  WA  0   0 128
  [41] .data..init_task  NOBITS          c000000003fb4000 3fc0100 004000 00  WA  0   0  1
  [42] .data..page_aligned PROGBITS        c000000003fc0000 3fd0000 010000 00  WA  0   0 65536
  [43] .data..cacheline_aligned PROGBITS        c000000003fd0000 3fe0000 023500 00  WA  0   0 128
  [44] .data..read_mostly PROGBITS        c000000003ff3500 4003500 03cb80 00  WA  0   0 128
  [45] .data_nosave      PROGBITS        c000000004040000 407bcec 000000 00   W  0   0  1
  [46] __bug_table       PROGBITS        c000000004040000 4050000 02bcec 00  WA  0   0  1
  [47] .bss              NOBITS          c000000004070000 407bcec 725338 00  WA  0   0 65536
  [48] .debug_aranges    PROGBITS        0000000000000000 407bcf0 0279d0 00      0   0 16
  [49] .debug_info       PROGBITS        0000000000000000 40a36c0 fa4d575 00      0   0  1
  [50] .debug_abbrev     PROGBITS        0000000000000000 13af0c35 673114 00      0   0  1
  [51] .debug_line       PROGBITS        0000000000000000 14163d49 211a8e7 00      0   0  1
  [52] .debug_frame      PROGBITS        0000000000000000 1627e630 3ba1f8 00      0   0  8
  [53] .debug_str        PROGBITS        0000000000000000 16638828 426e36 01  MS  0   0  1
  [54] .debug_line_str   PROGBITS        0000000000000000 16a5f65e 0004f5 01  MS  0   0  1
  [55] .debug_loclists   PROGBITS        0000000000000000 16a5fb53 1efdaf5 00      0   0  1
  [56] .debug_rnglists   PROGBITS        0000000000000000 1895d648 4d9186 00      0   0  1
  [57] .comment          PROGBITS        0000000000000000 18e367ce 00002e 01  MS  0   0  1
  [58] .symtab           SYMTAB          0000000000000000 18e36800 42b670 18     59 150524  8
  [59] .strtab           STRTAB          0000000000000000 19261e70 379870 00      0   0  1
  [60] .shstrtab         STRTAB          0000000000000000 195db6e0 000302 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), p (processor specific)'

> to see what line it's failing at?
>

As you can see, the last executed line line is

ELF_SECHEADERS=$(sed -n '/There are [0-9]* section headers, starting at offset\|Section Headers:/,$p' "$tmpfile" | sed -n '/Symbol table .* contains [0-9]* entries:/q;p')
which it self is called from run_readelf

since sed -o errexit is set in the script, sed returns an non-zero error
and that causes the script to exit if the line is not found.

The other options are

1.  to reset sed -o errexit  in run_readelf
diff --git a/scripts/faddr2line b/scripts/faddr2line
index 622875396bcf..f1b83913d08c 100755
--- a/scripts/faddr2line
+++ b/scripts/faddr2line
@@ -116,12 +116,14 @@ run_readelf() {
 
 	${READELF} --file-header --section-headers --symbols --wide "$objfile" > "$tmpfile"
 
+	set +o errexit
 	# This assumes that readelf first prints the file header, then the section headers, then the symbols.
 	# Note: It seems that GNU readelf does not prefix section headers with the "There are X section headers"
 	# line when multiple options are given, so let's also match with the "Section Headers:" line.
 	ELF_FILEHEADER=$(sed -n '/There are [0-9]* section headers, starting at offset\|Section Headers:/q;p' "$tmpfile")
 	ELF_SECHEADERS=$(sed -n '/There are [0-9]* section headers, starting at offset\|Section Headers:/,$p' "$tmpfile" | sed -n '/Symbol table .* contains [0-9]* entries:/q;p')
 	ELF_SYMS=$(sed -n '/Symbol table .* contains [0-9]* entries:/,$p' "$tmpfile")
+	set -o errexit
 
 	rm -f -- "$tmpfile"
 }


2. or use || true with sed, so that it doesn't fail.

diff --git a/scripts/faddr2line b/scripts/faddr2line
index 622875396bcf..6e867b053ac4 100755
--- a/scripts/faddr2line
+++ b/scripts/faddr2line
@@ -119,9 +119,9 @@ run_readelf() {
 	# This assumes that readelf first prints the file header, then the section headers, then the symbols.
 	# Note: It seems that GNU readelf does not prefix section headers with the "There are X section headers"
 	# line when multiple options are given, so let's also match with the "Section Headers:" line.
-	ELF_FILEHEADER=$(sed -n '/There are [0-9]* section headers, starting at offset\|Section Headers:/q;p' "$tmpfile")
-	ELF_SECHEADERS=$(sed -n '/There are [0-9]* section headers, starting at offset\|Section Headers:/,$p' "$tmpfile" | sed -n '/Symbol table .* contains [0-9]* entries:/q;p')
-	ELF_SYMS=$(sed -n '/Symbol table .* contains [0-9]* entries:/,$p' "$tmpfile")
+	ELF_FILEHEADER=$(sed -n '/There are [0-9]* section headers, starting at offset\|Section Headers:/q;p' "$tmpfile" || true)
+	ELF_SECHEADERS=$(sed -n '/There are [0-9]* section headers, starting at offset\|Section Headers:/,$p' "$tmpfile" | sed -n '/Symbol table .* contains [0-9]* entries:/q;p' || true)
+	ELF_SYMS=$(sed -n '/Symbol table .* contains [0-9]* entries:/,$p' "$tmpfile" || true)
 
 	rm -f -- "$tmpfile"
 }

Note: only the SECHEADERS line needs true but adding true to just that line looks hacky.

3. remove set -o errexit for the entire file.

diff --git a/scripts/faddr2line b/scripts/faddr2line
index 622875396bcf..174ab098750f 100755
--- a/scripts/faddr2line
+++ b/scripts/faddr2line
@@ -41,7 +41,6 @@
 #   free_reserved_area at mm/page_alloc.c:6429 (discriminator 2)
 
 
-set -o errexit
 set -o nounset
 
 usage() {

4. patch I sent before, use readelf multiple times.

I have tried and verified these options work correctly too.
However I feel option 4, where we run readelf 3 times is the cleanest.

> Any chance the below fixes it?
> 
> diff --git a/scripts/faddr2line b/scripts/faddr2line
> index 622875396bcfc..550c0f9b9d473 100755
> --- a/scripts/faddr2line
> +++ b/scripts/faddr2line
> @@ -78,7 +78,7 @@ GREP="grep"
>  
>  # Enforce ASCII-only output from tools like readelf
>  # ensuring sed processes strings correctly.
> -export LANG=C
> +export LC_ALL=C
>  

As you can see above from the log, I have tried this but this doesn't help

>  command -v ${AWK} >/dev/null 2>&1 || die "${AWK} isn't installed"
>  command -v ${READELF} >/dev/null 2>&1 || die "${READELF} isn't installed"

-- 
Thanks and Regards
Srikar Dronamraju

      reply	other threads:[~2026-09-15  2:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-05  1:24 Srikar Dronamraju
2026-09-14 19:00 ` Josh Poimboeuf
2026-09-15  2:15   ` Srikar Dronamraju [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aqiqScJg8Ey5QnKl@linux.ibm.com \
    --to=srikar@linux.ibm.com \
    --cc=bjohannesmeyer@gmail.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®