mbox series

[bpf-next,0/8] samples: bpf: improve/fix cross-compilation

Message ID 20190904212212.13052-1-ivan.khoronzhuk@linaro.org
Headers show
Series samples: bpf: improve/fix cross-compilation | expand

Message

Ivan Khoronzhuk Sept. 4, 2019, 9:22 p.m. UTC
This series contains mainly fixes/improvements for cross-compilation
(also verified on native platform build), tested on arm, but intended
for any arch.

Initial RFC link:
https://lkml.org/lkml/2019/8/29/1665

Besides the pathces given here, the RFC also contains couple patches
related to llvm clang
  arm: include: asm: swab: mask rev16 instruction for clang
  arm: include: asm: unified: mask .syntax unified for clang

The change touches not only cross-compilation and can have impact on
other archs and build environments, so might be good idea to verify
it in order to add appropriate changes, some warn options could be
tuned also.

Ivan Khoronzhuk (8):
  samples: bpf: Makefile: use --target from cross-compile
  samples: bpf: Makefile: remove target for native build
  libbpf: Makefile: add C/CXX/LDFLAGS to libbpf.so and test_libpf
    targets
  samples: bpf: use own EXTRA_CFLAGS for clang commands
  samples: bpf: Makefile: use vars from KBUILD_CFLAGS to handle linux
    headers
  samples: bpf: makefile: fix HDR_PROBE "echo"
  samples: bpf: add makefile.prog for separate CC build
  samples: bpf: Makefile: base progs build on Makefile.progs

 samples/bpf/Makefile      | 177 ++++++++++++++++++++++----------------
 samples/bpf/Makefile.prog |  77 +++++++++++++++++
 samples/bpf/README.rst    |   7 ++
 tools/lib/bpf/Makefile    |  11 ++-
 4 files changed, 197 insertions(+), 75 deletions(-)
 create mode 100644 samples/bpf/Makefile.prog

-- 
2.17.1

Comments

Alexei Starovoitov Sept. 6, 2019, 11:31 p.m. UTC | #1
On Thu, Sep 05, 2019 at 12:22:06AM +0300, Ivan Khoronzhuk wrote:
> No need to set --target for native build, at least for arm, the

> default target will be used anyway. In case of arm, for at least

> clang 5 - 10 it causes error like:

> 

> clang: warning: unknown platform, assuming -mfloat-abi=soft

> LLVM ERROR: Unsupported calling convention

> make[2]: *** [/home/root/snapshot/samples/bpf/Makefile:299:

> /home/root/snapshot/samples/bpf/sockex1_kern.o] Error 1

> 

> Only set to real triple helps: --target=arm-linux-gnueabihf

> or just drop the target key to use default one. Decision to just

> drop it and thus default target will be used (wich is native),

> looks better.

> 

> Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>

> ---

>  samples/bpf/Makefile | 2 --

>  1 file changed, 2 deletions(-)

> 

> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile

> index 61b7394b811e..a2953357927e 100644

> --- a/samples/bpf/Makefile

> +++ b/samples/bpf/Makefile

> @@ -197,8 +197,6 @@ BTF_PAHOLE ?= pahole

>  ifdef CROSS_COMPILE

>  HOSTCC = $(CROSS_COMPILE)gcc

>  CLANG_ARCH_ARGS = --target=$(notdir $(CROSS_COMPILE:%-=%))

> -else

> -CLANG_ARCH_ARGS = -target $(ARCH)

>  endif


I don't follow here.
Didn't you introduce this bug in patch 1 and now fixing it in patch 2?
Ivan Khoronzhuk Sept. 6, 2019, 11:52 p.m. UTC | #2
On Fri, Sep 06, 2019 at 04:31:39PM -0700, Alexei Starovoitov wrote:
>On Thu, Sep 05, 2019 at 12:22:06AM +0300, Ivan Khoronzhuk wrote:

>> No need to set --target for native build, at least for arm, the

>> default target will be used anyway. In case of arm, for at least

>> clang 5 - 10 it causes error like:

>>

>> clang: warning: unknown platform, assuming -mfloat-abi=soft

>> LLVM ERROR: Unsupported calling convention

>> make[2]: *** [/home/root/snapshot/samples/bpf/Makefile:299:

>> /home/root/snapshot/samples/bpf/sockex1_kern.o] Error 1

