llvm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] modpost: Skip .llvm.call-graph-profile section check
@ 2023-08-22  6:52 Denis Nikitin
  2023-08-22  7:05 ` Fangrui Song
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Denis Nikitin @ 2023-08-22  6:52 UTC (permalink / raw)
  To: linux-kbuild
  Cc: denik, Masahiro Yamada, Nathan Chancellor, Nick Desaulniers,
	Nicolas Schier, Tom Rix, linux-kernel, llvm

.llvm.call-graph-profile section is added when the kernel is built with
profiles (e.g. -fprofile-sample-use=<llvm.profile>). The section holds
metadata for symbols beloning to other sections and hence doesn't need
modpost checks.

This change fixes the kernel build with sample profiles which fails
with:
"FATAL: modpost: Please add code to calculate addend for this architecture"

Signed-off-by: Denis Nikitin <denik@chromium.org>
---
 scripts/mod/modpost.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index b29b29707f10..64bd13f7199c 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -761,6 +761,7 @@ static const char *const section_white_list[] =
 	".fmt_slot*",			/* EZchip */
 	".gnu.lto*",
 	".discard.*",
+	".llvm.call-graph-profile",	/* call graph */
 	NULL
 };
 
-- 
2.42.0.rc1.204.g551eb34607-goog


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] modpost: Skip .llvm.call-graph-profile section check
  2023-08-22  6:52 [PATCH] modpost: Skip .llvm.call-graph-profile section check Denis Nikitin
@ 2023-08-22  7:05 ` Fangrui Song
  2023-08-22 17:17   ` Denis Nikitin
  2023-08-22 15:47 ` Nick Desaulniers
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Fangrui Song @ 2023-08-22  7:05 UTC (permalink / raw)
  To: Denis Nikitin
  Cc: linux-kbuild, Masahiro Yamada, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, Tom Rix, linux-kernel, llvm

On Mon, Aug 21, 2023 at 11:54 PM Denis Nikitin <denik@chromium.org> wrote:
>
> .llvm.call-graph-profile section is added when the kernel is built with
> profiles (e.g. -fprofile-sample-use=<llvm.profile>).

Right. .llvm.call-graph-profile may also be added when the kernel is
built with clang -fprofile-use= (though instrumentation-based PGO
support is not upstreamed yet).

> The section holds
> metadata for symbols beloning to other sections and hence doesn't need
> modpost checks.

Typo: belonging.

.llvm.call-graph-profile contains edge information derived from text
sections, so .llvm.call-graph-profile itself doesn't need more
analysis as the text sections have been analyzed.

> This change fixes the kernel build with sample profiles which fails
> with:
> "FATAL: modpost: Please add code to calculate addend for this architecture"
>
> Signed-off-by: Denis Nikitin <denik@chromium.org>
> ---
>  scripts/mod/modpost.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index b29b29707f10..64bd13f7199c 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -761,6 +761,7 @@ static const char *const section_white_list[] =
>         ".fmt_slot*",                   /* EZchip */
>         ".gnu.lto*",
>         ".discard.*",
> +       ".llvm.call-graph-profile",     /* call graph */
>         NULL
>  };
>
> --
> 2.42.0.rc1.204.g551eb34607-goog
>
>

Otherwise the change looks good to me.


-- 
宋方睿

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] modpost: Skip .llvm.call-graph-profile section check
  2023-08-22  6:52 [PATCH] modpost: Skip .llvm.call-graph-profile section check Denis Nikitin
  2023-08-22  7:05 ` Fangrui Song
@ 2023-08-22 15:47 ` Nick Desaulniers
  2023-08-22 17:21   ` Denis Nikitin
  2023-08-22 17:48 ` [PATCH v2] " Denis Nikitin
  2023-08-25  7:27 ` [PATCH v3] " Denis Nikitin
  3 siblings, 1 reply; 16+ messages in thread
From: Nick Desaulniers @ 2023-08-22 15:47 UTC (permalink / raw)
  To: Denis Nikitin
  Cc: linux-kbuild, Masahiro Yamada, Nathan Chancellor, Nicolas Schier,
	Tom Rix, linux-kernel, llvm

On Mon, Aug 21, 2023 at 11:54 PM Denis Nikitin <denik@chromium.org> wrote:
>
> .llvm.call-graph-profile section is added when the kernel is built with
> profiles (e.g. -fprofile-sample-use=<llvm.profile>). The section holds
> metadata for symbols beloning to other sections and hence doesn't need
> modpost checks.
>
> This change fixes the kernel build with sample profiles which fails
> with:
> "FATAL: modpost: Please add code to calculate addend for this architecture"
>
> Signed-off-by: Denis Nikitin <denik@chromium.org>

Thanks for the patch. If you send a v2 with Fangrui's suggested
changes+additions, feel free to carry forward my reviewed by tag.

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>  scripts/mod/modpost.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index b29b29707f10..64bd13f7199c 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -761,6 +761,7 @@ static const char *const section_white_list[] =
>         ".fmt_slot*",                   /* EZchip */
>         ".gnu.lto*",
>         ".discard.*",
> +       ".llvm.call-graph-profile",     /* call graph */
>         NULL
>  };
>
> --
> 2.42.0.rc1.204.g551eb34607-goog
>


-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] modpost: Skip .llvm.call-graph-profile section check
  2023-08-22  7:05 ` Fangrui Song
