浏览代码

btf: backport resolve_btfids ELF_T_WORD endian fix for sublevel-43 trees

Upstream 61e8aeda9398 (a9355b201d16) fixes libelf endian handling in
resolv_btfids. The .BTF_ids section content defaults to ELF_T_BYTE, so
libelf performs no per-word translation when resolve_btfids patches the
section back via elf_update(). Without ELF_T_WORD, BTF_ID entries (e.g.
xdp_buff) are mishandled and resolution aborts with 'FAILED unresolved
symbol xdp_buff' — the failure seen on android12-5.10-2021-10 and lower
(SUBLEVEL 43). Sublevels >= 66 (2021-11+) already carry the fix in-tree,
so the action step only patches when d_type = ELF_T_WORD is missing.

Verified: patched 2021-10 main.c is byte-identical to the working
2021-11 tree's main.c; the skip path exits 0 on already-fixed trees.
TheWildJames 1 月之前
父节点
当前提交
8c49102ae7
共有 2 个文件被更改,包括 33 次插入0 次删除
  1. 21 0
      .github/actions/btf/action.yml
  2. 12 0
      .github/actions/btf/patches/0004-resolve_btfids-elf-word.patch

+ 21 - 0
.github/actions/btf/action.yml

@@ -48,6 +48,27 @@ runs:
         # Idempotent/harmless on newer sublevels.
         patch -p1 -N < ${{ github.action_path }}/patches/0003-btf-emit-xdp-buff.patch
 
+    - name: Apply resolve_btfids ELF_T_WORD endian fix (android12-5.10)
+      shell: bash
+      working-directory: ${{ github.workspace }}/kernel/common
+      if: ${{ inputs.version == 'android12-5.10' }}
+      run: |
+        set -euo pipefail
+        # Backport of upstream 61e8aeda9398 ("bpf: Fix libelf endian handling
+        # in resolv_btfids"). The .BTF_ids section content defaults to
+        # ELF_T_BYTE, so libelf does no per-word translation when
+        # resolve_btfids patches the section back with elf_update(); without
+        # ELF_T_WORD the BTF_ID entries (e.g. xdp_buff) are handled as raw
+        # bytes and resolution fails with "FAILED unresolved symbol xdp_buff".
+        # Sublevels >= 66 (2021-11+) already carry this fix in-tree, so only
+        # patch when it is missing (sublevel-43 trees: 2021-10 and lower) to
+        # stay idempotent under `set -e`.
+        if ! grep -q 'd_type = ELF_T_WORD' tools/bpf/resolve_btfids/main.c; then
+          patch -p1 -N < ${{ github.action_path }}/patches/0004-resolve_btfids-elf-word.patch
+        else
+          echo "resolve_btfids already has the ELF_T_WORD fix; skipping"
+        fi
+
     - name: Expose host dd for hermetic BTF generation (android12-5.10)
       shell: bash
       working-directory: ${{ github.workspace }}/kernel/common

+ 12 - 0
.github/actions/btf/patches/0004-resolve_btfids-elf-word.patch

@@ -0,0 +1,12 @@
+--- a/tools/bpf/resolve_btfids/main.c
++++ b/tools/bpf/resolve_btfids/main.c
+@@ -649,6 +649,9 @@
+ 	if (sets_patch(obj))
+ 		return -1;
+ 
++	/* Set type to ensure endian translation occurs. */
++	obj->efile.idlist->d_type = ELF_T_WORD;
++
+ 	elf_flagdata(obj->efile.idlist, ELF_C_SET, ELF_F_DIRTY);
+ 
+ 	err = elf_update(obj->efile.elf, ELF_C_WRITE);