[PATCH 7/7] scripts/faddr2line: Check only two symbols when calculating symbol size

Brian Johannesmeyer posted 7 patches 1 year, 11 months ago
There is a newer version of this series
[PATCH 7/7] scripts/faddr2line: Check only two symbols when calculating symbol size
Posted by Brian Johannesmeyer 1 year, 11 months ago
Rather than looping through each symbol in a particular section to
calculate a symbol's size, grep for the symbol and its immediate
successor, and only use those two symbols.

Signed-off-by: Brian Johannesmeyer <bjohannesmeyer@gmail.com>
---
 scripts/faddr2line | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/faddr2line b/scripts/faddr2line
index 1fa6beef9f97..70d5a4602a92 100755
--- a/scripts/faddr2line
+++ b/scripts/faddr2line
@@ -252,7 +252,7 @@ __faddr2line() {
 				found=2
 				break
 			fi
-		done < <(echo "${ELF_SYMS}" | sed 's/\[.*\]//' | ${AWK} -v sec=$sym_sec '$7 == sec' | sort --key=2)
+		done < <(echo "${ELF_SYMS}" | sed 's/\[.*\]//' | ${AWK} -v sec=$sym_sec '$7 == sec' | sort --key=2 | ${GREP} -A1 " ${sym_name}$")
 
 		if [[ $found = 0 ]]; then
 			warn "can't find symbol: sym_name: $sym_name sym_sec: $sym_sec sym_addr: $sym_addr sym_elf_size: $sym_elf_size"
-- 
2.34.1
Re: [PATCH 7/7] scripts/faddr2line: Check only two symbols when calculating symbol size
Posted by Brian Johannesmeyer 1 year, 10 months ago
On Mon, Mar 11, 2024 at 1:40 PM Brian Johannesmeyer
<bjohannesmeyer@gmail.com> wrote:
>
> Rather than looping through each symbol in a particular section to
> calculate a symbol's size, grep for the symbol and its immediate
> successor, and only use those two symbols.
>
> Signed-off-by: Brian Johannesmeyer <bjohannesmeyer@gmail.com>
> ---
>  scripts/faddr2line | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/faddr2line b/scripts/faddr2line
> index 1fa6beef9f97..70d5a4602a92 100755
> --- a/scripts/faddr2line
> +++ b/scripts/faddr2line
> @@ -252,7 +252,7 @@ __faddr2line() {
>                                 found=2
>                                 break
>                         fi
> -               done < <(echo "${ELF_SYMS}" | sed 's/\[.*\]//' | ${AWK} -v sec=$sym_sec '$7 == sec' | sort --key=2)
> +               done < <(echo "${ELF_SYMS}" | sed 's/\[.*\]//' | ${AWK} -v sec=$sym_sec '$7 == sec' | sort --key=2 | ${GREP} -A1 " ${sym_name}$")
>
>                 if [[ $found = 0 ]]; then
>                         warn "can't find symbol: sym_name: $sym_name sym_sec: $sym_sec sym_addr: $sym_addr sym_elf_size: $sym_elf_size"
> --
> 2.34.1
>

Hey Josh,

I just noticed that this patch does not correctly handle duplicate
sym_names. To fix, the "--no-group-separator" option should be added
as follows:

> -               done < <(echo "${ELF_SYMS}" | sed 's/\[.*\]//' | ${AWK} -v sec=$sym_sec '$7 == sec' | sort --key=2)
> +               done < <(echo "${ELF_SYMS}" | sed 's/\[.*\]//' | ${AWK} -v sec=$sym_sec '$7 == sec' | sort --key=2 | ${GREP} -A1 --no-group-separator " ${sym_name}$")

Would you like me to re-submit the patch series with this fix?

Thanks,

Brian
Re: [PATCH 7/7] scripts/faddr2line: Check only two symbols when calculating symbol size
Posted by Josh Poimboeuf 1 year, 10 months ago
On Thu, Apr 11, 2024 at 12:28:29PM -0700, Brian Johannesmeyer wrote:
> Hey Josh,
> 
> I just noticed that this patch does not correctly handle duplicate
> sym_names. To fix, the "--no-group-separator" option should be added
> as follows:
> 
> > -               done < <(echo "${ELF_SYMS}" | sed 's/\[.*\]//' | ${AWK} -v sec=$sym_sec '$7 == sec' | sort --key=2)
> > +               done < <(echo "${ELF_SYMS}" | sed 's/\[.*\]//' | ${AWK} -v sec=$sym_sec '$7 == sec' | sort --key=2 | ${GREP} -A1 --no-group-separator " ${sym_name}$")
> 
> Would you like me to re-submit the patch series with this fix?

Yes, that would be helpful.  Thanks!

-- 
Josh