@ 2023-08-22 17:17   ` Denis Nikitin
  0 siblings, 0 replies; 16+ messages in thread
From: Denis Nikitin @ 2023-08-22 17:17 UTC (permalink / raw)
  To: Fangrui Song
  Cc: linux-kbuild, Masahiro Yamada, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, Tom Rix, linux-kernel, llvm

Thanks for the prompt review!

On Tue, Aug 22, 2023 at 12:06 AM Fangrui Song <maskray@google.com> wrote:
>
> On Mon, Aug 21, 2023 at 11:54 PM Denis Nikitin <denik@chromium.org> wrote:
> >
> > .llvm.call-graph-profile section is added when the kernel is built with
> > profiles (e.g. -fprofile-sample-use=<llvm.profile>).
>
> Right. .llvm.call-graph-profile may also be added when the kernel is
> built with clang -fprofile-use= (though instrumentation-based PGO
> support is not upstreamed yet).

OK, I will add -fprofile-use.

> > The section holds
> > metadata for symbols beloning to other sections and hence doesn't need
> > modpost checks.
>
> Typo: belonging.
>
> .llvm.call-graph-profile contains edge information derived from text
> sections, so .llvm.call-graph-profile itself doesn't need more
> analysis as the text sections have been analyzed.

Ack.

Thanks,
Denis

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] modpost: Skip .llvm.call-graph-profile section check
  2023-08-22 15:47 ` Nick Desaulniers
@ 2023-08-22 17:21   ` Denis Nikitin
  0 siblings, 0 replies; 16+ messages in thread
From: Denis Nikitin @ 2023-08-22 17:21 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Masahiro Yamada, Nathan Chancellor, Nicolas Schier, Tom Rix,
	linux-kernel, llvm, Nick Desaulniers, Fangrui Song

On Tue, Aug 22, 2023 at 8:47 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> On Mon, Aug 21, 2023 at 11:54 PM Denis Nikitin <denik@chromium.org> wrote:
> >
> > .llvm.call-graph-profile section is added when the kernel is built with
> > profiles (e.g. -fprofile-sample-use=<llvm.profile>). The section holds
> > metadata for symbols beloning to other sections and hence doesn't need
> > modpost checks.
> >
> > This change fixes the kernel build with sample profiles which fails
> > with:
> > "FATAL: modpost: Please add code to calculate addend for this architecture"
> >
> > Signed-off-by: Denis Nikitin <denik@chromium.org>
>
> Thanks for the patch. If you send a v2 with Fangrui's suggested
> changes+additions, feel free to carry forward my reviewed by tag.
>
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
>

Thanks! Will do shortly.

- Denis

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2] modpost: Skip .llvm.call-graph-profile section check
  2023-08-22  6:52 [PATCH] modpost: Skip .llvm.call-graph-profile section check Denis Nikitin
  2023-08-22  7:05 ` Fangrui Song
  2023-08-22 15:47 ` Nick Desaulniers
@ 2023-08-22 17:48 ` Denis Nikitin
  2023-08-22 17:51   ` Fangrui Song
  2023-08-25  7:27 ` [PATCH v3] " Denis Nikitin
  3 siblings, 1 reply; 16+ messages in thread
From: Denis Nikitin @ 2023-08-22 17:48 UTC (permalink / raw)
  To: linux-kbuild
  Cc: denik, Fangrui Song, Nick Desaulniers, Masahiro Yamada,
	Nathan Chancellor, Nicolas Schier, Tom Rix, linux-kernel, llvm

