Skip to content

Commit fcd4d3b

Browse files
viktormalikdanobi
authored andcommitted
Debug info: fix emitting struct names
When emitting debug info for structs (which will be translated into BTF), the name *must not* contain the "struct" (or "union") prefix, otherwise our emitted debug info will not match the kernel BTF (which doesn't use the prefix) and the programs where the match is required will be rejected.
1 parent 6139e3f commit fcd4d3b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/ast/dibuilderbpf.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,14 @@ DIType *DIBuilderBPF::CreateByteArrayType(uint64_t num_bytes)
212212
DIType *DIBuilderBPF::GetType(const SizedType &stype, bool emit_codegen_types)
213213
{
214214
if (!emit_codegen_types && stype.IsRecordTy()) {
215+
std::string name = stype.GetName();
216+
if (name.find("struct ") == 0)
217+
name = name.substr(std::string("struct ").length());
218+
else if (name.find("union ") == 0)
219+
name = name.substr(std::string("union ").length());
220+
215221
return createStructType(file,
216-
stype.GetName(),
222+
name,
217223
file,
218224
0,
219225
stype.GetSize() * 8,

tests/codegen/llvm/call_len_map_sum_elem_count.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,5 @@ attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: re
117117
!61 = !DISubroutineType(types: !62)
118118
!62 = !{!18, !63}
119119
!63 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !64, size: 64)
120-
!64 = !DICompositeType(tag: DW_TAG_structure_type, name: "struct bpf_map", scope: !2, file: !2, elements: !65)
120+
!64 = !DICompositeType(tag: DW_TAG_structure_type, name: "bpf_map", scope: !2, file: !2, elements: !65)
121121
!65 = !{}

0 commit comments

Comments
 (0)