Topics

bpftool binary size

Jesper Dangaard Brouer
 

(Cc. iovisor-dev list)

On Wed, 18 Apr 2018 21:32:45 +0200
Jesper Dangaard Brouer <brouer@...> wrote:
On Wed, 18 Apr 2018 20:13:39 +0100
Quentin Monnet <quentin.monnet@...> wrote:

Hi Jesper,

Out of curiosity, how much did you say your bpftool executable weigh? Was
it 2 MB? I recompiled it on my laptop and it's 173 kB, 113 kB if stripped.
I don't believe it embeds libopcode on my system (right now Ubuntu 18.04).
What is your setup, if you don't mind me asking?
On my Fedora 26, it is 2.2MB (2207976) and stripped 2MB (2046784).

For some reason the bpftool binary gets statically linked with
libopcodes, which is /usr/lib64/libopcodes.a 1.76MB.
So, I figured out why this happens.

What does bpftool use BFD for?

I need the BFD lib and include file: /usr/include/bfd.h.
Thus, on fedora I need to install package binutils-devel.

The file /usr/lib64/libopcodes.so contains a ld-script that enforce
static linking:

$ cat /usr/lib64/libopcodes.so
/* GNU ld script */

/* Ensure this .so library will not be used by a link for a different format
on a multi-architecture system. */
OUTPUT_FORMAT(elf64-x86-64)

INPUT ( /usr/lib64/libopcodes.a -lbfd )



The info/description on the RPM file is interesting, it explicitly
explain why this static linking is enforced... and "strongly
encouraged" developers to use libelf instead of BFD.

Is using libelf instead an option?


$ rpm -qi binutils-devel
Name : binutils-devel
Version : 2.27
Release : 28.fc26
Architecture: x86_64
Install Date: Wed 18 Apr 2018 09:34:52 PM CEST
Group : System Environment/Libraries
Size : 4651893
License : GPLv3+
Signature : RSA/SHA256, Thu 02 Nov 2017 10:37:53 AM CET, Key ID 812a6b4b64dab85d
Source RPM : binutils-2.27-28.fc26.src.rpm
Build Date : Fri 13 Oct 2017 03:48:11 PM CEST
Build Host : buildvm-16.phx2.fedoraproject.org
Relocations : (not relocatable)
Packager : Fedora Project
Vendor : Fedora Project
URL : http://sources.redhat.com/binutils
Summary : BFD and opcodes static and dynamic libraries and header files
Description :
This package contains BFD and opcodes static and dynamic libraries.

The dynamic libraries are in this package, rather than a seperate
base package because they are actually linker scripts that force
the use of the static libraries. This is because the API of the
BFD library is too unstable to be used dynamically.

The static libraries are here because they are now needed by the
dynamic libraries.

Developers starting new projects are strongly encouraged to consider
using libelf instead of BFD.


--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer

Daniel Borkmann
 

On 04/18/2018 10:03 PM, Jesper Dangaard Brouer via iovisor-dev wrote:[...]
What does bpftool use BFD for?
It's used for the prog JIT dump in order to disassemble the instructions.