aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
diff options
context:
space:
mode:
authoreddyz87 <eddyz87@gmail.com>2024-06-18 10:23:25 +0300
committerGitHub <noreply@github.com>2024-06-18 10:23:25 +0300
commit3ca17443ef4af21bdb1f3b4fbcfff672cbc6176c (patch)
tree688ece13f66b40a8d309953781c085f0802c2e68 /llvm/lib/Bitcode/Reader/MetadataLoader.cpp
parentd95b82c49aef0223bcc03ff5a9163e70037c82be (diff)
downloadllvm-3ca17443ef4af21bdb1f3b4fbcfff672cbc6176c.zip
llvm-3ca17443ef4af21bdb1f3b4fbcfff672cbc6176c.tar.gz
llvm-3ca17443ef4af21bdb1f3b4fbcfff672cbc6176c.tar.bz2
[DebugInfo][BPF] Add 'annotations' field for DIBasicType & DISubroutineType (#91422)
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"} ``` The field 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 in [thread](https://lore.kernel.org/bpf/87r0w9jjoq.fsf@oracle.com/) came to conclusion, that such annotations should apply to the annotated type itself. Hence the necessity to extend `DIBasicType` & `DISubroutineType` types with 'annotations' field to represent cases like below: ``` int __attribute__((btf_type_tag("foo"))) bar; ``` This was previously tracked as differential revision: https://reviews.llvm.org/D143966
Diffstat (limited to 'llvm/lib/Bitcode/Reader/MetadataLoader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/MetadataLoader.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 9102f3a..bc06c55 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -1527,7 +1527,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
break;
}
case bitc::METADATA_BASIC_TYPE: {
- if (Record.size() < 6 || Record.size() > 7)
+ if (Record.size() < 6 || Record.size() > 8)
return error("Invalid record");
IsDistinct = Record[0];
@@ -1535,10 +1535,14 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
? static_cast<DINode::DIFlags>(Record[6])
: DINode::FlagZero;
+ Metadata *Annotations = nullptr;
+ if (Record.size() > 7 && Record[7])
+ Annotations = getMDOrNull(Record[7]);
+
MetadataList.assignValue(
GET_OR_DISTINCT(DIBasicType,
(Context, Record[1], getMDString(Record[2]), Record[3],
- Record[4], Record[5], Flags)),
+ Record[4], Record[5], Flags, Annotations)),
NextMetadataNo);
NextMetadataNo++;
break;
@@ -1703,7 +1707,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
break;
}
case bitc::METADATA_SUBROUTINE_TYPE: {
- if (Record.size() < 3 || Record.size() > 4)
+ if (Record.size() < 3 || Record.size() > 5)
return error("Invalid record");
bool IsOldTypeRefArray = Record[0] < 2;
unsigned CC = (Record.size() > 3) ? Record[3] : 0;
@@ -1713,9 +1717,13 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
Metadata *Types = getMDOrNull(Record[2]);
if (LLVM_UNLIKELY(IsOldTypeRefArray))
Types = MetadataList.upgradeTypeRefArray(Types);
+ Metadata *Annotations = nullptr;
+ if (Record.size() > 4 && Record[4])
+ Annotations = getMDOrNull(Record[4]);
MetadataList.assignValue(
- GET_OR_DISTINCT(DISubroutineType, (Context, Flags, CC, Types)),
+ GET_OR_DISTINCT(DISubroutineType,
+ (Context, Flags, CC, Types, Annotations)),
NextMetadataNo);
NextMetadataNo++;
break;