Repository navigation
Conversation
A C++ record declared with the class keyword has DW_TAG_class_type in the debug info. Since llvm#155783, visitCompositeType() hits llvm_unreachable() on it; before, the class type was emitted as type 0. The CO-RE pass only computes the field offset for DW_TAG_structure_type, so an access into a class got the offset 0: for "class C { public: int x, y; }", &c->y was relocated as offset 0 instead of 4. Handle DW_TAG_class_type wherever DW_TAG_structure_type is handled, so that a class becomes a BTF struct (not a union) and is relocated like one. A class with methods, base classes or static data members also needs llvm#226717. Assisted-by: Claude Code (Claude Opus 5.5)
|
Hello @maxskokov 👋 Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.
Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description. Frequently asked questionsHow do I add reviewers? This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically. You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using What if there are no comments? If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers. Are any special GitHub settings required to contribute to LLVM? We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details. If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse. Thank you, |
|
I've read the policies, including the AI Tool Use Policy. AI tool use is noted in the description with an Assisted-by line, and I've reviewed and tested the change myself. |
|
ping |
|
Superseded by #233715. |
A C++ record declared with the
classkeyword hasDW_TAG_class_typein the debug info, and the BPF backend only handlesDW_TAG_structure_type:DW_TAG_variant_partin BTF generation #155783 (LLVM 22.1),visitCompositeType()hitsllvm_unreachable()on a class, so compiling C++ for BPF with-gcrashes as soon as a class is used. Before, the class was emitted as type 0 (clang 19:Holder.cgetstype_id=0).DW_TAG_structure_type, so&p->yabove is relocated as offset 0 instead of 4 (@"llvm.C:0:0$0:1"with clang 19 and main).This PR handles
DW_TAG_class_typewhereverDW_TAG_structure_typeis handled, through one helper, so a class becomes a BTF struct (not a union) and is relocated like one. On its own it fixes classes whose elements are all data members; a class with methods, base classes or static data members also needs #226717, so neither PR makes C++ classes work without the other.Testing: new tests check that a class and a declared-only class become
STRUCTandFWDin BTF, that a map definition declared as a class gets the type its value points to in full rather than asFWD, as for a struct, and that a CO-RE access and the field info byte offset of a bit-field in a class are right; both fail on main. The kernel BPF selftests (999 C programs) compile to byte-identical code,.BTFand.BTF.ext. All BPF lit tests pass.This is the other half of #226717: that PR handles base classes, static data members and methods in C++ records, this one records declared with
class. They touch the same lines, so whichever lands second needs a rebase, and two checks from #226717 then needisStructTag()as well:getBTFRecordElements()inBPFCORE.h, and the struct/union check before the field index mapping incomputeBaseAndAccessKey().This fixes a crash that is a regression since 22.1 (#155783); once this lands I'd like to request a backport to 23.x together with #226717.
Assisted-by: Claude Code (Claude Opus 5.5)