Skip to content

Problem about LIBBPF_SYS_LIBRARY_PATH and build.rs #106

Open
@kxxt

Description

@kxxt

When cross-compiling an application that uses libbpf-sys in build.rs(Usually via libbpf-cargo).

If LIBBPF_SYS_LIBRARY_PATH is set to a path that contains the libelf for the target architecture(let's say, aarch64),

then while building the build.rs of this application, we are actually required to build libbpf-sys for the build architecture(x86_64) because the build.rs script needs to link libbpf-sys. But in the build.rs of libbpf-sys, we can only know that we are building for aarch64 target and we are linking aarch64 libelf from LIBBPF_SYS_LIBRARY_PATH into x86_64 libbpf-sys rlib.

static:

 = note: rust-lld: error: /home/kxxt/repos/tracexec/target/debug/deps/liblibbpf_sys-abc8218b23be072d.rlib(elf_version.o) is incompatible with elf64-x86-64
          rust-lld: error: /home/kxxt/repos/tracexec/target/debug/deps/liblibbpf_sys-abc8218b23be072d.rlib(elf_hash.o) is incompatible with elf64-x86-64
          rust-lld: error: /home/kxxt/repos/tracexec/target/debug/deps/liblibbpf_sys-abc8218b23be072d.rlib(elf_error.o) is incompatible with elf64-x86-64
          rust-lld: error: /home/kxxt/repos/tracexec/target/debug/deps/liblibbpf_sys-abc8218b23be072d.rlib(elf_fill.o) is incompatible with elf64-x86-64
          rust-lld: error: /home/kxxt/repos/tracexec/target/debug/deps/liblibbpf_sys-abc8218b23be072d.rlib(elf_begin.o) is incompatible with elf64-x86-64
          rust-lld: error: /home/kxxt/repos/tracexec/target/debug/deps/liblibbpf_sys-abc8218b23be072d.rlib(elf_next.o) is incompatible with elf64-x86-64
          rust-lld: error: /home/kxxt/repos/tracexec/target/debug/deps/liblibbpf_sys-abc8218b23be072d.rlib(elf_rand.o) is incompatible with elf64-x86-64
          rust-lld: error: /home/kxxt/repos/tracexec/target/debug/deps/liblibbpf_sys-abc8218b23be072d.rlib(elf_end.o) is incompatible with elf64-x86-64

dynamic:

  = note: rust-lld: error: /home/kxxt/repos/tracexec/3rdparty/aarch64/usr/lib/aarch64-linux-gnu/libelf.so is incompatible with elf64-x86-64
          rust-lld: error: /home/kxxt/repos/tracexec/3rdparty/aarch64/usr/lib/aarch64-linux-gnu/libz.so is incompatible with elf64-x86-64
          collect2: error: ld returned 1 exit status

This almost makes LIBBPF_SYS_LIBRARY_PATH useless unless libbpf-sys is only used as a dependency but not a build dependency at the same time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions