diff mbox series

[v3,1/4] scripts/faddr2line: Use LLVM addr2line and readelf if LLVM=1

Message ID 20230728113415.21067-2-will@kernel.org (mailing list archive)
State New, archived
Headers show
Series Fix 'faddr2line' for LLVM arm64 builds | expand

Commit Message

Will Deacon July 28, 2023, 11:34 a.m. UTC
GNU utilities cannot necessarily parse objects built by LLVM, which can
result in confusing errors when using 'faddr2line':

$ CROSS_COMPILE=aarch64-linux-gnu- ./scripts/faddr2line vmlinux do_one_initcall+0xf4/0x260
aarch64-linux-gnu-addr2line: vmlinux: unknown type [0x13] section `.relr.dyn'
aarch64-linux-gnu-addr2line: DWARF error: invalid or unhandled FORM value: 0x25
do_one_initcall+0xf4/0x260:
aarch64-linux-gnu-addr2line: vmlinux: unknown type [0x13] section `.relr.dyn'
aarch64-linux-gnu-addr2line: DWARF error: invalid or unhandled FORM value: 0x25
$x.73 at main.c:?

Although this can be worked around by setting CROSS_COMPILE to "llvm=-",
it's cleaner to follow the same syntax as the top-level Makefile and
accept LLVM=1 as an indication to use the llvm- tools.

Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: John Stultz <jstultz@google.com>
Signed-off-by: Will Deacon <will@kernel.org>
---
 scripts/faddr2line | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Masahiro Yamada July 29, 2023, 8:47 p.m. UTC | #1
On Fri, Jul 28, 2023 at 8:34 PM Will Deacon <will@kernel.org> wrote:
>
> GNU utilities cannot necessarily parse objects built by LLVM, which can
> result in confusing errors when using 'faddr2line':
>
> $ CROSS_COMPILE=aarch64-linux-gnu- ./scripts/faddr2line vmlinux do_one_initcall+0xf4/0x260
> aarch64-linux-gnu-addr2line: vmlinux: unknown type [0x13] section `.relr.dyn'
> aarch64-linux-gnu-addr2line: DWARF error: invalid or unhandled FORM value: 0x25
> do_one_initcall+0xf4/0x260:
> aarch64-linux-gnu-addr2line: vmlinux: unknown type [0x13] section `.relr.dyn'
> aarch64-linux-gnu-addr2line: DWARF error: invalid or unhandled FORM value: 0x25
> $x.73 at main.c:?
>
> Although this can be worked around by setting CROSS_COMPILE to "llvm=-",
> it's cleaner to follow the same syntax as the top-level Makefile and
> accept LLVM=1 as an indication to use the llvm- tools.


Just a note.
The top Makefile accepts not only LLVM=1
but also LLVM=/usr/lib/llvm-16/bin/.
The latter is useful when you want to use
a particular version or a custom one.

Another idea might be to use a generic '${prefix}'
as this is not hooked to the Makefile,
but I do not have a strong opinion.




