bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Fix alignment of .BTF_ids
@ 2020-09-30  9:36 Jean-Philippe Brucker
  2020-09-30 11:52 ` Jiri Olsa
  2020-10-01  1:30 ` patchwork-bot+bpf
  0 siblings, 2 replies; 3+ messages in thread
From: Jean-Philippe Brucker @ 2020-09-30  9:36 UTC (permalink / raw)
  To: ast, daniel
  Cc: shuah, kafai, songliubraving, yhs, andriin, john.fastabend,
	kpsingh, jolsa, bpf, Jean-Philippe Brucker

Fix a build failure on arm64, due to missing alignment information for
the .BTF_ids section:

resolve_btfids.test.o: in function `test_resolve_btfids':
tools/testing/selftests/bpf/prog_tests/resolve_btfids.c:140:(.text+0x29c): relocation truncated to fit: R_AARCH64_LDST32_ABS_LO12_NC against `.BTF_ids'
ld: tools/testing/selftests/bpf/prog_tests/resolve_btfids.c:140: warning: one possible cause of this error is that the symbol is being referenced in the indicated code as if it had a larger alignment than was declared where it was defined

In vmlinux, the .BTF_ids section is aligned to 4 bytes by vmlinux.lds.h.
In test_progs however, .BTF_ids doesn't have alignment constraints. The
arm64 linker expects the btf_id_set.cnt symbol, a u32, to be naturally
aligned but finds it misaligned and cannot apply the relocation. Enforce
alignment of .BTF_ids to 4 bytes.

Fixes: cd04b04de119 ("selftests/bpf: Add set test to resolve_btfids")
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
 tools/testing/selftests/bpf/prog_tests/resolve_btfids.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c
index 8826c652adad..6ace5e9efec1 100644
--- a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c
+++ b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c
@@ -28,6 +28,12 @@ struct symbol test_symbols[] = {
 	{ "func",    BTF_KIND_FUNC,    -1 },
 };
 
+/* Align the .BTF_ids section to 4 bytes */
+asm (
+".pushsection " BTF_IDS_SECTION " ,\"a\"; \n"
+".balign 4, 0;                            \n"
+".popsection;                             \n");
+
 BTF_ID_LIST(test_list_local)
 BTF_ID_UNUSED
 BTF_ID(typedef, S)
-- 
2.28.0


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

* Re: [PATCH bpf-next] selftests/bpf: Fix alignment of .BTF_ids
  2020-09-30  9:36 [PATCH bpf-next] selftests/bpf: Fix alignment of .BTF_ids Jean-Philippe Brucker
@ 2020-09-30 11:52 ` Jiri Olsa
  2020-10-01  1:30 ` patchwork-bot+bpf
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Olsa @ 2020-09-30 11:52 UTC (permalink / raw)
  To: Jean-Philippe Brucker
  Cc: ast, daniel, shuah, kafai, songliubraving, yhs, andriin,
	john.fastabend, kpsingh, jolsa, bpf

On Wed, Sep 30, 2020 at 11:36:01AM +0200, Jean-Philippe Brucker wrote:
> Fix a build failure on arm64, due to missing alignment information for
> the .BTF_ids section:
> 
> resolve_btfids.test.o: in function `test_resolve_btfids':
> tools/testing/selftests/bpf/prog_tests/resolve_btfids.c:140:(.text+0x29c): relocation truncated to fit: R_AARCH64_LDST32_ABS_LO12_NC against `.BTF_ids'
> ld: tools/testing/selftests/bpf/prog_tests/resolve_btfids.c:140: warning: one possible cause of this error is that the symbol is being referenced in the indicated code as if it had a larger alignment than was declared where it was defined
> 
> In vmlinux, the .BTF_ids section is aligned to 4 bytes by vmlinux.lds.h.
> In test_progs however, .BTF_ids doesn't have alignment constraints. The
> arm64 linker expects the btf_id_set.cnt symbol, a u32, to be naturally
> aligned but finds it misaligned and cannot apply the relocation. Enforce
> alignment of .BTF_ids to 4 bytes.
> 
> Fixes: cd04b04de119 ("selftests/bpf: Add set test to resolve_btfids")
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> ---
>  tools/testing/selftests/bpf/prog_tests/resolve_btfids.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c
> index 8826c652adad..6ace5e9efec1 100644
> --- a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c
> +++ b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c
> @@ -28,6 +28,12 @@ struct symbol test_symbols[] = {
>  	{ "func",    BTF_KIND_FUNC,    -1 },
>  };
>  
> +/* Align the .BTF_ids section to 4 bytes */
> +asm (
> +".pushsection " BTF_IDS_SECTION " ,\"a\"; \n"
> +".balign 4, 0;                            \n"
> +".popsection;                             \n");
> +

Acked-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

>  BTF_ID_LIST(test_list_local)
>  BTF_ID_UNUSED
>  BTF_ID(typedef, S)
> -- 
> 2.28.0
> 


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

* Re: [PATCH bpf-next] selftests/bpf: Fix alignment of .BTF_ids
  2020-09-30  9:36 [PATCH bpf-next] selftests/bpf: Fix alignment of .BTF_ids Jean-Philippe Brucker
  2020-09-30 11:52 ` Jiri Olsa
@ 2020-10-01  1:30 ` patchwork-bot+bpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bpf @ 2020-10-01  1:30 UTC (permalink / raw)
  To: Jean-Philippe Brucker; +Cc: bpf

Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

On Wed, 30 Sep 2020 11:36:01 +0200 you wrote:
> Fix a build failure on arm64, due to missing alignment information for
> the .BTF_ids section:
> 
> resolve_btfids.test.o: in function `test_resolve_btfids':
> tools/testing/selftests/bpf/prog_tests/resolve_btfids.c:140:(.text+0x29c): relocation truncated to fit: R_AARCH64_LDST32_ABS_LO12_NC against `.BTF_ids'
> ld: tools/testing/selftests/bpf/prog_tests/resolve_btfids.c:140: warning: one possible cause of this error is that the symbol is being referenced in the indicated code as if it had a larger alignment than was declared where it was defined
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: Fix alignment of .BTF_ids
    https://git.kernel.org/bpf/bpf-next/c/3effc06a4dde

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2020-10-01  1:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30  9:36 [PATCH bpf-next] selftests/bpf: Fix alignment of .BTF_ids Jean-Philippe Brucker
2020-09-30 11:52 ` Jiri Olsa
2020-10-01  1:30 ` patchwork-bot+bpf

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).