iovisor / iovisor/bcc

Statically compile BCC with LLVM

Open
#3,282 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
10d 4h
Merged PRs (30d)
3

Description

## Summary

I'm trying to embed bcc with clang and llvm into a Go program. I currently compile everything statically because it's great for portability. I would love to add bcc + clang + llvm to my go program, and I was able to do it, but the resulting binary doesn't work because LLVM fails when initializing a BPF module.

## Details

I'm building a Go app statically using `gobpf` and `-linkmode external -extldflags '-static' -lbcc -l...` in Alpine Linux (with musl libc) and I was able to build everything but the problem is that when I run my program the BCC `Module` fails to build, because llvm fails when it tries to compile ebpf program:
```
Could not create ExecutionEngine: Dynamic loading not supported
```

It happens here: https://github.com/iovisor/bcc/blob/25438d3863a0d5fc61af2d861a9e7c7a60a1cfbe/src/cc/bpf_module.cc#L472-L476

It looks like LLVM tries to do a `dlopen(null)`, meaning

> If file is a null pointer, dlopen() shall return a global symbol table handle for the currently running process image

`dlopen` is stubbed out in static musl libc so that's why the whole thing fails.

## Question

Is it possible to statically build bcc with llvm into one portable linux binary?

I'm not a big expert in compilers / linkers so any pointers would be appreciated.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.