.llvm.call-graph-profile section is added by clang when the kernel is
built with profiles (e.g. -fprofile-sample-use= or -fprofile-use=).

The section contains edge information derived from text sections,
so .llvm.call-graph-profile itself doesn't need more analysis as
the text sections have been analyzed.

This change fixes the kernel build with clang and a sample profile
which currently fails with:

"FATAL: modpost: Please add code to calculate addend for this architecture"

Signed-off-by: Denis Nikitin <denik@chromium.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
---
 scripts/mod/modpost.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index b29b29707f10..64bd13f7199c 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -761,6 +761,7 @@ static const char *const section_white_list[] =
 	".fmt_slot*",			/* EZchip */
 	".gnu.lto*",
 	".discard.*",
+	".llvm.call-graph-profile",	/* call graph */
 	NULL
 };
 
-- 
2.42.0.rc1.204.g551eb34607-goog


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] modpost: Skip .llvm.call-graph-profile section check
  2023-08-22 17:48 ` [PATCH v2] " Denis Nikitin
@ 2023-08-22 17:51   ` Fangrui Song
  2023-08-23 23:01     ` Masahiro Yamada
  0 siblings, 1 reply; 16+ messages in thread
From: Fangrui Song @ 2023-08-22 17:51 UTC (permalink / raw)
  To: Denis Nikitin
  Cc: linux-kbuild, Nick Desaulniers, Masahiro Yamada,
	Nathan Chancellor, Nicolas Schier, Tom Rix, linux-kernel, llvm

On Tue, Aug 22, 2023 at 10:49 AM Denis Nikitin <denik@chromium.org> wrote:
>
> .llvm.call-graph-profile section is added by clang when the kernel is
> built with profiles (e.g. -fprofile-sample-use= or -fprofile-use=).
>
> The section contains edge information derived from text sections,
> so .llvm.call-graph-profile itself doesn't need more analysis as
> the text sections have been analyzed.
>
> This change fixes the kernel build with clang and a sample profile
> which currently fails with:
>
> "FATAL: modpost: Please add code to calculate addend for this architecture"
>
> Signed-off-by: Denis Nikitin <denik@chromium.org>
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

Thanks. The new commit message looks good to me.

Reviewed-by: Fangrui Song <maskray@google.com>

> ---
>  scripts/mod/modpost.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index b29b29707f10..64bd13f7199c 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -761,6 +761,7 @@ static const char *const section_white_list[] =
>         ".fmt_slot*",                   /* EZchip */
>         ".gnu.lto*",
>         ".discard.*",
> +       ".llvm.call-graph-profile",     /* call graph */
>         NULL
>  };
>
> --
> 2.42.0.rc1.204.g551eb34607-goog
>


-- 
宋方睿

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] modpost: Skip .llvm.call-graph-profile section check
  2023-08-22 17:51   ` Fangrui Song
@ 2023-08-23 23:01     ` Masahiro Yamada
  2023-08-23 23:12       ` Denis Nikitin
  0 siblings, 1 reply; 16+ messages in thread
From: Masahiro Yamada @ 2023-08-23 23:01 UTC (permalink / raw)
  To: Fangrui Song
  Cc: Denis Nikitin, linux-kbuild, Nick Desaulniers, Nathan Chancellor,
	Nicolas Schier, Tom Rix, linux-kernel, llvm

On Wed, Aug 23, 2023 at 3:00 AM Fangrui Song <maskray@google.com> wrote:
>
> On Tue, Aug 22, 2023 at 10:49 AM Denis Nikitin <denik@chromium.org> wrote:
> >
> > .llvm.call-graph-profile section is added by clang when the kernel is
> > built with profiles (e.g. -fprofile-sample-use= or -fprofile-use=).
> >
> > The section contains edge information derived from text sections,
> > so .llvm.call-graph-profile itself doesn't need more analysis as
> > the text sections have been analyzed.
> >
> > This change fixes the kernel build with clang and a sample profile
> > which currently fails with:
> >
> > "FATAL: modpost: Please add code to calculate addend for this architecture"


Curious.

This message is only displayed for REL.

(Please not it is located in section_rel() function)


I think modern architectures use RELA instead of REL.
Which architecture are we talking about?


What does the output of this command look like?

$ llvm-readelf -S vmlinux.o | grep  .llvm.call-graph-profile


Is it REL?









