diff mbox series

bpftool: Allow building statically

Message ID 20220217120435.2245447-1-nborisov@suse.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series bpftool: Allow building statically | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next fail VM_Test
netdev/tree_selection success Not a local patch

Commit Message

Nikolay Borisov Feb. 17, 2022, 12:04 p.m. UTC
Sometime it can be useful to haul around a statically built version of
bpftool. Simply add support for passing STATIC=1 while building to build
the tool statically.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---

Currently the bpftool being distributed as part of libbpf-tools under bcc project
is dynamically built on a system using GLIBC 2.28, this makes the tool unusable on
ubuntu 18.04 for example. Perhaps after this patch has landed the bpftool in bcc
can be turned into a static binary.

 tools/bpf/bpftool/Makefile | 4 ++++
 1 file changed, 4 insertions(+)

--
2.25.1

Comments

Quentin Monnet Feb. 18, 2022, 4:08 p.m. UTC | #1
2022-02-17 14:04 UTC+0200 ~ Nikolay Borisov <nborisov@suse.com>
> Sometime it can be useful to haul around a statically built version of
> bpftool. Simply add support for passing STATIC=1 while building to build
> the tool statically.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
> 
> Currently the bpftool being distributed as part of libbpf-tools under bcc project
> is dynamically built on a system using GLIBC 2.28, this makes the tool unusable on
> ubuntu 18.04 for example. Perhaps after this patch has landed the bpftool in bcc
> can be turned into a static binary.
> 
>  tools/bpf/bpftool/Makefile | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> index 83369f55df61..835621e215e4 100644
> --- a/tools/bpf/bpftool/Makefile
> +++ b/tools/bpf/bpftool/Makefile
> @@ -13,6 +13,10 @@ else
>    Q = @
>  endif
> 
> +ifeq ($(STATIC),1)
> +	CFLAGS += --static
> +endif
> +
>  BPF_DIR = $(srctree)/tools/lib/bpf
> 
>  ifneq ($(OUTPUT),)
> --
> 2.25.1
> 

Why not just pass the flag on the command line? I don't think the
Makefile overwrites it:

    $ CFLAGS=--static make

Quentin
Nikolay Borisov Feb. 18, 2022, 4:14 p.m. UTC | #2
On 18.02.22 г. 18:08 ч., Quentin Monnet wrote:
> 2022-02-17 14:04 UTC+0200 ~ Nikolay Borisov <nborisov@suse.com>
>> Sometime it can be useful to haul around a statically built version of
>> bpftool. Simply add support for passing STATIC=1 while building to build
>> the tool statically.
>>
>> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
>> ---
>>
>> Currently the bpftool being distributed as part of libbpf-tools under bcc project
>> is dynamically built on a system using GLIBC 2.28, this makes the tool unusable on
>> ubuntu 18.04 for example. Perhaps after this patch has landed the bpftool in bcc
>> can be turned into a static binary.
>>
>>   tools/bpf/bpftool/Makefile | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
>> index 83369f55df61..835621e215e4 100644
>> --- a/tools/bpf/bpftool/Makefile
>> +++ b/tools/bpf/bpftool/Makefile
>> @@ -13,6 +13,10 @@ else
>>     Q = @
>>   endif
>>
>> +ifeq ($(STATIC),1)
>> +	CFLAGS += --static
>> +endif
>> +
>>   BPF_DIR = $(srctree)/tools/lib/bpf
>>
>>   ifneq ($(OUTPUT),)
>> --
>> 2.25.1
>>
> 
> Why not just pass the flag on the command line? I don't think the
> Makefile overwrites it:
> 
>      $ CFLAGS=--static make

Yeah, this also works, I initially thought that overriding a variable on 
the command line would require having the override directive in the 
makefile but apparently is not the case. I guess this patch can be 
scratched.