>
> Cc: Josh Poimboeuf <jpoimboe@kernel.org>
> Cc: John Stultz <jstultz@google.com>
> Signed-off-by: Will Deacon <will@kernel.org>
> ---
>  scripts/faddr2line | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/faddr2line b/scripts/faddr2line
> index 0e73aca4f908..62a3fa6f6f59 100755
> --- a/scripts/faddr2line
> +++ b/scripts/faddr2line
> @@ -58,8 +58,14 @@ die() {
>         exit 1
>  }
>
> -READELF="${CROSS_COMPILE:-}readelf"
> -ADDR2LINE="${CROSS_COMPILE:-}addr2line"
> +if [ "${LLVM:-}" == "1" ]; then
> +       UTIL_PREFIX=llvm-
> +else
> +       UTIL_PREFIX=${CROSS_COMPILE:-}
> +fi
> +
> +READELF="${UTIL_PREFIX}readelf"
> +ADDR2LINE="${UTIL_PREFIX}addr2line"
>  AWK="awk"
>  GREP="grep"
>
> --
> 2.41.0.487.g6d72f3e995-goog
>
Nick Desaulniers Aug. 1, 2023, 4:50 p.m. UTC | #2
On Sat, Jul 29, 2023 at 1:48 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Fri, Jul 28, 2023 at 8:34 PM Will Deacon <will@kernel.org> wrote:
> >
> > GNU utilities cannot necessarily parse objects built by LLVM, which can
> > result in confusing errors when using 'faddr2line':
> >
> > $ CROSS_COMPILE=aarch64-linux-gnu- ./scripts/faddr2line vmlinux do_one_initcall+0xf4/0x260
> > aarch64-linux-gnu-addr2line: vmlinux: unknown type [0x13] section `.relr.dyn'

^ old GNU binutils missing support for RELR relocation format.
https://maskray.me/blog/2021-10-31-relative-relocations-and-relr

> > aarch64-linux-gnu-addr2line: DWARF error: invalid or unhandled FORM value: 0x25

^ old GNU binutils missing support for DWARFv5

I suppose if someone used a new GCC with an old binutils, they could
observe the exact same errors.

> > do_one_initcall+0xf4/0x260:
> > aarch64-linux-gnu-addr2line: vmlinux: unknown type [0x13] section `.relr.dyn'
> > aarch64-linux-gnu-addr2line: DWARF error: invalid or unhandled FORM value: 0x25
> > $x.73 at main.c:?
> >
> > Although this can be worked around by setting CROSS_COMPILE to "llvm=-",
> > it's cleaner to follow the same syntax as the top-level Makefile and
> > accept LLVM=1 as an indication to use the llvm- tools.
>
>
> Just a note.
> The top Makefile accepts not only LLVM=1
> but also LLVM=/usr/lib/llvm-16/bin/.
> The latter is useful when you want to use
> a particular version or a custom one.

Ah, like LLVM_PREFIX/LLVM_SUFFIX a la
commit e9c281928c24 ("kbuild: Make $(LLVM) more flexible")

Then we could have both UTIL_PREFIX+UTIL_SUFFIX.

>
> Another idea might be to use a generic '${prefix}'
> as this is not hooked to the Makefile,
> but I do not have a strong opinion.
>
>
>
>
> >
> > Cc: Josh Poimboeuf <jpoimboe@kernel.org>
> > Cc: John Stultz <jstultz@google.com>
> > Signed-off-by: Will Deacon <will@kernel.org>
> > ---
> >  scripts/faddr2line | 10 ++++++++--
> >  1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/scripts/faddr2line b/scripts/faddr2line
> > index 0e73aca4f908..62a3fa6f6f59 100755
> > --- a/scripts/faddr2line
> > +++ b/scripts/faddr2line
> > @@ -58,8 +58,14 @@ die() {
> >         exit 1
> >  }
> >
> > -READELF="${CROSS_COMPILE:-}readelf"
> > -ADDR2LINE="${CROSS_COMPILE:-}addr2line"
> > +if [ "${LLVM:-}" == "1" ]; then
> > +       UTIL_PREFIX=llvm-
> > +else
> > +       UTIL_PREFIX=${CROSS_COMPILE:-}
> > +fi
> > +
> > +READELF="${UTIL_PREFIX}readelf"
> > +ADDR2LINE="${UTIL_PREFIX}addr2line"
> >  AWK="awk"
> >  GREP="grep"
> >
> > --
> > 2.41.0.487.g6d72f3e995-goog
> >
>
>
> --
> Best Regards
> Masahiro Yamada
diff mbox series

Patch

diff --git a/scripts/faddr2line b/scripts/faddr2line
index 0e73aca4f908..62a3fa6f6f59 100755
--- a/scripts/faddr2line
+++ b/scripts/faddr2line
@@ -58,8 +58,14 @@  die() {
 	exit 1
 }
 
-READELF="${CROSS_COMPILE:-}readelf"
-ADDR2LINE="${CROSS_COMPILE:-}addr2line"
+if [ "${LLVM:-}" == "1" ]; then
+	UTIL_PREFIX=llvm-
+else
+	UTIL_PREFIX=${CROSS_COMPILE:-}
+fi
+
+READELF="${UTIL_PREFIX}readelf"
+ADDR2LINE="${UTIL_PREFIX}addr2line"
 AWK="awk"
 GREP="grep"