> >
> > Signed-off-by: Denis Nikitin <denik@chromium.org>
> > Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
>
> Thanks. The new commit message looks good to me.
>
> Reviewed-by: Fangrui Song <maskray@google.com>
>
> > ---
> >  scripts/mod/modpost.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> > index b29b29707f10..64bd13f7199c 100644
> > --- a/scripts/mod/modpost.c
> > +++ b/scripts/mod/modpost.c
> > @@ -761,6 +761,7 @@ static const char *const section_white_list[] =
> >         ".fmt_slot*",                   /* EZchip */
> >         ".gnu.lto*",
> >         ".discard.*",
> > +       ".llvm.call-graph-profile",     /* call graph */
> >         NULL
> >  };
> >
> > --
> > 2.42.0.rc1.204.g551eb34607-goog
> >
>
>
> --
> 宋方睿



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] modpost: Skip .llvm.call-graph-profile section check
  2023-08-23 23:01     ` Masahiro Yamada
@ 2023-08-23 23:12       ` Denis Nikitin
  2023-08-23 23:54         ` Fangrui Song
  2023-08-24  1:34         ` Masahiro Yamada
  0 siblings, 2 replies; 16+ messages in thread
From: Denis Nikitin @ 2023-08-23 23:12 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Fangrui Song, linux-kbuild, Nick Desaulniers, Nathan Chancellor,
	Nicolas Schier, Tom Rix, linux-kernel, llvm, Douglas Anderson

On Wed, Aug 23, 2023 at 4:02 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Wed, Aug 23, 2023 at 3:00 AM Fangrui Song <maskray@google.com> wrote:
> >
> > On Tue, Aug 22, 2023 at 10:49 AM Denis Nikitin <denik@chromium.org> wrote:
> > >
> > > .llvm.call-graph-profile section is added by clang when the kernel is
> > > built with profiles (e.g. -fprofile-sample-use= or -fprofile-use=).
> > >
> > > The section contains edge information derived from text sections,
> > > so .llvm.call-graph-profile itself doesn't need more analysis as
> > > the text sections have been analyzed.
> > >
> > > This change fixes the kernel build with clang and a sample profile
> > > which currently fails with:
> > >
> > > "FATAL: modpost: Please add code to calculate addend for this architecture"
>
>
> Curious.
>
> This message is only displayed for REL.
>
> (Please not it is located in section_rel() function)
>
>
> I think modern architectures use RELA instead of REL.
> Which architecture are we talking about?

Aarch64. There was also a report on x86-64 but the error message could be
different there.

>
>
> What does the output of this command look like?
>
> $ llvm-readelf -S vmlinux.o | grep  .llvm.call-graph-profile
>
>
> Is it REL?
>

  [119] .llvm.call-graph-profile LLVM_CALL_GRAPH_PROFILE 0000000000000000
1c74a458 0104c8 08   E  0   0  1
  [120] .rel.llvm.call-graph-profile REL 0000000000000000 1c75a920 041320 10
I 26090 119  8

Thanks,
Denis

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] modpost: Skip .llvm.call-graph-profile section check
  2023-08-23 23:12       ` Denis Nikitin
@ 2023-08-23 23:54         ` Fangrui Song
  2023-08-24 23:09           ` Masahiro Yamada
  2023-08-24  1:34         ` Masahiro Yamada
  1 sibling, 1 reply; 16+ messages in thread
From: Fangrui Song @ 2023-08-23 23:54 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Denis Nikitin, linux-kbuild, Nick Desaulniers, Nathan Chancellor,
	Nicolas Schier, Tom Rix, linux-kernel, llvm, Douglas Anderson

On Wed, Aug 23, 2023 at 4:13 PM Denis Nikitin <denik@chromium.org> wrote:
>
> On Wed, Aug 23, 2023 at 4:02 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > On Wed, Aug 23, 2023 at 3:00 AM Fangrui Song <maskray@google.com> wrote:
> > >
> > > On Tue, Aug 22, 2023 at 10:49 AM Denis Nikitin <denik@chromium.org> wrote:
> > > >
> > > > .llvm.call-graph-profile section is added by clang when the kernel is
> > > > built with profiles (e.g. -fprofile-sample-use= or -fprofile-use=).
> > > >
> > > > The section contains edge information derived from text sections,
> > > > so .llvm.call-graph-profile itself doesn't need more analysis as
> > > > the text sections have been analyzed.
> > > >
> > > > This change fixes the kernel build with clang and a sample profile
> > > > which currently fails with:
> > > >
> > > > "FATAL: modpost: Please add code to calculate addend for this architecture"
> >
> >
> > Curious.
> >
> > This message is only displayed for REL.
> >
> > (Please not it is located in section_rel() function)
> >
> >
> > I think modern architectures use RELA instead of REL.
> > Which architecture are we talking about?
>
> Aarch64. There was also a report on x86-64 but the error message could be
> different there.