> 
> Quentin
>
Quentin Monnet Feb. 18, 2022, 4:33 p.m. UTC | #3
2022-02-18 18:14 UTC+0200 ~ Nikolay Borisov <nborisov@suse.com>
> 
> 
> On 18.02.22 г. 18:08 ч., Quentin Monnet wrote:
>> 2022-02-17 14:04 UTC+0200 ~ Nikolay Borisov <nborisov@suse.com>
>>> Sometime it can be useful to haul around a statically built version of
>>> bpftool. Simply add support for passing STATIC=1 while building to build
>>> the tool statically.
>>>
>>> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
>>> ---
>>>
>>> Currently the bpftool being distributed as part of libbpf-tools under
>>> bcc project
>>> is dynamically built on a system using GLIBC 2.28, this makes the
>>> tool unusable on
>>> ubuntu 18.04 for example. Perhaps after this patch has landed the
>>> bpftool in bcc
>>> can be turned into a static binary.
>>>
>>>   tools/bpf/bpftool/Makefile | 4 ++++
>>>   1 file changed, 4 insertions(+)
>>>
>>> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
>>> index 83369f55df61..835621e215e4 100644
>>> --- a/tools/bpf/bpftool/Makefile
>>> +++ b/tools/bpf/bpftool/Makefile
>>> @@ -13,6 +13,10 @@ else
>>>     Q = @
>>>   endif
>>>
>>> +ifeq ($(STATIC),1)
>>> +    CFLAGS += --static
>>> +endif
>>> +
>>>   BPF_DIR = $(srctree)/tools/lib/bpf
>>>
>>>   ifneq ($(OUTPUT),)
>>> -- 
>>> 2.25.1
>>>
>>
>> Why not just pass the flag on the command line? I don't think the
>> Makefile overwrites it:
>>
>>      $ CFLAGS=--static make
> 
> Yeah, this also works, I initially thought that overriding a variable on
> the command line would require having the override directive in the
> makefile but apparently is not the case. I guess this patch can be
> scratched.

You'd need something if the Makefile was initialising the variable, with
something like "CFLAGS = -O2" or "CFLAGS := -O2". But bpftool's Makefile
always uses "CFLAGS += ...", meaning it appends to the current value, so
you can pass whatever you want from the command line, as long as it
doesn't get overwritten by another flag (for example, passing "-O0"
would not work I think, since we add "-O2" in the Makefile).
Daniel Borkmann Feb. 18, 2022, 7:58 p.m. UTC | #4
On 2/18/22 5:33 PM, Quentin Monnet wrote:
> 2022-02-18 18:14 UTC+0200 ~ Nikolay Borisov <nborisov@suse.com>
>> On 18.02.22 г. 18:08 ч., Quentin Monnet wrote:
>>> 2022-02-17 14:04 UTC+0200 ~ Nikolay Borisov <nborisov@suse.com>
>>>> Sometime it can be useful to haul around a statically built version of
>>>> bpftool. Simply add support for passing STATIC=1 while building to build
>>>> the tool statically.
>>>>
>>>> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
>>>> ---
>>>>
>>>> Currently the bpftool being distributed as part of libbpf-tools under
>>>> bcc project
>>>> is dynamically built on a system using GLIBC 2.28, this makes the
>>>> tool unusable on
>>>> ubuntu 18.04 for example. Perhaps after this patch has landed the
>>>> bpftool in bcc
>>>> can be turned into a static binary.
>>>>
>>>>    tools/bpf/bpftool/Makefile | 4 ++++
>>>>    1 file changed, 4 insertions(+)
>>>>
>>>> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
>>>> index 83369f55df61..835621e215e4 100644
>>>> --- a/tools/bpf/bpftool/Makefile
>>>> +++ b/tools/bpf/bpftool/Makefile
>>>> @@ -13,6 +13,10 @@ else
>>>>      Q = @
>>>>    endif
>>>>
>>>> +ifeq ($(STATIC),1)
>>>> +    CFLAGS += --static
>>>> +endif
>>>> +
>>>>    BPF_DIR = $(srctree)/tools/lib/bpf
>>>>
>>>>    ifneq ($(OUTPUT),)
>>>
>>> Why not just pass the flag on the command line? I don't think the
>>> Makefile overwrites it:
>>>
>>>       $ CFLAGS=--static make
>>
>> Yeah, this also works, I initially thought that overriding a variable on
>> the command line would require having the override directive in the
>> makefile but apparently is not the case. I guess this patch can be
>> scratched.
> 
> You'd need something if the Makefile was initialising the variable, with
> something like "CFLAGS = -O2" or "CFLAGS := -O2". But bpftool's Makefile
> always uses "CFLAGS += ...", meaning it appends to the current value, so
> you can pass whatever you want from the command line, as long as it
> doesn't get overwritten by another flag (for example, passing "-O0"
> would not work I think, since we add "-O2" in the Makefile).

