[PATCH] D143966: [DebugInfo][BPF] Add 'annotations' field for DIBasicType & DISubroutineType

Eduard Zingerman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 13 15:51:42 PDT 2023


eddyz87 created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
eddyz87 updated this revision to Diff 497834.
eddyz87 added a comment.
eddyz87 retitled this revision from "[DebugInfo][BPF] 'annotations' field for DIBasicType & DISubroutineType" to "[DebugInfo][BPF] Add 'annotations' field for DIBasicType & DISubroutineType".
eddyz87 edited the summary of this revision.
eddyz87 updated this revision to Diff 499279.
eddyz87 edited the summary of this revision.
eddyz87 updated this revision to Diff 502032.
eddyz87 updated this revision to Diff 502149.
eddyz87 updated this revision to Diff 502320.
eddyz87 updated this revision to Diff 504492.
eddyz87 published this revision for review.
eddyz87 added reviewers: yonghong-song, echristo, dblaikie.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

- Added tests for 'annotations' DWARF field generation for DIBasicType and DISubroutineType.
- Fix for DIBasicType::getImpl() to correctly handle Annotations field.
- Fix for `DwarfUnit::constructTypeDIE(... DIBasicType *BTy)` to generate annotations for dwarf::DW_TAG_unspecified_type instances.


eddyz87 added a comment.

Rebase


eddyz87 added a comment.

Rebase, change for tag name from btf_type_tag:v2 to btf:type_tag.


eddyz87 added a comment.

Fix for LLVMIR compilation error.


eddyz87 added a comment.

Another rebase, hope to fix windows build issue.


eddyz87 added a comment.

Rebase.


Extend `DIBasicType` and `DISubroutineType` with additional field 'annotations', e.g. as below:

  !5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed, annotations: !6)
  !6 = !{!7}
  !7 = !{!"btf_type_tag", !"tag1"}

These fields would be used by BPF backend to generate DWARF attributes corresponding to `btf_type_tag` type attributes, e.g.:

  0x00000029:   DW_TAG_base_type
                  DW_AT_name	("int")
                  DW_AT_encoding	(DW_ATE_signed)
                  DW_AT_byte_size	(0x04)
  
  0x0000002d:     DW_TAG_LLVM_annotation
                    DW_AT_name	("btf_type_tag")
                    DW_AT_const_value	("tag1")

Such DWARF entries would be used to generate BTF definitions by tools like pahole <https://github.com/acmel/dwarves>.

Note: similar fields with similar purposes are already present in `DIDerivedType` and `DICompositeType`.

Currently `btf_type_tag` attributes are represented in debug information as `annotations` fields in `DIDerivedType` with `DW_TAG_pointer_type tag`. The annotation on a pointer corresponds to pointee having the attributes in the final BTF.

The discussion <https://lore.kernel.org/bpf/87r0w9jjoq.fsf@oracle.com/> at Kernel BPF mailing list came to conclusion, that such annotations should apply to the annotated type itself.
Hence the necessity to extend `DIBasicType` and `DISubroutineType` types with `annotations` field to represent cases like below:

  int __attribute__((btf_type_tag("foo"))) bar;


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143966

Files:
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/MetadataLoader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/test/Bitcode/attr-btf_tag-dibasic.ll
  llvm/test/Bitcode/attr-btf_tag-disubroutine.ll
  llvm/test/DebugInfo/attr-btf_type_tag.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143966.504492.patch
Type: text/x-patch
Size: 31527 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230313/0872a8e5/attachment.bin>


More information about the llvm-commits mailing list