Regarding REL:

The original format of .llvm.call-graph-profile
(SHT_LLVM_CALL_GRAPH_PROFILE=0x6fff4c02) used symbol indices without
relocations and could be corrupted by symbol table change.
https://github.com/llvm/llvm-project/commit/a224c5199b327ed0efcdcd87b6dbf950cf4d9ee1
(2021) changed the format to represent call edge information with
R_*_NONE and changed SHT_LLVM_CALL_GRAPH_PROFILE to 0x6fff4c09.

We don't use the addend field of R_*_NONE relocations, so I proposed
that we use REL for all targets.
My https://github.com/llvm/llvm-project/commit/ca3bdb57fa1ac98b711a735de048c12b5fdd8086
selected REL for .llvm.call-graph-profile

aaelf64 says:

> A binary file may use ``REL`` or ``RELA`` relocations or a mixture of the two (but multiple relocations of the same place must use only one type).

Other psABI documents may be more vague on how REL is used, but as
long as the tool that needs to process it (currently just lld and
readelf like tools) supports it, it's fine.
binutils seems to support REL for all ELF targets, even if its
objcopy/strip may unintentionally convert REL to RELA. lld can consume
RELA SHT_LLVM_CALL_GRAPH_PROFILE.

> >
> >
> > What does the output of this command look like?
> >
> > $ llvm-readelf -S vmlinux.o | grep  .llvm.call-graph-profile
> >
> >
> > Is it REL?
> >
>
>   [119] .llvm.call-graph-profile LLVM_CALL_GRAPH_PROFILE 0000000000000000
> 1c74a458 0104c8 08   E  0   0  1
>   [120] .rel.llvm.call-graph-profile REL 0000000000000000 1c75a920 041320 10
> I 26090 119  8
>
> Thanks,
> Denis



-- 
宋方睿

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] modpost: Skip .llvm.call-graph-profile section check
  2023-08-23 23:12       ` Denis Nikitin
  2023-08-23 23:54         ` Fangrui Song
@ 2023-08-24  1:34         ` Masahiro Yamada
  2023-08-24  6:13           ` Fangrui Song
  1 sibling, 1 reply; 16+ messages in thread
From: Masahiro Yamada @ 2023-08-24  1:34 UTC (permalink / raw)
  To: Denis Nikitin, Fangrui Song
  Cc: linux-kbuild, Nick Desaulniers, Nathan Chancellor,
	Nicolas Schier, Tom Rix, linux-kernel, llvm, Douglas Anderson

On Thu, Aug 24, 2023 at 8:30 AM Denis Nikitin <denik@chromium.org> wrote:
>
> On Wed, Aug 23, 2023 at 4:02 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > On Wed, Aug 23, 2023 at 3:00 AM Fangrui Song <maskray@google.com> wrote:
> > >
> > > On Tue, Aug 22, 2023 at 10:49 AM Denis Nikitin <denik@chromium.org> wrote:
> > > >
> > > > .llvm.call-graph-profile section is added by clang when the kernel is
> > > > built with profiles (e.g. -fprofile-sample-use= or -fprofile-use=).
> > > >
> > > > The section contains edge information derived from text sections,
> > > > so .llvm.call-graph-profile itself doesn't need more analysis as
> > > > the text sections have been analyzed.
> > > >
> > > > This change fixes the kernel build with clang and a sample profile
> > > > which currently fails with:
> > > >
> > > > "FATAL: modpost: Please add code to calculate addend for this architecture"
> >
> >
> > Curious.
> >
> > This message is only displayed for REL.
> >
> > (Please not it is located in section_rel() function)
> >
> >
> > I think modern architectures use RELA instead of REL.
> > Which architecture are we talking about?
>
> Aarch64. There was also a report on x86-64 but the error message could be
> different there.
>
> >
> >
> > What does the output of this command look like?
> >
> > $ llvm-readelf -S vmlinux.o | grep  .llvm.call-graph-profile
> >
> >
> > Is it REL?
> >
>
>   [119] .llvm.call-graph-profile LLVM_CALL_GRAPH_PROFILE 0000000000000000
> 1c74a458 0104c8 08   E  0   0  1
>   [120] .rel.llvm.call-graph-profile REL 0000000000000000 1c75a920 041320 10
> I 26090 119  8


