-1

Here's the error that I am getting and none of the online solutions are effectively fixing the issues that I am having. Just adding #include <stdint.h> breaks the compilation of my code. I tried installing multilib but the library seems to have no support on Ubuntu. I also tried some of the compatibility libraries but to no avail.

clang -O2 -target bpf -c hello.c -o hello.o
In file included from hello.c:2:
In file included from /usr/lib/llvm-11/lib/clang/11.0.0/include/stdint.h:52:
/usr/include/stdint.h:26:10: fatal error: 'bits/libc-header-start.h' file not found
#include <bits/libc-header-start.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

The code for reference. I am trying to run a compiled version of uBPF on an ARM device

#include <stdint.h>

static int idouble(int a)
{
    return (a * 2);
}

int bpf_prog(void *ctx)
{
    int a = 1;
    a = idouble(a);
    return (a);
}

This question is based on this Klyr's tutorial on how to setup user input with uBPF.

Zarif Rahman
  • 79
  • 1
  • 8
  • Can you compile native code (i.e. without the -target flag)? – n. m. could be an AI Jun 21 '21 at 18:47
  • Nope :( not possible. I get **Failed to load code: wrong machine, expected none or BPF, got 183** – Zarif Rahman Jun 21 '21 at 19:07
  • Why do you expect that including `stdint.h` would work in BPF? – pchaigno Jun 21 '21 at 19:36
  • I'm basing this off this blog testing out uBPF [here](https://klyr.github.io/posts/playing_with_ubpf/) – Zarif Rahman Jun 21 '21 at 20:23
  • I'm guessing those examples work if you try on an amd614 CPU? – pchaigno Jun 21 '21 at 20:43
  • I'm running a version of uBPF meant to run on arm actually. It was modified to run by one of the members of the eBPF slack community. The library issues seem to be something with an installation maybe? – Zarif Rahman Jun 21 '21 at 21:01
  • Actually running it on an x86 computer nets me the same error sadly – Zarif Rahman Jun 21 '21 at 21:32
  • `` is a standard header, so it can't be wrong for your C code to be using it. Since the error comes from inside the actual `stdint.h` file, it suggests an installation problem. Cross-compilation can be almost arbitrarily complex, and it wouldn't surprise me if someone's attempt to resolve some other issue ended up with an incompatible version of `stdint.h` being installed somewhere. – Steve Summit Jun 21 '21 at 23:56
  • 1
    @SteveSummit Note this is not standard C, but BPF C. – pchaigno Jun 22 '21 at 08:01
  • 1
    Can reproduce on x86_64, Ubuntu. `sudo apt install gcc-multilib` is enough to fix it in my case, what makes you believe the multilib has no support on Ubuntu? – Qeole Jun 22 '21 at 08:03
  • Yes, GCC-multilib fixes it on x86 but I still want to fix it on my Pi and there does not seem to be an equivalent that I can find at this moment. – Zarif Rahman Jun 22 '21 at 12:54

1 Answers1

0

I was able to have my issue fixed actually. ARM does not have a gcc-multilib equivalent so you must install gcc-multilib-arm-linux-gnueabihf for this to work. When trying to compile and target with Clang, you must first

cd /usr/include/aarch64-linux-gnu

then

sudo cp -r . ..

It's a hacky solution but it will let you import libraries as you see fit

Zarif Rahman
  • 79
  • 1
  • 8