{"id":19453565,"url":"https://github.com/bowei/cilium-bpf-hack","last_synced_at":"2026-04-19T15:03:12.718Z","repository":{"id":255535764,"uuid":"852331703","full_name":"bowei/cilium-bpf-hack","owner":"bowei","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-07T05:46:30.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-08T00:35:15.976Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bowei.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-04T16:13:54.000Z","updated_at":"2024-09-07T05:46:33.000Z","dependencies_parsed_at":"2024-09-07T02:45:55.962Z","dependency_job_id":null,"html_url":"https://github.com/bowei/cilium-bpf-hack","commit_stats":null,"previous_names":["bowei/cilium-bpf-hack"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowei%2Fcilium-bpf-hack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowei%2Fcilium-bpf-hack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowei%2Fcilium-bpf-hack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowei%2Fcilium-bpf-hack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bowei","download_url":"https://codeload.github.com/bowei/cilium-bpf-hack/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240645589,"owners_count":19834443,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T17:05:02.143Z","updated_at":"2025-11-18T15:05:14.238Z","avatar_url":"https://github.com/bowei.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cilium-bpf-hack\n\nThis is a bunch of scripts to visualize the Cilium BPF codebase. \n\nWARNING: The software here is a hack, so be aware of its general instability and\nhackery.\n\n## Usage\n\nThe general flow is:\n\n* Generate an LLVM bitcode output from the BPF code.\n* Generate an associated annotations file from the source code using `cmd/genam/genam.sh`.\n* Generate the graphviz PDF output using `cmd/cfg`.\n\n### Generating the BPF LLVM object code\n\nWARNING: total hack here.\n\nMake the bpf test object file. Right now the way I do this is to grab the\ncommand line for the fully expanded options from running `make` and change the\noptimization to `-O=0 -emit-llvm` and remove inlining:\n\n```\n$ clang -O0 -DSKIP_DEBUG=1 \\\n  -DENABLE_IPV4=1 -DENABLE_IPV6=1 -DENABLE_ROUTING=1 ... \\\n  -I/home/bowei/work/cilium/bpf/include \\\n  -I/home/bowei/work/cilium/bpf \\\n  -D__NR_CPUS__=8 -g --target=bpf -std=gnu89 -nostdinc \\\n  -Wall -W... \\\n  -mcpu=v3 -emit-llvm -S -c bpf_lxc.c \\\n  -o bpf_lxc.ll\n```\n\nInline removal patch:\n\n```\ndiff --git a/bpf/include/bpf/compiler.h b/bpf/include/bpf/compiler.h\nindex d685e454e8..2b0c4cc673 100644\n--- a/bpf/include/bpf/compiler.h\n+++ b/bpf/include/bpf/compiler.h\n@@ -42,7 +42,9 @@\n #endif\n \n #undef __always_inline         /* stddef.h defines its own */\n-#define __always_inline                inline __attribute__((always_inline))\n+//#define __always_inline              inline __attribute__((always_inline))\n+\n+#define __always_inline\n \n #ifndef __stringify\n # define __stringify(X)                #X\ndiff --git a/bpf/lib/source_info.h b/bpf/lib/source_info.h\nindex 5cdc083f4e..79324a2d18 100644\n--- a/bpf/lib/source_info.h\n+++ b/bpf/lib/source_info.h\n@@ -3,7 +3,7 @@\n #pragma once\n \n #ifndef BPF_TEST\n-#define __MAGIC_FILE__ (__u8)__id_for_file(__FILE_NAME__)\n+#define __MAGIC_FILE__ (__u8)__id_for_file(__FILE__)\n #define __MAGIC_LINE__ __LINE__\n #else\n /* bpf tests assert that metrics get updated by performing a map lookup.\n```\n\nThis will generate a `bpf_lxc.ll` that has the object file as LLVM bitcode.\n\n### Generating diagrams\n\n#### Source annotations\n\n`genam` generates an annotations file from the source code. This is a file that\ncontains a mapping of `file:line` with comments/annotations in the\nresulting diagrams.\n\n```\n$ bash cmd/genan/genan.sh ../cilium/bpf \u003e annotations.txt\n```\n\n#### Control flow output\n\n```\n# $1 is the name of the function to start the diagram from. E.g. cil_from_container.\n$ ./cfg -mode rawcg \\\n  -in bpf_lxc.ll \\\n  -an annotations1.txt \\\n  -an annotations2.txt \\\n  -start $1 \\\n  \u003e /tmp/out.gv\n\n$ dot -Tpdf /tmp/out.gv -o out.pdf\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbowei%2Fcilium-bpf-hack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbowei%2Fcilium-bpf-hack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbowei%2Fcilium-bpf-hack/lists"}