Fangrui,

Aarch64 uses RELA for other sections, but REL for this one.

I'd like to confirm if this is an expectation, not a toolchain bug.



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] modpost: Skip .llvm.call-graph-profile section check
  2023-08-24  1:34         ` Masahiro Yamada
@ 2023-08-24  6:13           ` Fangrui Song
  0 siblings, 0 replies; 16+ messages in thread
From: Fangrui Song @ 2023-08-24  6:13 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Denis Nikitin, linux-kbuild, Nick Desaulniers, Nathan Chancellor,
	Nicolas Schier, Tom Rix, linux-kernel, llvm, Douglas Anderson

On Wed, Aug 23, 2023 at 6:34 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Thu, Aug 24, 2023 at 8:30 AM Denis Nikitin <denik@chromium.org> wrote:
> >
> > On Wed, Aug 23, 2023 at 4:02 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
> > >
> > > On Wed, Aug 23, 2023 at 3:00 AM Fangrui Song <maskray@google.com> wrote:
> > > >
> > > > On Tue, Aug 22, 2023 at 10:49 AM Denis Nikitin <denik@chromium.org> wrote:
> > > > >
> > > > > .llvm.call-graph-profile section is added by clang when the kernel is
> > > > > built with profiles (e.g. -fprofile-sample-use= or -fprofile-use=).
> > > > >
> > > > > The section contains edge information derived from text sections,
> > > > > so .llvm.call-graph-profile itself doesn't need more analysis as
> > > > > the text sections have been analyzed.
> > > > >
> > > > > This change fixes the kernel build with clang and a sample profile
> > > > > which currently fails with:
> > > > >
> > > > > "FATAL: modpost: Please add code to calculate addend for this architecture"
> > >
> > >
> > > Curious.
> > >
> > > This message is only displayed for REL.
> > >
> > > (Please not it is located in section_rel() function)
> > >
> > >
> > > I think modern architectures use RELA instead of REL.
> > > Which architecture are we talking about?
> >
> > Aarch64. There was also a report on x86-64 but the error message could be
> > different there.
> >
> > >
> > >
> > > What does the output of this command look like?
> > >
> > > $ llvm-readelf -S vmlinux.o | grep  .llvm.call-graph-profile
> > >
> > >
> > > Is it REL?
> > >
> >
> >   [119] .llvm.call-graph-profile LLVM_CALL_GRAPH_PROFILE 0000000000000000
> > 1c74a458 0104c8 08   E  0   0  1
> >   [120] .rel.llvm.call-graph-profile REL 0000000000000000 1c75a920 041320 10
> > I 26090 119  8
>
>
> Fangrui,
>
> Aarch64 uses RELA for other sections, but REL for this one.
>
> I'd like to confirm if this is an expectation, not a toolchain bug.

Hi Masahiro,

Yes, using REL is intentional. It makes the relocations of
.llvm.call-graph-profile smaller.
The format encodes the (from,to,count) information with

* the section content holds 'count'
* two R_*_NONE relocations hold 'from' and 'to'. The addend field is
unused, therefore REL is better.