>>

>> Only set to real triple helps: --target=arm-linux-gnueabihf

>> or just drop the target key to use default one. Decision to just

>> drop it and thus default target will be used (wich is native),

>> looks better.

>>

>> Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>

>> ---

>>  samples/bpf/Makefile | 2 --

>>  1 file changed, 2 deletions(-)

>>

>> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile

>> index 61b7394b811e..a2953357927e 100644

>> --- a/samples/bpf/Makefile

>> +++ b/samples/bpf/Makefile

>> @@ -197,8 +197,6 @@ BTF_PAHOLE ?= pahole

>>  ifdef CROSS_COMPILE

>>  HOSTCC = $(CROSS_COMPILE)gcc

>>  CLANG_ARCH_ARGS = --target=$(notdir $(CROSS_COMPILE:%-=%))

>> -else

>> -CLANG_ARCH_ARGS = -target $(ARCH)

>>  endif

>

>I don't follow here.

>Didn't you introduce this bug in patch 1 and now fixing it in patch 2?

>


It looks like but that's not true.
Previous patch adds target only for cross compiling,
before the patch the target was used for both, cross compiling and w/o cc.

This patch removes target only for native build (it's not cross compiling).

By fact, it's two separate significant changes.

-- 
Regards,
Ivan Khoronzhuk
Ivan Khoronzhuk Sept. 7, 2019, 12:19 a.m. UTC | #3
On Fri, Sep 06, 2019 at 05:04:08PM -0700, Alexei Starovoitov wrote:
>On Fri, Sep 6, 2019 at 4:52 PM Ivan Khoronzhuk

><ivan.khoronzhuk@linaro.org> wrote:

>>

>> On Fri, Sep 06, 2019 at 04:31:39PM -0700, Alexei Starovoitov wrote:

>> >On Thu, Sep 05, 2019 at 12:22:06AM +0300, Ivan Khoronzhuk wrote:

>> >> No need to set --target for native build, at least for arm, the

>> >> default target will be used anyway. In case of arm, for at least

>> >> clang 5 - 10 it causes error like:

>> >>

>> >> clang: warning: unknown platform, assuming -mfloat-abi=soft

>> >> LLVM ERROR: Unsupported calling convention

>> >> make[2]: *** [/home/root/snapshot/samples/bpf/Makefile:299:

>> >> /home/root/snapshot/samples/bpf/sockex1_kern.o] Error 1

>> >>

>> >> Only set to real triple helps: --target=arm-linux-gnueabihf

>> >> or just drop the target key to use default one. Decision to just

>> >> drop it and thus default target will be used (wich is native),

>> >> looks better.

>> >>

>> >> Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>

>> >> ---

>> >>  samples/bpf/Makefile | 2 --

>> >>  1 file changed, 2 deletions(-)

>> >>

>> >> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile

>> >> index 61b7394b811e..a2953357927e 100644

>> >> --- a/samples/bpf/Makefile

>> >> +++ b/samples/bpf/Makefile

>> >> @@ -197,8 +197,6 @@ BTF_PAHOLE ?= pahole

>> >>  ifdef CROSS_COMPILE

>> >>  HOSTCC = $(CROSS_COMPILE)gcc

>> >>  CLANG_ARCH_ARGS = --target=$(notdir $(CROSS_COMPILE:%-=%))

>> >> -else

>> >> -CLANG_ARCH_ARGS = -target $(ARCH)

>> >>  endif

>> >

>> >I don't follow here.

>> >Didn't you introduce this bug in patch 1 and now fixing it in patch 2?

>> >

>>

>> It looks like but that's not true.

>> Previous patch adds target only for cross compiling,

>> before the patch the target was used for both, cross compiling and w/o cc.

>>

>> This patch removes target only for native build (it's not cross compiling).

>>

>> By fact, it's two separate significant changes.

>

>How so?

>before first patch CLANG_ARCH_ARGS is only used under CROSS_COMPILE.

>After the first patch CLANG_ARCH_ARGS is now suddenly defined w/o CROSS_COMPILE

>and second patch brings it to the state before first patch.


Oh sorry ), messed with my local exp with target bpf, after rebase, even forgot
that's mine. Will drop it, with removing "else" for previous patch.

-- 
Regards,
Ivan Khoronzhuk