Skip to content

dwarf_loader: Fix --lang_exclude on merged CUs

Alan Derk bpf dwarves rust-for-linux 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 3 repliesIn review
  2. v11 patch 0 repliesSuperseded

Changes in v2 from the cover letter

- Add patch 2.
- Patch 1 is unchanged; its note about the Kconfig follow-up moved here.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2dwarf_loader: Take the merged CU language from a CU that is keptdwarf_loader.c tests/lang_exclude_merged_cu.sh+89 -120 replies
2/2dwarf_loader: Load types that kept CUs use from excluded CUsdwarf_loader.c tests/lang_exclude_lto_refs.sh+164 -70 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH dwarves v2 0/2] dwarf_loader: Fix --lang_exclude on merged CUs

Two fixes for --lang_exclude when CUs are merged, as for LTO objects.

Patch 1 takes the merged CU's language from a CU that is kept, so that excluding the language of the first CU no longer drops the whole object. With LTO, this is what makes BTF generation fail for kernel modules that mix Rust and C.

Patch 2 fixes a second bug from the same commit, which I found while testing userspace LTO objects after sending v1. With clang LTO, a type such as int is emitted once and shared through DW_FORM_ref_addr, so skipping the excluded CUs left references into them dangling: pahole crashed printing such members, and -J encoded them as void. Patch 2 loads the types that kept CUs use from the excluded CUs. Output without --lang_exclude does not change, and neither does the BTF of the LTO kernels I tested.

Patch 1 exposes this bug in one more link order. For a C++ object linked before a C one, pahole used to drop the C types without any error; with patch 1 alone it keeps them, and then crashes printing them, or encodes them as void with -J. Please apply the two together.

As far as I know, patch 1 removes the last thing that keeps the kernel's RUST option off when LTO and BTF are both on. Once these fixes are in a release, I'd like to propose relaxing that dependency to something like:

  depends on !DEBUG_INFO_BTF || (PAHOLE_HAS_LANG_EXCLUDE && (!LTO || PAHOLE_VERSION >= 133))

assuming they land in 1.33. The kernel tests in patch 1 ran with "&& !LTO" dropped from that line, hence the Cc to rust-for-linux.

Changes in v2:
- Add patch 2.
- Patch 1 is unchanged; its note about the Kconfig follow-up moved here.

v1: https://lore.kernel.org/all/[email protected]/

Alan Derk (2):
dwarf_loader: Take the merged CU language from a CU that is kept
dwarf_loader: Load types that kept CUs use from excluded CUs

 dwarf_loader.c                  | 129 +++++++++++++++++++++++++++-----
 tests/lang_exclude_lto_refs.sh  |  76 +++++++++++++++++++
 tests/lang_exclude_merged_cu.sh |  67 +++++++++++++++++
 3 files changed, 253 insertions(+), 19 deletions(-)
 create mode 100755 tests/lang_exclude_lto_refs.sh
 create mode 100755 tests/lang_exclude_merged_cu.sh

base-commit: 1e342ac44979748bcf5bb37f84ea055e7f4d7184

Signature · 1 line
2.55.0