-- 
宋方睿

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] modpost: Skip .llvm.call-graph-profile section check
  2023-08-23 23:54         ` Fangrui Song
@ 2023-08-24 23:09           ` Masahiro Yamada
  2023-08-25  6:42             ` Denis Nikitin
  0 siblings, 1 reply; 16+ messages in thread
From: Masahiro Yamada @ 2023-08-24 23:09 UTC (permalink / raw)
  To: Fangrui Song
  Cc: Denis Nikitin, linux-kbuild, Nick Desaulniers, Nathan Chancellor,
	Nicolas Schier, Tom Rix, linux-kernel, llvm, Douglas Anderson

On Fri, Aug 25, 2023 at 2:30 AM Fangrui Song <maskray@google.com> wrote:
>
> On Wed, Aug 23, 2023 at 4:13 PM Denis Nikitin <denik@chromium.org> wrote:
> >
> > On Wed, Aug 23, 2023 at 4:02 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
> > >
> > > On Wed, Aug 23, 2023 at 3:00 AM Fangrui Song <maskray@google.com> wrote:
> > > >
> > > > On Tue, Aug 22, 2023 at 10:49 AM Denis Nikitin <denik@chromium.org> wrote:
> > > > >
> > > > > .llvm.call-graph-profile section is added by clang when the kernel is
> > > > > built with profiles (e.g. -fprofile-sample-use= or -fprofile-use=).
> > > > >
> > > > > The section contains edge information derived from text sections,
> > > > > so .llvm.call-graph-profile itself doesn't need more analysis as
> > > > > the text sections have been analyzed.
> > > > >
> > > > > This change fixes the kernel build with clang and a sample profile
> > > > > which currently fails with:
> > > > >
> > > > > "FATAL: modpost: Please add code to calculate addend for this architecture"
> > >
> > >
> > > Curious.
> > >
> > > This message is only displayed for REL.
> > >
> > > (Please not it is located in section_rel() function)
> > >
> > >
> > > I think modern architectures use RELA instead of REL.
> > > Which architecture are we talking about?
> >
> > Aarch64. There was also a report on x86-64 but the error message could be
> > different there.
>
> Regarding REL:
>
> The original format of .llvm.call-graph-profile
> (SHT_LLVM_CALL_GRAPH_PROFILE=0x6fff4c02) used symbol indices without
> relocations and could be corrupted by symbol table change.
> https://github.com/llvm/llvm-project/commit/a224c5199b327ed0efcdcd87b6dbf950cf4d9ee1
> (2021) changed the format to represent call edge information with
> R_*_NONE and changed SHT_LLVM_CALL_GRAPH_PROFILE to 0x6fff4c09.
>
> We don't use the addend field of R_*_NONE relocations, so I proposed
> that we use REL for all targets.
> My https://github.com/llvm/llvm-project/commit/ca3bdb57fa1ac98b711a735de048c12b5fdd8086
> selected REL for .llvm.call-graph-profile
>
> aaelf64 says:
>
> > A binary file may use ``REL`` or ``RELA`` relocations or a mixture of the two (but multiple relocations of the same place must use only one type).
>
> Other psABI documents may be more vague on how REL is used, but as
> long as the tool that needs to process it (currently just lld and
> readelf like tools) supports it, it's fine.
> binutils seems to support REL for all ELF targets, even if its
> objcopy/strip may unintentionally convert REL to RELA. lld can consume
> RELA SHT_LLVM_CALL_GRAPH_PROFILE.
>
> > >
> > >
> > > What does the output of this command look like?
> > >
> > > $ llvm-readelf -S vmlinux.o | grep  .llvm.call-graph-profile
> > >
> > >
> > > Is it REL?
> > >
> >
> >   [119] .llvm.call-graph-profile LLVM_CALL_GRAPH_PROFILE 0000000000000000
> > 1c74a458 0104c8 08   E  0   0  1
> >   [120] .rel.llvm.call-graph-profile REL 0000000000000000 1c75a920 041320 10
> > I 26090 119  8
> >
> > Thanks,
> > Denis



Thanks, Fangrui.


I'd like the commit log to record the use of REL for
.llvm.call-graph-profile is intentional.


Denis, could you add some more comments?



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2] modpost: Skip .llvm.call-graph-profile section check
  2023-08-24 23:09           ` Masahiro Yamada
