All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: add documentation to compare clang "-target bpf" and default target
@ 2018-02-02  7:00 Yonghong Song
  2018-02-02 10:25 ` Daniel Borkmann
  0 siblings, 1 reply; 2+ messages in thread
From: Yonghong Song @ 2018-02-02  7:00 UTC (permalink / raw)
  To: ast, daniel, netdev; +Cc: kernel-team

The added documentation explains how generated codes may differ
between clang bpf target and default target, and when to use
each target.

Signed-off-by: Yonghong Song <yhs@fb.com>
---
 Documentation/bpf/bpf_devel_QA.txt | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/Documentation/bpf/bpf_devel_QA.txt b/Documentation/bpf/bpf_devel_QA.txt
index cefef85..3a3e77c 100644
--- a/Documentation/bpf/bpf_devel_QA.txt
+++ b/Documentation/bpf/bpf_devel_QA.txt
@@ -516,4 +516,34 @@ A: LLVM has a -mcpu selector for the BPF back end in order to allow the
    By the way, the BPF kernel selftests run with -mcpu=probe for better
    test coverage.
 
+Q: In some cases clang flag "-target bpf" is used but in other cases the
+   default clang target, which matches the underlying architecture, is used.
+   What is the difference and when I should use which?
+
+   Although LLVM IR generation and optimization try to stay architecture
+   independent, "-target <arch>" still has some impact on generated code:
+
+     - BPF program may recursively include header file(s) with file scope
+       inline assembly codes. Default target can handle this well,
+       while bpf target may fail if bpf backend assembler does not
+       understand these assembly codes, which is true in most cases.
+
+     - When compiled without -g, additional elf sections, e.g.,
+       .eh_frame and .rela.eh_frame, may be present in the object file
+       with default target, but not with bpf target.
+
+     - The default target may turn a C switch statement into a switch table
+       lookup and jump operation. Since the switch table is placed
+       in the global readonly section, the bpf program will fail to load.
+       The bpf target does not support switch table optimization.
+       The clang option "-fno-jump-tables" can be used to disable
+       switch table generation.
+
+   You should use default target when:
+     - Your program includes a header file, e.g., ptrace.h, which eventually
+       pulls in some header files containing file scope host assembly codes.
+     - You can add "-fno-jump-tables" to work around the switch table issue.
+
+   Otherwise, you can use bpf target.
+
 Happy BPF hacking!
-- 
2.9.5

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

* Re: [PATCH bpf-next] bpf: add documentation to compare clang "-target bpf" and default target
  2018-02-02  7:00 [PATCH bpf-next] bpf: add documentation to compare clang "-target bpf" and default target Yonghong Song
@ 2018-02-02 10:25 ` Daniel Borkmann
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Borkmann @ 2018-02-02 10:25 UTC (permalink / raw)
  To: Yonghong Song, ast, netdev; +Cc: kernel-team

On 02/02/2018 08:00 AM, Yonghong Song wrote:
> The added documentation explains how generated codes may differ
> between clang bpf target and default target, and when to use
> each target.
> 
> Signed-off-by: Yonghong Song <yhs@fb.com>

Since it's a small doc-only addition and one that really helps clarifying
the recently seen issues with libbpf, I've applied this to bpf, thanks for
adding this, Yonghong!

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

end of thread, other threads:[~2018-02-02 10:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-02  7:00 [PATCH bpf-next] bpf: add documentation to compare clang "-target bpf" and default target Yonghong Song
2018-02-02 10:25 ` Daniel Borkmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.