We don't have an in-tree readme, but the `CFLAGS=--static make` use case
could probably be documented in [0] at minimum.

Cheers,
Daniel

   [0] https://github.com/libbpf/bpftool
Quentin Monnet Feb. 18, 2022, 8 p.m. UTC | #5
2022-02-18 20:58 UTC+0100 ~ Daniel Borkmann <daniel@iogearbox.net>
> On 2/18/22 5:33 PM, Quentin Monnet wrote:
>> 2022-02-18 18:14 UTC+0200 ~ Nikolay Borisov <nborisov@suse.com>
>>> On 18.02.22 г. 18:08 ч., Quentin Monnet wrote:
>>>> 2022-02-17 14:04 UTC+0200 ~ Nikolay Borisov <nborisov@suse.com>
>>>>> Sometime it can be useful to haul around a statically built version of
>>>>> bpftool. Simply add support for passing STATIC=1 while building to
>>>>> build
>>>>> the tool statically.
>>>>>
>>>>> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
>>>>> ---
>>>>>
>>>>> Currently the bpftool being distributed as part of libbpf-tools under
>>>>> bcc project
>>>>> is dynamically built on a system using GLIBC 2.28, this makes the
>>>>> tool unusable on
>>>>> ubuntu 18.04 for example. Perhaps after this patch has landed the
>>>>> bpftool in bcc
>>>>> can be turned into a static binary.
>>>>>
>>>>>    tools/bpf/bpftool/Makefile | 4 ++++
>>>>>    1 file changed, 4 insertions(+)
>>>>>
>>>>> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
>>>>> index 83369f55df61..835621e215e4 100644
>>>>> --- a/tools/bpf/bpftool/Makefile
>>>>> +++ b/tools/bpf/bpftool/Makefile
>>>>> @@ -13,6 +13,10 @@ else
>>>>>      Q = @
>>>>>    endif
>>>>>
>>>>> +ifeq ($(STATIC),1)
>>>>> +    CFLAGS += --static
>>>>> +endif
>>>>> +
>>>>>    BPF_DIR = $(srctree)/tools/lib/bpf
>>>>>
>>>>>    ifneq ($(OUTPUT),)
>>>>
>>>> Why not just pass the flag on the command line? I don't think the
>>>> Makefile overwrites it:
>>>>
>>>>       $ CFLAGS=--static make
>>>
>>> Yeah, this also works, I initially thought that overriding a variable on
>>> the command line would require having the override directive in the
>>> makefile but apparently is not the case. I guess this patch can be
>>> scratched.
>>
>> You'd need something if the Makefile was initialising the variable, with
>> something like "CFLAGS = -O2" or "CFLAGS := -O2". But bpftool's Makefile
>> always uses "CFLAGS += ...", meaning it appends to the current value, so
>> you can pass whatever you want from the command line, as long as it
>> doesn't get overwritten by another flag (for example, passing "-O0"
>> would not work I think, since we add "-O2" in the Makefile).
> 
> We don't have an in-tree readme, but the `CFLAGS=--static make` use case
> could probably be documented in [0] at minimum.
> 
> Cheers,
> Daniel
> 
>   [0] https://github.com/libbpf/bpftool

Makes sense, I'll do this. Thanks Daniel!
Quentin
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index 83369f55df61..835621e215e4 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -13,6 +13,10 @@  else
   Q = @
 endif

+ifeq ($(STATIC),1)
+	CFLAGS += --static
+endif
+
 BPF_DIR = $(srctree)/tools/lib/bpf

 ifneq ($(OUTPUT),)