@ 2023-08-25  6:42             ` Denis Nikitin
  0 siblings, 0 replies; 16+ messages in thread
From: Denis Nikitin @ 2023-08-25  6:42 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Fangrui Song, linux-kbuild, Nick Desaulniers, Nathan Chancellor,
	Nicolas Schier, Tom Rix, linux-kernel, llvm, Douglas Anderson

>
> Thanks, Fangrui.
>
>
> I'd like the commit log to record the use of REL for
> .llvm.call-graph-profile is intentional.
>
>
> Denis, could you add some more comments?
>

Sure, I will send a new version.

Thanks,
Denis

>
>
> --
> Best Regards
> Masahiro Yamada

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v3] modpost: Skip .llvm.call-graph-profile section check
  2023-08-22  6:52 [PATCH] modpost: Skip .llvm.call-graph-profile section check Denis Nikitin
                   ` (2 preceding siblings ...)
  2023-08-22 17:48 ` [PATCH v2] " Denis Nikitin
@ 2023-08-25  7:27 ` Denis Nikitin
  2023-08-29 13:17   ` Masahiro Yamada
  3 siblings, 1 reply; 16+ messages in thread
From: Denis Nikitin @ 2023-08-25  7:27 UTC (permalink / raw)
  To: linux-kbuild
  Cc: denik, Fangrui Song, Douglas Anderson, Nick Desaulniers,
	Masahiro Yamada, Nathan Chancellor, Nicolas Schier, Tom Rix,
	linux-kernel, llvm

.llvm.call-graph-profile section is added by clang when the kernel is
built with profiles (e.g. -fprofile-sample-use= or -fprofile-use=).
Note that .llvm.call-graph-profile intentionally uses REL relocations
to decrease the object size, for more details see
https://reviews.llvm.org/D104080.

The section contains edge information derived from text sections,
so .llvm.call-graph-profile itself doesn't need more analysis as
the text sections have been analyzed.

This change fixes the kernel build with clang and a sample profile
which currently fails with:

"FATAL: modpost: Please add code to calculate addend for this architecture"

Signed-off-by: Denis Nikitin <denik@chromium.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Fangrui Song <maskray@google.com>
---
 scripts/mod/modpost.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index b29b29707f10..64bd13f7199c 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -761,6 +761,7 @@ static const char *const section_white_list[] =
 	".fmt_slot*",			/* EZchip */
 	".gnu.lto*",
 	".discard.*",
+	".llvm.call-graph-profile",	/* call graph */
 	NULL
 };
 
-- 
2.42.0.rc1.204.g551eb34607-goog


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v3] modpost: Skip .llvm.call-graph-profile section check
  2023-08-25  7:27 ` [PATCH v3] " Denis Nikitin
@ 2023-08-29 13:17   ` Masahiro Yamada
  0 siblings, 0 replies; 16+ messages in thread
From: Masahiro Yamada @ 2023-08-29 13:17 UTC (permalink / raw)
  To: Denis Nikitin
  Cc: linux-kbuild, Fangrui Song, Douglas Anderson, Nick Desaulniers,
	Nathan Chancellor, Nicolas Schier, Tom Rix, linux-kernel, llvm

On Mon, Aug 28, 2023 at 5:15 AM Denis Nikitin <denik@chromium.org> wrote:
>
> .llvm.call-graph-profile section is added by clang when the kernel is
> built with profiles (e.g. -fprofile-sample-use= or -fprofile-use=).
> Note that .llvm.call-graph-profile intentionally uses REL relocations
> to decrease the object size, for more details see
> https://reviews.llvm.org/D104080.
>
> The section contains edge information derived from text sections,
> so .llvm.call-graph-profile itself doesn't need more analysis as
> the text sections have been analyzed.
>
> This change fixes the kernel build with clang and a sample profile
> which currently fails with:
>
> "FATAL: modpost: Please add code to calculate addend for this architecture"
>
> Signed-off-by: Denis Nikitin <denik@chromium.org>
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> Reviewed-by: Fangrui Song <maskray@google.com>
> ---


Applied to linux-kbuild.
Thanks.


>  scripts/mod/modpost.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index b29b29707f10..64bd13f7199c 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -761,6 +761,7 @@ static const char *const section_white_list[] =
>         ".fmt_slot*",                   /* EZchip */
>         ".gnu.lto*",
>         ".discard.*",
> +       ".llvm.call-graph-profile",     /* call graph */
>         NULL
>  };
>
> --
> 2.42.0.rc1.204.g551eb34607-goog
>


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-08-29 13:18 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-22  6:52 [PATCH] modpost: Skip .llvm.call-graph-profile section check Denis Nikitin
2023-08-22  7:05 ` Fangrui Song
2023-08-22 17:17   ` Denis Nikitin
2023-08-22 15:47 ` Nick Desaulniers
2023-08-22 17:21   ` Denis Nikitin
2023-08-22 17:48 ` [PATCH v2] " Denis Nikitin
2023-08-22 17:51   ` Fangrui Song
2023-08-23 23:01     ` Masahiro Yamada
2023-08-23 23:12       ` Denis Nikitin
2023-08-23 23:54         ` Fangrui Song
2023-08-24 23:09           ` Masahiro Yamada
2023-08-25  6:42             ` Denis Nikitin
2023-08-24  1:34         ` Masahiro Yamada
2023-08-24  6:13           ` Fangrui Song
2023-08-25  7:27 ` [PATCH v3] " Denis Nikitin
2023-08-29 13:17   ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).