LLVM  14.0.0git
BTFDebug.cpp
Go to the documentation of this file.
1 //===- BTFDebug.cpp - BTF Generator ---------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains support for writing BTF debug info.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "BTFDebug.h"
14 #include "BPF.h"
15 #include "BPFCORE.h"
17 #include "llvm/BinaryFormat/ELF.h"
20 #include "llvm/MC/MCContext.h"
22 #include "llvm/MC/MCSectionELF.h"
23 #include "llvm/MC/MCStreamer.h"
26 
27 using namespace llvm;
28 
29 static const char *BTFKindStr[] = {
30 #define HANDLE_BTF_KIND(ID, NAME) "BTF_KIND_" #NAME,
31 #include "BTF.def"
32 };
33 
34 /// Emit a BTF common type.
36  OS.AddComment(std::string(BTFKindStr[Kind]) + "(id = " + std::to_string(Id) +
37  ")");
42 }
43 
45  bool NeedsFixup)
46  : DTy(DTy), NeedsFixup(NeedsFixup) {
47  switch (Tag) {
48  case dwarf::DW_TAG_pointer_type:
49  Kind = BTF::BTF_KIND_PTR;
50  break;
51  case dwarf::DW_TAG_const_type:
52  Kind = BTF::BTF_KIND_CONST;
53  break;
54  case dwarf::DW_TAG_volatile_type:
55  Kind = BTF::BTF_KIND_VOLATILE;
56  break;
57  case dwarf::DW_TAG_typedef:
58  Kind = BTF::BTF_KIND_TYPEDEF;
59  break;
60  case dwarf::DW_TAG_restrict_type:
61  Kind = BTF::BTF_KIND_RESTRICT;
62  break;
63  default:
64  llvm_unreachable("Unknown DIDerivedType Tag");
65  }
66  BTFType.Info = Kind << 24;
67 }
68 
70  if (IsCompleted)
71  return;
72  IsCompleted = true;
73 
74  BTFType.NameOff = BDebug.addString(DTy->getName());
75 
76  if (NeedsFixup)
77  return;
78 
79  // The base type for PTR/CONST/VOLATILE could be void.
80  const DIType *ResolvedType = DTy->getBaseType();
81  if (!ResolvedType) {
82  assert((Kind == BTF::BTF_KIND_PTR || Kind == BTF::BTF_KIND_CONST ||
83  Kind == BTF::BTF_KIND_VOLATILE) &&
84  "Invalid null basetype");
85  BTFType.Type = 0;
86  } else {
87  BTFType.Type = BDebug.getTypeId(ResolvedType);
88  }
89 }
90 
92 
94  BTFType.Type = PointeeType;
95 }
96 
97 /// Represent a struct/union forward declaration.
99  Kind = BTF::BTF_KIND_FWD;
100  BTFType.Info = IsUnion << 31 | Kind << 24;
101  BTFType.Type = 0;
102 }
103 
105  if (IsCompleted)
106  return;
107  IsCompleted = true;
108 
109  BTFType.NameOff = BDebug.addString(Name);
110 }
111 
113 
115  uint32_t OffsetInBits, StringRef TypeName)
116  : Name(TypeName) {
117  // Translate IR int encoding to BTF int encoding.
118  uint8_t BTFEncoding;
119  switch (Encoding) {
120  case dwarf::DW_ATE_boolean:
121  BTFEncoding = BTF::INT_BOOL;
122  break;
123  case dwarf::DW_ATE_signed:
124  case dwarf::DW_ATE_signed_char:
125  BTFEncoding = BTF::INT_SIGNED;
126  break;
127  case dwarf::DW_ATE_unsigned:
128  case dwarf::DW_ATE_unsigned_char:
129  BTFEncoding = 0;
130  break;
131  default:
132  llvm_unreachable("Unknown BTFTypeInt Encoding");
133  }
134 
135  Kind = BTF::BTF_KIND_INT;
136  BTFType.Info = Kind << 24;
137  BTFType.Size = roundupToBytes(SizeInBits);
138  IntVal = (BTFEncoding << 24) | OffsetInBits << 16 | SizeInBits;
139 }
140 
142  if (IsCompleted)
143  return;
144  IsCompleted = true;
145 
146  BTFType.NameOff = BDebug.addString(Name);
147 }
148 
151  OS.AddComment("0x" + Twine::utohexstr(IntVal));
152  OS.emitInt32(IntVal);
153 }
154 
155 BTFTypeEnum::BTFTypeEnum(const DICompositeType *ETy, uint32_t VLen) : ETy(ETy) {
156  Kind = BTF::BTF_KIND_ENUM;
157  BTFType.Info = Kind << 24 | VLen;
159 }
160 
162  if (IsCompleted)
163  return;
164  IsCompleted = true;
165 
166  BTFType.NameOff = BDebug.addString(ETy->getName());
167 
168  DINodeArray Elements = ETy->getElements();
169  for (const auto Element : Elements) {
170  const auto *Enum = cast<DIEnumerator>(Element);
171 
172  struct BTF::BTFEnum BTFEnum;
173  BTFEnum.NameOff = BDebug.addString(Enum->getName());
174  // BTF enum value is 32bit, enforce it.
175  uint32_t Value;
176  if (Enum->isUnsigned())
177  Value = static_cast<uint32_t>(Enum->getValue().getZExtValue());
178  else
179  Value = static_cast<uint32_t>(Enum->getValue().getSExtValue());
180  BTFEnum.Val = Value;
181  EnumValues.push_back(BTFEnum);
182  }
183 }
184 
187  for (const auto &Enum : EnumValues) {
188  OS.emitInt32(Enum.NameOff);
189  OS.emitInt32(Enum.Val);
190  }
191 }
192 
194  Kind = BTF::BTF_KIND_ARRAY;
195  BTFType.NameOff = 0;
196  BTFType.Info = Kind << 24;
197  BTFType.Size = 0;
198 
199  ArrayInfo.ElemType = ElemTypeId;
200  ArrayInfo.Nelems = NumElems;
201 }
202 
203 /// Represent a BTF array.
205  if (IsCompleted)
206  return;
207  IsCompleted = true;
208 
209  // The IR does not really have a type for the index.
210  // A special type for array index should have been
211  // created during initial type traversal. Just
212  // retrieve that type id.
213  ArrayInfo.IndexType = BDebug.getArrayIndexTypeId();
214 }
215 
218  OS.emitInt32(ArrayInfo.ElemType);
219  OS.emitInt32(ArrayInfo.IndexType);
220  OS.emitInt32(ArrayInfo.Nelems);
221 }
222 
223 /// Represent either a struct or a union.
225  bool HasBitField, uint32_t Vlen)
226  : STy(STy), HasBitField(HasBitField) {
227  Kind = IsStruct ? BTF::BTF_KIND_STRUCT : BTF::BTF_KIND_UNION;
229  BTFType.Info = (HasBitField << 31) | (Kind << 24) | Vlen;
230 }
231 
233  if (IsCompleted)
234  return;
235  IsCompleted = true;
236 
237  BTFType.NameOff = BDebug.addString(STy->getName());
238 
239  // Add struct/union members.
240  const DINodeArray Elements = STy->getElements();
241  for (const auto *Element : Elements) {
242  struct BTF::BTFMember BTFMember;
243  const auto *DDTy = cast<DIDerivedType>(Element);
244 
245  BTFMember.NameOff = BDebug.addString(DDTy->getName());
246  if (HasBitField) {
247  uint8_t BitFieldSize = DDTy->isBitField() ? DDTy->getSizeInBits() : 0;
248  BTFMember.Offset = BitFieldSize << 24 | DDTy->getOffsetInBits();
249  } else {
250  BTFMember.Offset = DDTy->getOffsetInBits();
251  }
252  const auto *BaseTy = DDTy->getBaseType();
253  BTFMember.Type = BDebug.getTypeId(BaseTy);
254  Members.push_back(BTFMember);
255  }
256 }
257 
260  for (const auto &Member : Members) {
261  OS.emitInt32(Member.NameOff);
262  OS.emitInt32(Member.Type);
263  OS.AddComment("0x" + Twine::utohexstr(Member.Offset));
264  OS.emitInt32(Member.Offset);
265  }
266 }
267 
268 std::string BTFTypeStruct::getName() { return std::string(STy->getName()); }
269 
270 /// The Func kind represents both subprogram and pointee of function
271 /// pointers. If the FuncName is empty, it represents a pointee of function
272 /// pointer. Otherwise, it represents a subprogram. The func arg names
273 /// are empty for pointee of function pointer case, and are valid names
274 /// for subprogram.
276  const DISubroutineType *STy, uint32_t VLen,
277  const std::unordered_map<uint32_t, StringRef> &FuncArgNames)
278  : STy(STy), FuncArgNames(FuncArgNames) {
279  Kind = BTF::BTF_KIND_FUNC_PROTO;
280  BTFType.Info = (Kind << 24) | VLen;
281 }
282 
284  if (IsCompleted)
285  return;
286  IsCompleted = true;
287 
288  DITypeRefArray Elements = STy->getTypeArray();
289  auto RetType = Elements[0];
290  BTFType.Type = RetType ? BDebug.getTypeId(RetType) : 0;
291  BTFType.NameOff = 0;
292 
293  // For null parameter which is typically the last one
294  // to represent the vararg, encode the NameOff/Type to be 0.
295  for (unsigned I = 1, N = Elements.size(); I < N; ++I) {
296  struct BTF::BTFParam Param;
297  auto Element = Elements[I];
298  if (Element) {
299  Param.NameOff = BDebug.addString(FuncArgNames[I]);
300  Param.Type = BDebug.getTypeId(Element);
301  } else {
302  Param.NameOff = 0;
303  Param.Type = 0;
304  }
305  Parameters.push_back(Param);
306  }
307 }
308 
311  for (const auto &Param : Parameters) {
312  OS.emitInt32(Param.NameOff);
313  OS.emitInt32(Param.Type);
314  }
315 }
316 
318  uint32_t Scope)
319  : Name(FuncName) {
320  Kind = BTF::BTF_KIND_FUNC;
321  BTFType.Info = (Kind << 24) | Scope;
322  BTFType.Type = ProtoTypeId;
323 }
324 
326  if (IsCompleted)
327  return;
328  IsCompleted = true;
329 
330  BTFType.NameOff = BDebug.addString(Name);
331 }
332 
334 
336  : Name(VarName) {
337  Kind = BTF::BTF_KIND_VAR;
338  BTFType.Info = Kind << 24;
339  BTFType.Type = TypeId;
340  Info = VarInfo;
341 }
342 
344  BTFType.NameOff = BDebug.addString(Name);
345 }
346 
349  OS.emitInt32(Info);
350 }
351 
352 BTFKindDataSec::BTFKindDataSec(AsmPrinter *AsmPrt, std::string SecName)
353  : Asm(AsmPrt), Name(SecName) {
354  Kind = BTF::BTF_KIND_DATASEC;
355  BTFType.Info = Kind << 24;
356  BTFType.Size = 0;
357 }
358 
360  BTFType.NameOff = BDebug.addString(Name);
361  BTFType.Info |= Vars.size();
362 }
363 
366 
367  for (const auto &V : Vars) {
368  OS.emitInt32(std::get<0>(V));
369  Asm->emitLabelReference(std::get<1>(V), 4);
370  OS.emitInt32(std::get<2>(V));
371  }
372 }
373 
375  : Name(TypeName) {
376  Kind = BTF::BTF_KIND_FLOAT;
377  BTFType.Info = Kind << 24;
378  BTFType.Size = roundupToBytes(SizeInBits);
379 }
380 
382  if (IsCompleted)
383  return;
384  IsCompleted = true;
385 
386  BTFType.NameOff = BDebug.addString(Name);
387 }
388 
390  // Check whether the string already exists.
391  for (auto &OffsetM : OffsetToIdMap) {
392  if (Table[OffsetM.second] == S)
393  return OffsetM.first;
394  }
395  // Not find, add to the string table.
396  uint32_t Offset = Size;
397  OffsetToIdMap[Offset] = Table.size();
398  Table.push_back(std::string(S));
399  Size += S.size() + 1;
400  return Offset;
401 }
402 
404  : DebugHandlerBase(AP), OS(*Asm->OutStreamer), SkipInstruction(false),
405  LineInfoGenerated(false), SecNameOff(0), ArrayIndexTypeId(0),
406  MapDefNotCollected(true) {
407  addString("\0");
408 }
409 
410 uint32_t BTFDebug::addType(std::unique_ptr<BTFTypeBase> TypeEntry,
411  const DIType *Ty) {
412  TypeEntry->setId(TypeEntries.size() + 1);
413  uint32_t Id = TypeEntry->getId();
414  DIToIdMap[Ty] = Id;
415  TypeEntries.push_back(std::move(TypeEntry));
416  return Id;
417 }
418 
419 uint32_t BTFDebug::addType(std::unique_ptr<BTFTypeBase> TypeEntry) {
420  TypeEntry->setId(TypeEntries.size() + 1);
421  uint32_t Id = TypeEntry->getId();
422  TypeEntries.push_back(std::move(TypeEntry));
423  return Id;
424 }
425 
426 void BTFDebug::visitBasicType(const DIBasicType *BTy, uint32_t &TypeId) {
427  // Only int and binary floating point types are supported in BTF.
428  uint32_t Encoding = BTy->getEncoding();
429  std::unique_ptr<BTFTypeBase> TypeEntry;
430  switch (Encoding) {
431  case dwarf::DW_ATE_boolean:
432  case dwarf::DW_ATE_signed:
433  case dwarf::DW_ATE_signed_char:
434  case dwarf::DW_ATE_unsigned:
435  case dwarf::DW_ATE_unsigned_char:
436  // Create a BTF type instance for this DIBasicType and put it into
437  // DIToIdMap for cross-type reference check.
438  TypeEntry = std::make_unique<BTFTypeInt>(
439  Encoding, BTy->getSizeInBits(), BTy->getOffsetInBits(), BTy->getName());
440  break;
441  case dwarf::DW_ATE_float:
442  TypeEntry =
443  std::make_unique<BTFTypeFloat>(BTy->getSizeInBits(), BTy->getName());
444  break;
445  default:
446  return;
447  }
448 
449  TypeId = addType(std::move(TypeEntry), BTy);
450 }
451 
452 /// Handle subprogram or subroutine types.
453 void BTFDebug::visitSubroutineType(
454  const DISubroutineType *STy, bool ForSubprog,
455  const std::unordered_map<uint32_t, StringRef> &FuncArgNames,
456  uint32_t &TypeId) {
457  DITypeRefArray Elements = STy->getTypeArray();
458  uint32_t VLen = Elements.size() - 1;
459  if (VLen > BTF::MAX_VLEN)
460  return;
461 
462  // Subprogram has a valid non-zero-length name, and the pointee of
463  // a function pointer has an empty name. The subprogram type will
464  // not be added to DIToIdMap as it should not be referenced by
465  // any other types.
466  auto TypeEntry = std::make_unique<BTFTypeFuncProto>(STy, VLen, FuncArgNames);
467  if (ForSubprog)
468  TypeId = addType(std::move(TypeEntry)); // For subprogram
469  else
470  TypeId = addType(std::move(TypeEntry), STy); // For func ptr
471 
472  // Visit return type and func arg types.
473  for (const auto Element : Elements) {
474  visitTypeEntry(Element);
475  }
476 }
477 
478 /// Handle structure/union types.
479 void BTFDebug::visitStructType(const DICompositeType *CTy, bool IsStruct,
480  uint32_t &TypeId) {
481  const DINodeArray Elements = CTy->getElements();
482  uint32_t VLen = Elements.size();
483  if (VLen > BTF::MAX_VLEN)
484  return;
485 
486  // Check whether we have any bitfield members or not
487  bool HasBitField = false;
488  for (const auto *Element : Elements) {
489  auto E = cast<DIDerivedType>(Element);
490  if (E->isBitField()) {
491  HasBitField = true;
492  break;
493  }
494  }
495 
496  auto TypeEntry =
497  std::make_unique<BTFTypeStruct>(CTy, IsStruct, HasBitField, VLen);
498  StructTypes.push_back(TypeEntry.get());
499  TypeId = addType(std::move(TypeEntry), CTy);
500 
501  // Visit all struct members.
502  for (const auto *Element : Elements)
503  visitTypeEntry(cast<DIDerivedType>(Element));
504 }
505 
506 void BTFDebug::visitArrayType(const DICompositeType *CTy, uint32_t &TypeId) {
507  // Visit array element type.
508  uint32_t ElemTypeId;
509  const DIType *ElemType = CTy->getBaseType();
510  visitTypeEntry(ElemType, ElemTypeId, false, false);
511 
512  // Visit array dimensions.
513  DINodeArray Elements = CTy->getElements();
514  for (int I = Elements.size() - 1; I >= 0; --I) {
515  if (auto *Element = dyn_cast_or_null<DINode>(Elements[I]))
516  if (Element->getTag() == dwarf::DW_TAG_subrange_type) {
517  const DISubrange *SR = cast<DISubrange>(Element);
518  auto *CI = SR->getCount().dyn_cast<ConstantInt *>();
519  int64_t Count = CI->getSExtValue();
520 
521  // For struct s { int b; char c[]; }, the c[] will be represented
522  // as an array with Count = -1.
523  auto TypeEntry =
524  std::make_unique<BTFTypeArray>(ElemTypeId,
525  Count >= 0 ? Count : 0);
526  if (I == 0)
527  ElemTypeId = addType(std::move(TypeEntry), CTy);
528  else
529  ElemTypeId = addType(std::move(TypeEntry));
530  }
531  }
532 
533  // The array TypeId is the type id of the outermost dimension.
534  TypeId = ElemTypeId;
535 
536  // The IR does not have a type for array index while BTF wants one.
537  // So create an array index type if there is none.
538  if (!ArrayIndexTypeId) {
539  auto TypeEntry = std::make_unique<BTFTypeInt>(dwarf::DW_ATE_unsigned, 32,
540  0, "__ARRAY_SIZE_TYPE__");
541  ArrayIndexTypeId = addType(std::move(TypeEntry));
542  }
543 }
544 
545 void BTFDebug::visitEnumType(const DICompositeType *CTy, uint32_t &TypeId) {
546  DINodeArray Elements = CTy->getElements();
547  uint32_t VLen = Elements.size();
548  if (VLen > BTF::MAX_VLEN)
549  return;
550 
551  auto TypeEntry = std::make_unique<BTFTypeEnum>(CTy, VLen);
552  TypeId = addType(std::move(TypeEntry), CTy);
553  // No need to visit base type as BTF does not encode it.
554 }
555 
556 /// Handle structure/union forward declarations.
557 void BTFDebug::visitFwdDeclType(const DICompositeType *CTy, bool IsUnion,
558  uint32_t &TypeId) {
559  auto TypeEntry = std::make_unique<BTFTypeFwd>(CTy->getName(), IsUnion);
560  TypeId = addType(std::move(TypeEntry), CTy);
561 }
562 
563 /// Handle structure, union, array and enumeration types.
564 void BTFDebug::visitCompositeType(const DICompositeType *CTy,
565  uint32_t &TypeId) {
566  auto Tag = CTy->getTag();
567  if (Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type) {
568  // Handle forward declaration differently as it does not have members.
569  if (CTy->isForwardDecl())
570  visitFwdDeclType(CTy, Tag == dwarf::DW_TAG_union_type, TypeId);
571  else
572  visitStructType(CTy, Tag == dwarf::DW_TAG_structure_type, TypeId);
573  } else if (Tag == dwarf::DW_TAG_array_type)
574  visitArrayType(CTy, TypeId);
575  else if (Tag == dwarf::DW_TAG_enumeration_type)
576  visitEnumType(CTy, TypeId);
577 }
578 
579 /// Handle pointer, typedef, const, volatile, restrict and member types.
580 void BTFDebug::visitDerivedType(const DIDerivedType *DTy, uint32_t &TypeId,
581  bool CheckPointer, bool SeenPointer) {
582  unsigned Tag = DTy->getTag();
583 
584  /// Try to avoid chasing pointees, esp. structure pointees which may
585  /// unnecessary bring in a lot of types.
586  if (CheckPointer && !SeenPointer) {
587  SeenPointer = Tag == dwarf::DW_TAG_pointer_type;
588  }
589 
590  if (CheckPointer && SeenPointer) {
591  const DIType *Base = DTy->getBaseType();
592  if (Base) {
593  if (const auto *CTy = dyn_cast<DICompositeType>(Base)) {
594  auto CTag = CTy->getTag();
595  if ((CTag == dwarf::DW_TAG_structure_type ||
596  CTag == dwarf::DW_TAG_union_type) &&
597  !CTy->getName().empty() && !CTy->isForwardDecl()) {
598  /// Find a candidate, generate a fixup. Later on the struct/union
599  /// pointee type will be replaced with either a real type or
600  /// a forward declaration.
601  auto TypeEntry = std::make_unique<BTFTypeDerived>(DTy, Tag, true);
602  auto &Fixup = FixupDerivedTypes[CTy->getName()];
603  Fixup.first = CTag == dwarf::DW_TAG_union_type;
604  Fixup.second.push_back(TypeEntry.get());
605  TypeId = addType(std::move(TypeEntry), DTy);
606  return;
607  }
608  }
609  }
610  }
611 
612  if (Tag == dwarf::DW_TAG_pointer_type || Tag == dwarf::DW_TAG_typedef ||
613  Tag == dwarf::DW_TAG_const_type || Tag == dwarf::DW_TAG_volatile_type ||
614  Tag == dwarf::DW_TAG_restrict_type) {
615  auto TypeEntry = std::make_unique<BTFTypeDerived>(DTy, Tag, false);
616  TypeId = addType(std::move(TypeEntry), DTy);
617  } else if (Tag != dwarf::DW_TAG_member) {
618  return;
619  }
620 
621  // Visit base type of pointer, typedef, const, volatile, restrict or
622  // struct/union member.
623  uint32_t TempTypeId = 0;
624  if (Tag == dwarf::DW_TAG_member)
625  visitTypeEntry(DTy->getBaseType(), TempTypeId, true, false);
626  else
627  visitTypeEntry(DTy->getBaseType(), TempTypeId, CheckPointer, SeenPointer);
628 }
629 
630 void BTFDebug::visitTypeEntry(const DIType *Ty, uint32_t &TypeId,
631  bool CheckPointer, bool SeenPointer) {
632  if (!Ty || DIToIdMap.find(Ty) != DIToIdMap.end()) {
633  TypeId = DIToIdMap[Ty];
634 
635  // To handle the case like the following:
636  // struct t;
637  // typedef struct t _t;
638  // struct s1 { _t *c; };
639  // int test1(struct s1 *arg) { ... }
640  //
641  // struct t { int a; int b; };
642  // struct s2 { _t c; }
643  // int test2(struct s2 *arg) { ... }
644  //
645  // During traversing test1() argument, "_t" is recorded
646  // in DIToIdMap and a forward declaration fixup is created
647  // for "struct t" to avoid pointee type traversal.
648  //
649  // During traversing test2() argument, even if we see "_t" is
650  // already defined, we should keep moving to eventually
651  // bring in types for "struct t". Otherwise, the "struct s2"
652  // definition won't be correct.
653  if (Ty && (!CheckPointer || !SeenPointer)) {
654  if (const auto *DTy = dyn_cast<DIDerivedType>(Ty)) {
655  unsigned Tag = DTy->getTag();
656  if (Tag == dwarf::DW_TAG_typedef || Tag == dwarf::DW_TAG_const_type ||
657  Tag == dwarf::DW_TAG_volatile_type ||
658  Tag == dwarf::DW_TAG_restrict_type) {
659  uint32_t TmpTypeId;
660  visitTypeEntry(DTy->getBaseType(), TmpTypeId, CheckPointer,
661  SeenPointer);
662  }
663  }
664  }
665 
666  return;
667  }
668 
669  if (const auto *BTy = dyn_cast<DIBasicType>(Ty))
670  visitBasicType(BTy, TypeId);
671  else if (const auto *STy = dyn_cast<DISubroutineType>(Ty))
672  visitSubroutineType(STy, false, std::unordered_map<uint32_t, StringRef>(),
673  TypeId);
674  else if (const auto *CTy = dyn_cast<DICompositeType>(Ty))
675  visitCompositeType(CTy, TypeId);
676  else if (const auto *DTy = dyn_cast<DIDerivedType>(Ty))
677  visitDerivedType(DTy, TypeId, CheckPointer, SeenPointer);
678  else
679  llvm_unreachable("Unknown DIType");
680 }
681 
682 void BTFDebug::visitTypeEntry(const DIType *Ty) {
683  uint32_t TypeId;
684  visitTypeEntry(Ty, TypeId, false, false);
685 }
686 
687 void BTFDebug::visitMapDefType(const DIType *Ty, uint32_t &TypeId) {
688  if (!Ty || DIToIdMap.find(Ty) != DIToIdMap.end()) {
689  TypeId = DIToIdMap[Ty];
690  return;
691  }
692 
693  // MapDef type may be a struct type or a non-pointer derived type
694  const DIType *OrigTy = Ty;
695  while (auto *DTy = dyn_cast<DIDerivedType>(Ty)) {
696  auto Tag = DTy->getTag();
697  if (Tag != dwarf::DW_TAG_typedef && Tag != dwarf::DW_TAG_const_type &&
698  Tag != dwarf::DW_TAG_volatile_type &&
699  Tag != dwarf::DW_TAG_restrict_type)
700  break;
701  Ty = DTy->getBaseType();
702  }
703 
704  const auto *CTy = dyn_cast<DICompositeType>(Ty);
705  if (!CTy)
706  return;
707 
708  auto Tag = CTy->getTag();
709  if (Tag != dwarf::DW_TAG_structure_type || CTy->isForwardDecl())
710  return;
711 
712  // Visit all struct members to ensure pointee type is visited
713  const DINodeArray Elements = CTy->getElements();
714  for (const auto *Element : Elements) {
715  const auto *MemberType = cast<DIDerivedType>(Element);
716  visitTypeEntry(MemberType->getBaseType());
717  }
718 
719  // Visit this type, struct or a const/typedef/volatile/restrict type
720  visitTypeEntry(OrigTy, TypeId, false, false);
721 }
722 
723 /// Read file contents from the actual file or from the source
724 std::string BTFDebug::populateFileContent(const DISubprogram *SP) {
725  auto File = SP->getFile();
726  std::string FileName;
727 
728  if (!File->getFilename().startswith("/") && File->getDirectory().size())
729  FileName = File->getDirectory().str() + "/" + File->getFilename().str();
730  else
731  FileName = std::string(File->getFilename());
732 
733  // No need to populate the contends if it has been populated!
734  if (FileContent.find(FileName) != FileContent.end())
735  return FileName;
736 
737  std::vector<std::string> Content;
738  std::string Line;
739  Content.push_back(Line); // Line 0 for empty string
740 
741  std::unique_ptr<MemoryBuffer> Buf;
742  auto Source = File->getSource();
743  if (Source)
745  else if (ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
746  MemoryBuffer::getFile(FileName))
747  Buf = std::move(*BufOrErr);
748  if (Buf)
749  for (line_iterator I(*Buf, false), E; I != E; ++I)
750  Content.push_back(std::string(*I));
751 
752  FileContent[FileName] = Content;
753  return FileName;
754 }
755 
756 void BTFDebug::constructLineInfo(const DISubprogram *SP, MCSymbol *Label,
757  uint32_t Line, uint32_t Column) {
758  std::string FileName = populateFileContent(SP);
759  BTFLineInfo LineInfo;
760 
761  LineInfo.Label = Label;
762  LineInfo.FileNameOff = addString(FileName);
763  // If file content is not available, let LineOff = 0.
764  if (Line < FileContent[FileName].size())
765  LineInfo.LineOff = addString(FileContent[FileName][Line]);
766  else
767  LineInfo.LineOff = 0;
768  LineInfo.LineNum = Line;
769  LineInfo.ColumnNum = Column;
770  LineInfoTable[SecNameOff].push_back(LineInfo);
771 }
772 
773 void BTFDebug::emitCommonHeader() {
775  OS.emitIntValue(BTF::MAGIC, 2);
777  OS.emitInt8(0);
778 }
779 
780 void BTFDebug::emitBTFSection() {
781  // Do not emit section if no types and only "" string.
782  if (!TypeEntries.size() && StringTable.getSize() == 1)
783  return;
784 
785  MCContext &Ctx = OS.getContext();
786  OS.SwitchSection(Ctx.getELFSection(".BTF", ELF::SHT_PROGBITS, 0));
787 
788  // Emit header.
789  emitCommonHeader();
791 
792  uint32_t TypeLen = 0, StrLen;
793  for (const auto &TypeEntry : TypeEntries)
794  TypeLen += TypeEntry->getSize();
795  StrLen = StringTable.getSize();
796 
797  OS.emitInt32(0);
798  OS.emitInt32(TypeLen);
799  OS.emitInt32(TypeLen);
800  OS.emitInt32(StrLen);
801 
802  // Emit type table.
803  for (const auto &TypeEntry : TypeEntries)
804  TypeEntry->emitType(OS);
805 
806  // Emit string table.
807  uint32_t StringOffset = 0;
808  for (const auto &S : StringTable.getTable()) {
809  OS.AddComment("string offset=" + std::to_string(StringOffset));
810  OS.emitBytes(S);
811  OS.emitBytes(StringRef("\0", 1));
812  StringOffset += S.size() + 1;
813  }
814 }
815 
816 void BTFDebug::emitBTFExtSection() {
817  // Do not emit section if empty FuncInfoTable and LineInfoTable
818  // and FieldRelocTable.
819  if (!FuncInfoTable.size() && !LineInfoTable.size() &&
820  !FieldRelocTable.size())
821  return;
822 
823  MCContext &Ctx = OS.getContext();
824  OS.SwitchSection(Ctx.getELFSection(".BTF.ext", ELF::SHT_PROGBITS, 0));
825 
826  // Emit header.
827  emitCommonHeader();
829 
830  // Account for FuncInfo/LineInfo record size as well.
831  uint32_t FuncLen = 4, LineLen = 4;
832  // Do not account for optional FieldReloc.
833  uint32_t FieldRelocLen = 0;
834  for (const auto &FuncSec : FuncInfoTable) {
835  FuncLen += BTF::SecFuncInfoSize;
836  FuncLen += FuncSec.second.size() * BTF::BPFFuncInfoSize;
837  }
838  for (const auto &LineSec : LineInfoTable) {
839  LineLen += BTF::SecLineInfoSize;
840  LineLen += LineSec.second.size() * BTF::BPFLineInfoSize;
841  }
842  for (const auto &FieldRelocSec : FieldRelocTable) {
843  FieldRelocLen += BTF::SecFieldRelocSize;
844  FieldRelocLen += FieldRelocSec.second.size() * BTF::BPFFieldRelocSize;
845  }
846 
847  if (FieldRelocLen)
848  FieldRelocLen += 4;
849 
850  OS.emitInt32(0);
851  OS.emitInt32(FuncLen);
852  OS.emitInt32(FuncLen);
853  OS.emitInt32(LineLen);
854  OS.emitInt32(FuncLen + LineLen);
855  OS.emitInt32(FieldRelocLen);
856 
857  // Emit func_info table.
858  OS.AddComment("FuncInfo");
860  for (const auto &FuncSec : FuncInfoTable) {
861  OS.AddComment("FuncInfo section string offset=" +
862  std::to_string(FuncSec.first));
863  OS.emitInt32(FuncSec.first);
864  OS.emitInt32(FuncSec.second.size());
865  for (const auto &FuncInfo : FuncSec.second) {
866  Asm->emitLabelReference(FuncInfo.Label, 4);
867  OS.emitInt32(FuncInfo.TypeId);
868  }
869  }
870 
871  // Emit line_info table.
872  OS.AddComment("LineInfo");
874  for (const auto &LineSec : LineInfoTable) {
875  OS.AddComment("LineInfo section string offset=" +
876  std::to_string(LineSec.first));
877  OS.emitInt32(LineSec.first);
878  OS.emitInt32(LineSec.second.size());
879  for (const auto &LineInfo : LineSec.second) {
880  Asm->emitLabelReference(LineInfo.Label, 4);
881  OS.emitInt32(LineInfo.FileNameOff);
882  OS.emitInt32(LineInfo.LineOff);
883  OS.AddComment("Line " + std::to_string(LineInfo.LineNum) + " Col " +
884  std::to_string(LineInfo.ColumnNum));
885  OS.emitInt32(LineInfo.LineNum << 10 | LineInfo.ColumnNum);
886  }
887  }
888 
889  // Emit field reloc table.
890  if (FieldRelocLen) {
891  OS.AddComment("FieldReloc");
893  for (const auto &FieldRelocSec : FieldRelocTable) {
894  OS.AddComment("Field reloc section string offset=" +
895  std::to_string(FieldRelocSec.first));
896  OS.emitInt32(FieldRelocSec.first);
897  OS.emitInt32(FieldRelocSec.second.size());
898  for (const auto &FieldRelocInfo : FieldRelocSec.second) {
899  Asm->emitLabelReference(FieldRelocInfo.Label, 4);
900  OS.emitInt32(FieldRelocInfo.TypeID);
901  OS.emitInt32(FieldRelocInfo.OffsetNameOff);
902  OS.emitInt32(FieldRelocInfo.RelocKind);
903  }
904  }
905  }
906 }
907 
909  auto *SP = MF->getFunction().getSubprogram();
910  auto *Unit = SP->getUnit();
911 
912  if (Unit->getEmissionKind() == DICompileUnit::NoDebug) {
913  SkipInstruction = true;
914  return;
915  }
916  SkipInstruction = false;
917 
918  // Collect MapDef types. Map definition needs to collect
919  // pointee types. Do it first. Otherwise, for the following
920  // case:
921  // struct m { ...};
922  // struct t {
923  // struct m *key;
924  // };
925  // foo(struct t *arg);
926  //
927  // struct mapdef {
928  // ...
929  // struct m *key;
930  // ...
931  // } __attribute__((section(".maps"))) hash_map;
932  //
933  // If subroutine foo is traversed first, a type chain
934  // "ptr->struct m(fwd)" will be created and later on
935  // when traversing mapdef, since "ptr->struct m" exists,
936  // the traversal of "struct m" will be omitted.
937  if (MapDefNotCollected) {
938  processGlobals(true);
939  MapDefNotCollected = false;
940  }
941 
942  // Collect all types locally referenced in this function.
943  // Use RetainedNodes so we can collect all argument names
944  // even if the argument is not used.
945  std::unordered_map<uint32_t, StringRef> FuncArgNames;
946  for (const DINode *DN : SP->getRetainedNodes()) {
947  if (const auto *DV = dyn_cast<DILocalVariable>(DN)) {
948  // Collect function arguments for subprogram func type.
949  uint32_t Arg = DV->getArg();
950  if (Arg) {
951  visitTypeEntry(DV->getType());
952  FuncArgNames[Arg] = DV->getName();
953  }
954  }
955  }
956 
957  // Construct subprogram func proto type.
958  uint32_t ProtoTypeId;
959  visitSubroutineType(SP->getType(), true, FuncArgNames, ProtoTypeId);
960 
961  // Construct subprogram func type
962  uint8_t Scope = SP->isLocalToUnit() ? BTF::FUNC_STATIC : BTF::FUNC_GLOBAL;
963  auto FuncTypeEntry =
964  std::make_unique<BTFTypeFunc>(SP->getName(), ProtoTypeId, Scope);
965  uint32_t FuncTypeId = addType(std::move(FuncTypeEntry));
966 
967  for (const auto &TypeEntry : TypeEntries)
968  TypeEntry->completeType(*this);
969 
970  // Construct funcinfo and the first lineinfo for the function.
971  MCSymbol *FuncLabel = Asm->getFunctionBegin();
972  BTFFuncInfo FuncInfo;
973  FuncInfo.Label = FuncLabel;
974  FuncInfo.TypeId = FuncTypeId;
975  if (FuncLabel->isInSection()) {
976  MCSection &Section = FuncLabel->getSection();
977  const MCSectionELF *SectionELF = dyn_cast<MCSectionELF>(&Section);
978  assert(SectionELF && "Null section for Function Label");
979  SecNameOff = addString(SectionELF->getName());
980  } else {
981  SecNameOff = addString(".text");
982  }
983  FuncInfoTable[SecNameOff].push_back(FuncInfo);
984 }
985 
987  SkipInstruction = false;
988  LineInfoGenerated = false;
989  SecNameOff = 0;
990 }
991 
992 /// On-demand populate types as requested from abstract member
993 /// accessing or preserve debuginfo type.
994 unsigned BTFDebug::populateType(const DIType *Ty) {
995  unsigned Id;
996  visitTypeEntry(Ty, Id, false, false);
997  for (const auto &TypeEntry : TypeEntries)
998  TypeEntry->completeType(*this);
999  return Id;
1000 }
1001 
1002 /// Generate a struct member field relocation.
1003 void BTFDebug::generatePatchImmReloc(const MCSymbol *ORSym, uint32_t RootId,
1004  const GlobalVariable *GVar, bool IsAma) {
1005  BTFFieldReloc FieldReloc;
1006  FieldReloc.Label = ORSym;
1007  FieldReloc.TypeID = RootId;
1008 
1009  StringRef AccessPattern = GVar->getName();
1010  size_t FirstDollar = AccessPattern.find_first_of('$');
1011  if (IsAma) {
1012  size_t FirstColon = AccessPattern.find_first_of(':');
1013  size_t SecondColon = AccessPattern.find_first_of(':', FirstColon + 1);
1014  StringRef IndexPattern = AccessPattern.substr(FirstDollar + 1);
1015  StringRef RelocKindStr = AccessPattern.substr(FirstColon + 1,
1016  SecondColon - FirstColon);
1017  StringRef PatchImmStr = AccessPattern.substr(SecondColon + 1,
1018  FirstDollar - SecondColon);
1019 
1020  FieldReloc.OffsetNameOff = addString(IndexPattern);
1021  FieldReloc.RelocKind = std::stoull(std::string(RelocKindStr));
1022  PatchImms[GVar] = std::make_pair(std::stoll(std::string(PatchImmStr)),
1023  FieldReloc.RelocKind);
1024  } else {
1025  StringRef RelocStr = AccessPattern.substr(FirstDollar + 1);
1026  FieldReloc.OffsetNameOff = addString("0");
1027  FieldReloc.RelocKind = std::stoull(std::string(RelocStr));
1028  PatchImms[GVar] = std::make_pair(RootId, FieldReloc.RelocKind);
1029  }
1030  FieldRelocTable[SecNameOff].push_back(FieldReloc);
1031 }
1032 
1033 void BTFDebug::processGlobalValue(const MachineOperand &MO) {
1034  // check whether this is a candidate or not
1035  if (MO.isGlobal()) {
1036  const GlobalValue *GVal = MO.getGlobal();
1037  auto *GVar = dyn_cast<GlobalVariable>(GVal);
1038  if (!GVar) {
1039  // Not a global variable. Maybe an extern function reference.
1040  processFuncPrototypes(dyn_cast<Function>(GVal));
1041  return;
1042  }
1043 
1046  return;
1047 
1048  MCSymbol *ORSym = OS.getContext().createTempSymbol();
1049  OS.emitLabel(ORSym);
1050 
1051  MDNode *MDN = GVar->getMetadata(LLVMContext::MD_preserve_access_index);
1052  uint32_t RootId = populateType(dyn_cast<DIType>(MDN));
1053  generatePatchImmReloc(ORSym, RootId, GVar,
1055  }
1056 }
1057 
1060 
1061  if (SkipInstruction || MI->isMetaInstruction() ||
1062  MI->getFlag(MachineInstr::FrameSetup))
1063  return;
1064 
1065  if (MI->isInlineAsm()) {
1066  // Count the number of register definitions to find the asm string.
1067  unsigned NumDefs = 0;
1068  for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
1069  ++NumDefs)
1070  ;
1071 
1072  // Skip this inline asm instruction if the asmstr is empty.
1073  const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
1074  if (AsmStr[0] == 0)
1075  return;
1076  }
1077 
1078  if (MI->getOpcode() == BPF::LD_imm64) {
1079  // If the insn is "r2 = LD_imm64 @<an AmaAttr global>",
1080  // add this insn into the .BTF.ext FieldReloc subsection.
1081  // Relocation looks like:
1082  // . SecName:
1083  // . InstOffset
1084  // . TypeID
1085  // . OffSetNameOff
1086  // . RelocType
1087  // Later, the insn is replaced with "r2 = <offset>"
1088  // where "<offset>" equals to the offset based on current
1089  // type definitions.
1090  //
1091  // If the insn is "r2 = LD_imm64 @<an TypeIdAttr global>",
1092  // The LD_imm64 result will be replaced with a btf type id.
1093  processGlobalValue(MI->getOperand(1));
1094  } else if (MI->getOpcode() == BPF::CORE_MEM ||
1095  MI->getOpcode() == BPF::CORE_ALU32_MEM ||
1096  MI->getOpcode() == BPF::CORE_SHIFT) {
1097  // relocation insn is a load, store or shift insn.
1098  processGlobalValue(MI->getOperand(3));
1099  } else if (MI->getOpcode() == BPF::JAL) {
1100  // check extern function references
1101  const MachineOperand &MO = MI->getOperand(0);
1102  if (MO.isGlobal()) {
1103  processFuncPrototypes(dyn_cast<Function>(MO.getGlobal()));
1104  }
1105  }
1106 
1107  if (!CurMI) // no debug info
1108  return;
1109 
1110  // Skip this instruction if no DebugLoc or the DebugLoc
1111  // is the same as the previous instruction.
1112  const DebugLoc &DL = MI->getDebugLoc();
1113  if (!DL || PrevInstLoc == DL) {
1114  // This instruction will be skipped, no LineInfo has
1115  // been generated, construct one based on function signature.
1116  if (LineInfoGenerated == false) {
1117  auto *S = MI->getMF()->getFunction().getSubprogram();
1118  MCSymbol *FuncLabel = Asm->getFunctionBegin();
1119  constructLineInfo(S, FuncLabel, S->getLine(), 0);
1120  LineInfoGenerated = true;
1121  }
1122 
1123  return;
1124  }
1125 
1126  // Create a temporary label to remember the insn for lineinfo.
1127  MCSymbol *LineSym = OS.getContext().createTempSymbol();
1128  OS.emitLabel(LineSym);
1129 
1130  // Construct the lineinfo.
1131  auto SP = DL.get()->getScope()->getSubprogram();
1132  constructLineInfo(SP, LineSym, DL.getLine(), DL.getCol());
1133 
1134  LineInfoGenerated = true;
1135  PrevInstLoc = DL;
1136 }
1137 
1138 void BTFDebug::processGlobals(bool ProcessingMapDef) {
1139  // Collect all types referenced by globals.
1140  const Module *M = MMI->getModule();
1141  for (const GlobalVariable &Global : M->globals()) {
1142  // Decide the section name.
1143  StringRef SecName;
1144  if (Global.hasSection()) {
1145  SecName = Global.getSection();
1146  } else if (Global.hasInitializer()) {
1147  // data, bss, or readonly sections
1148  if (Global.isConstant())
1149  SecName = ".rodata";
1150  else
1151  SecName = Global.getInitializer()->isZeroValue() ? ".bss" : ".data";
1152  }
1153 
1154  if (ProcessingMapDef != SecName.startswith(".maps"))
1155  continue;
1156 
1157  // Create a .rodata datasec if the global variable is an initialized
1158  // constant with private linkage and if it won't be in .rodata.str<#>
1159  // and .rodata.cst<#> sections.
1160  if (SecName == ".rodata" && Global.hasPrivateLinkage() &&
1161  DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
1162  SectionKind GVKind =
1164  // skip .rodata.str<#> and .rodata.cst<#> sections
1165  if (!GVKind.isMergeableCString() && !GVKind.isMergeableConst()) {
1166  DataSecEntries[std::string(SecName)] =
1167  std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
1168  }
1169  }
1170 
1172  Global.getDebugInfo(GVs);
1173 
1174  // No type information, mostly internal, skip it.
1175  if (GVs.size() == 0)
1176  continue;
1177 
1178  uint32_t GVTypeId = 0;
1179  for (auto *GVE : GVs) {
1180  if (SecName.startswith(".maps"))
1181  visitMapDefType(GVE->getVariable()->getType(), GVTypeId);
1182  else
1183  visitTypeEntry(GVE->getVariable()->getType(), GVTypeId, false, false);
1184  break;
1185  }
1186 
1187  // Only support the following globals:
1188  // . static variables
1189  // . non-static weak or non-weak global variables
1190  // . weak or non-weak extern global variables
1191  // Whether DataSec is readonly or not can be found from corresponding ELF
1192  // section flags. Whether a BTF_KIND_VAR is a weak symbol or not
1193  // can be found from the corresponding ELF symbol table.
1194  auto Linkage = Global.getLinkage();
1200  continue;
1201 
1202  uint32_t GVarInfo;
1204  GVarInfo = BTF::VAR_STATIC;
1205  } else if (Global.hasInitializer()) {
1206  GVarInfo = BTF::VAR_GLOBAL_ALLOCATED;
1207  } else {
1208  GVarInfo = BTF::VAR_GLOBAL_EXTERNAL;
1209  }
1210 
1211  auto VarEntry =
1212  std::make_unique<BTFKindVar>(Global.getName(), GVTypeId, GVarInfo);
1213  uint32_t VarId = addType(std::move(VarEntry));
1214 
1215  // An empty SecName means an extern variable without section attribute.
1216  if (SecName.empty())
1217  continue;
1218 
1219  // Find or create a DataSec
1220  if (DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
1221  DataSecEntries[std::string(SecName)] =
1222  std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
1223  }
1224 
1225  // Calculate symbol size
1226  const DataLayout &DL = Global.getParent()->getDataLayout();
1227  uint32_t Size = DL.getTypeAllocSize(Global.getType()->getElementType());
1228 
1229  DataSecEntries[std::string(SecName)]->addDataSecEntry(VarId,
1230  Asm->getSymbol(&Global), Size);
1231  }
1232 }
1233 
1234 /// Emit proper patchable instructions.
1236  if (MI->getOpcode() == BPF::LD_imm64) {
1237  const MachineOperand &MO = MI->getOperand(1);
1238  if (MO.isGlobal()) {
1239  const GlobalValue *GVal = MO.getGlobal();
1240  auto *GVar = dyn_cast<GlobalVariable>(GVal);
1241  if (GVar) {
1242  // Emit "mov ri, <imm>"
1243  int64_t Imm;
1244  uint32_t Reloc;
1247  Imm = PatchImms[GVar].first;
1248  Reloc = PatchImms[GVar].second;
1249  } else {
1250  return false;
1251  }
1252 
1254  Reloc == BPFCoreSharedInfo::ENUM_VALUE ||
1257  OutMI.setOpcode(BPF::LD_imm64);
1258  else
1259  OutMI.setOpcode(BPF::MOV_ri);
1260  OutMI.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1261  OutMI.addOperand(MCOperand::createImm(Imm));
1262  return true;
1263  }
1264  }
1265  } else if (MI->getOpcode() == BPF::CORE_MEM ||
1266  MI->getOpcode() == BPF::CORE_ALU32_MEM ||
1267  MI->getOpcode() == BPF::CORE_SHIFT) {
1268  const MachineOperand &MO = MI->getOperand(3);
1269  if (MO.isGlobal()) {
1270  const GlobalValue *GVal = MO.getGlobal();
1271  auto *GVar = dyn_cast<GlobalVariable>(GVal);
1272  if (GVar && GVar->hasAttribute(BPFCoreSharedInfo::AmaAttr)) {
1273  uint32_t Imm = PatchImms[GVar].first;
1274  OutMI.setOpcode(MI->getOperand(1).getImm());
1275  if (MI->getOperand(0).isImm())
1276  OutMI.addOperand(MCOperand::createImm(MI->getOperand(0).getImm()));
1277  else
1278  OutMI.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1279  OutMI.addOperand(MCOperand::createReg(MI->getOperand(2).getReg()));
1280  OutMI.addOperand(MCOperand::createImm(Imm));
1281  return true;
1282  }
1283  }
1284  }
1285  return false;
1286 }
1287 
1288 void BTFDebug::processFuncPrototypes(const Function *F) {
1289  if (!F)
1290  return;
1291 
1292  const DISubprogram *SP = F->getSubprogram();
1293  if (!SP || SP->isDefinition())
1294  return;
1295 
1296  // Do not emit again if already emitted.
1297  if (ProtoFunctions.find(F) != ProtoFunctions.end())
1298  return;
1299  ProtoFunctions.insert(F);
1300 
1301  uint32_t ProtoTypeId;
1302  const std::unordered_map<uint32_t, StringRef> FuncArgNames;
1303  visitSubroutineType(SP->getType(), false, FuncArgNames, ProtoTypeId);
1304 
1305  uint8_t Scope = BTF::FUNC_EXTERN;
1306  auto FuncTypeEntry =
1307  std::make_unique<BTFTypeFunc>(SP->getName(), ProtoTypeId, Scope);
1308  uint32_t FuncId = addType(std::move(FuncTypeEntry));
1309  if (F->hasSection()) {
1310  StringRef SecName = F->getSection();
1311 
1312  if (DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) {
1313  DataSecEntries[std::string(SecName)] =
1314  std::make_unique<BTFKindDataSec>(Asm, std::string(SecName));
1315  }
1316 
1317  // We really don't know func size, set it to 0.
1318  DataSecEntries[std::string(SecName)]->addDataSecEntry(FuncId,
1319  Asm->getSymbol(F), 0);
1320  }
1321 }
1322 
1324  // Collect MapDef globals if not collected yet.
1325  if (MapDefNotCollected) {
1326  processGlobals(true);
1327  MapDefNotCollected = false;
1328  }
1329 
1330  // Collect global types/variables except MapDef globals.
1331  processGlobals(false);
1332 
1333  for (auto &DataSec : DataSecEntries)
1334  addType(std::move(DataSec.second));
1335 
1336  // Fixups
1337  for (auto &Fixup : FixupDerivedTypes) {
1338  StringRef TypeName = Fixup.first;
1339  bool IsUnion = Fixup.second.first;
1340 
1341  // Search through struct types
1342  uint32_t StructTypeId = 0;
1343  for (const auto &StructType : StructTypes) {
1344  if (StructType->getName() == TypeName) {
1345  StructTypeId = StructType->getId();
1346  break;
1347  }
1348  }
1349 
1350  if (StructTypeId == 0) {
1351  auto FwdTypeEntry = std::make_unique<BTFTypeFwd>(TypeName, IsUnion);
1352  StructTypeId = addType(std::move(FwdTypeEntry));
1353  }
1354 
1355  for (auto &DType : Fixup.second.second) {
1356  DType->setPointeeType(StructTypeId);
1357  }
1358  }
1359 
1360  // Complete BTF type cross refereences.
1361  for (const auto &TypeEntry : TypeEntries)
1362  TypeEntry->completeType(*this);
1363 
1364  // Emit BTF sections.
1365  emitBTFSection();
1366  emitBTFExtSection();
1367 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
BPFMCTargetDesc.h
llvm::BTFTypeFloat::completeType
void completeType(BTFDebug &BDebug) override
Complete BTF type generation after all related DebugInfo types have been visited so their BTF type id...
Definition: BTFDebug.cpp:381
AsmPrinter.h
llvm::BTFFieldReloc::OffsetNameOff
uint32_t OffsetNameOff
The string to traverse types.
Definition: BTFDebug.h:246
llvm::StringRef::startswith
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:286
llvm::BTF::BTFMember
BTF_KIND_STRUCT and BTF_KIND_UNION are followed by multiple "struct BTFMember".
Definition: BTF.h:165
llvm::DICompositeType::getBaseType
DIType * getBaseType() const
Definition: DebugInfoMetadata.h:1180
llvm::DebugHandlerBase::beginInstruction
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
Definition: DebugHandlerBase.cpp:342
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:102
llvm::BTFTypeDerived::setPointeeType
void setPointeeType(uint32_t PointeeType)
Definition: BTFDebug.cpp:93
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::DIType
Base class for types.
Definition: DebugInfoMetadata.h:662
llvm::BTF::FUNC_GLOBAL
@ FUNC_GLOBAL
Definition: BTF.h:182
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
llvm::StructType::getName
StringRef getName() const
Return the name for this struct type if it has an identity.
Definition: Type.cpp:547
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
llvm::BTFFuncInfo::Label
const MCSymbol * Label
Func MCSymbol.
Definition: BTFDebug.h:229
llvm::BTF::BTFEnum
BTF_KIND_ENUM is followed by multiple "struct BTFEnum".
Definition: BTF.h:143
llvm::DIType::getSizeInBits
uint64_t getSizeInBits() const
Definition: DebugInfoMetadata.h:701
llvm::line_iterator
A forward iterator which reads text lines from a buffer.
Definition: LineIterator.h:33
llvm::MachineOperand::getGlobal
const GlobalValue * getGlobal() const
Definition: MachineOperand.h:563
llvm::BTFLineInfo
Represent one line info.
Definition: BTFDebug.h:234
llvm::BTFDebug::InstLower
bool InstLower(const MachineInstr *MI, MCInst &OutMI)
Emit proper patchable instructions.
Definition: BTFDebug.cpp:1235
llvm::MCOperand::createImm
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:141
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::Function
Definition: Function.h:61
llvm::BTFKindDataSec::emitType
void emitType(MCStreamer &OS) override
Emit types for this BTF type entry.
Definition: BTFDebug.cpp:364
llvm::BTFLineInfo::FileNameOff
uint32_t FileNameOff
file name offset in the .BTF string table
Definition: BTFDebug.h:236
llvm::BTFTypeBase::Kind
uint8_t Kind
Definition: BTFDebug.h:41
llvm::BTFTypeEnum::completeType
void completeType(BTFDebug &BDebug) override
Complete BTF type generation after all related DebugInfo types have been visited so their BTF type id...
Definition: BTFDebug.cpp:161
MCSectionELF.h
llvm::MCStreamer::emitInt8
void emitInt8(uint64_t Value)
Definition: MCStreamer.h:703
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::BTFFieldReloc::Label
const MCSymbol * Label
MCSymbol identifying insn for the reloc.
Definition: BTFDebug.h:244
llvm::BTFFieldReloc::TypeID
uint32_t TypeID
Type ID.
Definition: BTFDebug.h:245
llvm::Function::getSubprogram
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1532
llvm::BPFCoreSharedInfo::BTF_TYPE_ID_LOCAL
@ BTF_TYPE_ID_LOCAL
Definition: BPFCORE.h:29
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::GlobalObject::getMetadata
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Metadata.cpp:1197
llvm::BTFKindVar::completeType
void completeType(BTFDebug &BDebug) override
Complete BTF type generation after all related DebugInfo types have been visited so their BTF type id...
Definition: BTFDebug.cpp:343
llvm::BTF::VAR_GLOBAL_EXTERNAL
@ VAR_GLOBAL_EXTERNAL
Linkage: ExternalLinkage.
Definition: BTF.h:190
Content
T Content
Definition: ELFObjHandler.cpp:90
llvm::DIScope::getName
StringRef getName() const
Definition: DebugInfoMetadata.cpp:261
llvm::tgtok::VarName
@ VarName
Definition: TGLexer.h:71
llvm::DebugHandlerBase::PrevInstLoc
DebugLoc PrevInstLoc
Previous instruction's location information.
Definition: DebugHandlerBase.h:67
MCObjectFileInfo.h
llvm::StringMap::end
iterator end()
Definition: StringMap.h:205
llvm::BTFKindDataSec::BTFKindDataSec
BTFKindDataSec(AsmPrinter *AsmPrt, std::string SecName)
Definition: BTFDebug.cpp:352
llvm::MCStreamer::emitInt32
void emitInt32(uint64_t Value)
Definition: MCStreamer.h:705
llvm::BTF::FUNC_STATIC
@ FUNC_STATIC
Definition: BTF.h:181
llvm::SectionKind::isMergeableConst
bool isMergeableConst() const
Definition: SectionKind.h:138
llvm::BTF::BTFMember::Type
uint32_t Type
Member type.
Definition: BTF.h:167
llvm::GlobalVariable::hasAttribute
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists.
Definition: GlobalVariable.h:198
llvm::BTFStringTable::getTable
std::vector< std::string > & getTable()
Definition: BTFDebug.h:221
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::BTF::MAGIC
@ MAGIC
Definition: BTF.h:54
llvm::AsmPrinter::emitLabelReference
void emitLabelReference(const MCSymbol *Label, unsigned Size, bool IsSectionRelative=false) const
Emit something like ".long Label" where the size in bytes of the directive is specified by Size and L...
Definition: AsmPrinter.h:596
llvm::BTFDebug::BTFDebug
BTFDebug(AsmPrinter *AP)
Definition: BTFDebug.cpp:403
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::MCSectionELF
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:28
llvm::StringMap::find
iterator find(StringRef Key)
Definition: StringMap.h:218
BPF.h
llvm::BTFTypeDerived::completeType
void completeType(BTFDebug &BDebug) override
Complete BTF type generation after all related DebugInfo types have been visited so their BTF type id...
Definition: BTFDebug.cpp:69
llvm::BTFTypeArray::emitType
void emitType(MCStreamer &OS) override
Emit types for this BTF type entry.
Definition: BTFDebug.cpp:216
llvm::dwarf::Tag
Tag
Definition: Dwarf.h:104
llvm::BTFTypeFuncProto::completeType
void completeType(BTFDebug &BDebug) override
Complete BTF type generation after all related DebugInfo types have been visited so their BTF type id...
Definition: BTFDebug.cpp:283
llvm::BTFDebug::getTypeId
uint32_t getTypeId(const DIType *Ty)
Get the type id for a particular DIType.
Definition: BTFDebug.h:359
BTFKindStr
static const char * BTFKindStr[]
Definition: BTFDebug.cpp:29
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MCInst::setOpcode
void setOpcode(unsigned Op)
Definition: MCInst.h:197
llvm::BTF::MAX_VLEN
@ MAX_VLEN
Max # of struct/union/enum members or func args.
Definition: BTF.h:89
llvm::ELF::SHT_PROGBITS
@ SHT_PROGBITS
Definition: ELF.h:910
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
llvm::StringRef::substr
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:611
llvm::BTFTypeFloat::BTFTypeFloat
BTFTypeFloat(uint32_t SizeInBits, StringRef TypeName)
Definition: BTFDebug.cpp:374
llvm::DITypeRefArray
Definition: DebugInfoMetadata.h:67
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
llvm::BTFTypeDerived::BTFTypeDerived
BTFTypeDerived(const DIDerivedType *Ty, unsigned Tag, bool NeedsFixup)
Definition: BTFDebug.cpp:44
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:197
llvm::BTF::BTFArray::Nelems
uint32_t Nelems
Number of elements for this array.
Definition: BTF.h:152
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
llvm::MemoryBuffer::getFile
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
Definition: MemoryBuffer.cpp:246
ELF.h
llvm::MCSymbol::getSection
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:262
llvm::DISubrange::getCount
BoundType getCount() const
Definition: DebugInfoMetadata.cpp:369
llvm::BTFLineInfo::ColumnNum
uint32_t ColumnNum
the column number
Definition: BTFDebug.h:239
llvm::BTF::VERSION
@ VERSION
Definition: BTF.h:54
llvm::DebugHandlerBase::Asm
AsmPrinter * Asm
Target of debug info emission.
Definition: DebugHandlerBase.h:58
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::BTFStringTable::addString
uint32_t addString(StringRef S)
Add a string to the string table and returns its offset in the table.
Definition: BTFDebug.cpp:389
llvm::BTFTypeStruct::completeType
void completeType(BTFDebug &BDebug) override
Complete BTF type generation after all related DebugInfo types have been visited so their BTF type id...
Definition: BTFDebug.cpp:232
MCContext.h
llvm::MCStreamer::emitLabel
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:413
llvm::BTF::INT_SIGNED
@ INT_SIGNED
Definition: BTF.h:135
Param
Value * Param
Definition: NVPTXLowerArgs.cpp:163
llvm::DIType::getName
StringRef getName() const
Definition: DebugInfoMetadata.h:708
llvm::MCContext::getELFSection
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:540
llvm::DISubrange
Array subrange.
Definition: DebugInfoMetadata.h:296
false
Definition: StackSlotColoring.cpp:142
llvm::BTFTypeBase::BTFType
struct BTF::CommonType BTFType
Definition: BTFDebug.h:44
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::DIBasicType::getEncoding
unsigned getEncoding() const
Definition: DebugInfoMetadata.h:823
llvm::MachineInstr::FrameSetup
@ FrameSetup
Definition: MachineInstr.h:82
LineIterator.h
llvm::BTF::BTFMember::Offset
uint32_t Offset
BitOffset or BitFieldSize+BitOffset.
Definition: BTF.h:168
llvm::BTFTypeInt::emitType
void emitType(MCStreamer &OS) override
Emit types for this BTF type entry.
Definition: BTFDebug.cpp:149
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
llvm::GlobalValue::InternalLinkage
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:55
llvm::BTF::BPFFieldRelocSize
@ BPFFieldRelocSize
Definition: BTF.h:71
llvm::BTFDebug::addString
size_t addString(StringRef S)
Add string to the string table.
Definition: BTFDebug.h:356
llvm::TargetLoweringObjectFile::getKindForGlobal
static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM)
Classify the specified global variable into a set of target independent categories embodied in Sectio...
Definition: TargetLoweringObjectFile.cpp:202
llvm::AsmPrinter::getFunctionBegin
MCSymbol * getFunctionBegin() const
Definition: AsmPrinter.h:247
llvm::BTFTypeFwd::BTFTypeFwd
BTFTypeFwd(StringRef Name, bool IsUnion)
Represent a struct/union forward declaration.
Definition: BTFDebug.cpp:98
llvm::BTF::ExtHeaderSize
@ ExtHeaderSize
Definition: BTF.h:59
llvm::BTF::INT_BOOL
@ INT_BOOL
Definition: BTF.h:137
llvm::MCInst::addOperand
void addOperand(const MCOperand Op)
Definition: MCInst.h:210
llvm::BPFCoreSharedInfo::BTF_TYPE_ID_REMOTE
@ BTF_TYPE_ID_REMOTE
Definition: BPFCORE.h:30
llvm::BTFDebug
Collect and emit BTF information.
Definition: BTFDebug.h:251
llvm::BTF::BTFMember::NameOff
uint32_t NameOff
Member name offset in the string table.
Definition: BTF.h:166
llvm::BTFTypeFunc::completeType
void completeType(BTFDebug &BDebug) override
Complete BTF type generation after all related DebugInfo types have been visited so their BTF type id...
Definition: BTFDebug.cpp:325
llvm::BTFFuncInfo
Represent one func and its type id.
Definition: BTFDebug.h:228
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::BTF::FUNC_EXTERN
@ FUNC_EXTERN
Definition: BTF.h:183
llvm::Twine::utohexstr
static Twine utohexstr(const uint64_t &Val)
Definition: Twine.h:408
llvm::DICompositeType::getElements
DINodeArray getElements() const
Definition: DebugInfoMetadata.h:1181
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::BPFCoreSharedInfo::ENUM_VALUE
@ ENUM_VALUE
Definition: BPFCORE.h:34
llvm::BTF::VAR_STATIC
@ VAR_STATIC
Linkage: InternalLinkage.
Definition: BTF.h:188
llvm::BTFLineInfo::LineNum
uint32_t LineNum
the line number
Definition: BTFDebug.h:238
llvm::GlobalValue::WeakAnyLinkage
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition: GlobalValue.h:52
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::BTF::SecLineInfoSize
@ SecLineInfoSize
Definition: BTF.h:67
FuncId
Profile::FuncID FuncId
Definition: Profile.cpp:321
llvm::SectionKind::isMergeableCString
bool isMergeableCString() const
Definition: SectionKind.h:130
BTFDebug.h
llvm::BTF::BTFParam
BTF_KIND_FUNC_PROTO are followed by multiple "struct BTFParam".
Definition: BTF.h:174
llvm::BTF::BTFArray::IndexType
uint32_t IndexType
Index type.
Definition: BTF.h:151
llvm::BTFStringTable::getSize
uint32_t getSize()
Definition: BTFDebug.h:220
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AsmPrinter::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:492
llvm::MCStreamer::emitIntValue
virtual void emitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
Definition: MCStreamer.cpp:131
llvm::BTFLineInfo::Label
MCSymbol * Label
MCSymbol identifying insn for the lineinfo.
Definition: BTFDebug.h:235
llvm::BPFCoreSharedInfo::TypeIdAttr
static constexpr StringRef TypeIdAttr
The attribute attached to globals representing a type id.
Definition: BPFCORE.h:63
MachineModuleInfo.h
llvm::BTFTypeEnum::emitType
void emitType(MCStreamer &OS) override
Emit types for this BTF type entry.
Definition: BTFDebug.cpp:185
llvm::BTFTypeStruct::emitType
void emitType(MCStreamer &OS) override
Emit types for this BTF type entry.
Definition: BTFDebug.cpp:258
llvm::BTFTypeFuncProto::BTFTypeFuncProto
BTFTypeFuncProto(const DISubroutineType *STy, uint32_t NumParams, const std::unordered_map< uint32_t, StringRef > &FuncArgNames)
The Func kind represents both subprogram and pointee of function pointers.
Definition: BTFDebug.cpp:275
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MDNode
Metadata node.
Definition: Metadata.h:897
llvm::BTFTypeStruct::BTFTypeStruct
BTFTypeStruct(const DICompositeType *STy, bool IsStruct, bool HasBitField, uint32_t NumMembers)
Represent either a struct or a union.
Definition: BTFDebug.cpp:224
llvm::BTFDebug::endFunctionImpl
void endFunctionImpl(const MachineFunction *MF) override
Post process after all instructions in this function are processed.
Definition: BTFDebug.cpp:986
llvm::DebugHandlerBase::CurMI
const MachineInstr * CurMI
If nonnull, stores the current machine instruction we're processing.
Definition: DebugHandlerBase.h:76
isReg
static bool isReg(const MCInst &MI, unsigned OpNo)
Definition: MipsInstPrinter.cpp:31
llvm::DIBasicType
Basic type, like 'int' or 'float'.
Definition: DebugInfoMetadata.h:769
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::DINode::getTag
dwarf::Tag getTag() const
Definition: DebugInfoMetadata.h:160
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1528
llvm::BTFTypeInt::BTFTypeInt
BTFTypeInt(uint32_t Encoding, uint32_t SizeInBits, uint32_t OffsetInBits, StringRef TypeName)
Definition: BTFDebug.cpp:114
llvm::DISubroutineType
Type array for a subprogram.
Definition: DebugInfoMetadata.h:1263
llvm::DICompositeType
Composite types.
Definition: DebugInfoMetadata.h:1051
llvm::DICompileUnit::NoDebug
@ NoDebug
Definition: DebugInfoMetadata.h:1323
llvm::Sched::Source
@ Source
Definition: TargetLowering.h:99
llvm::BTFFieldReloc
Represent one field relocation.
Definition: BTFDebug.h:243
llvm::StructType
Class to represent struct types.
Definition: DerivedTypes.h:212
Fixup
PowerPC TLS Dynamic Call Fixup
Definition: PPCTLSDynamicCall.cpp:235
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::DINode
Tagged DWARF-like metadata node.
Definition: DebugInfoMetadata.h:127
llvm::BTFTypeFuncProto::emitType
void emitType(MCStreamer &OS) override
Emit types for this BTF type entry.
Definition: BTFDebug.cpp:309
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::MCOperand::createReg
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:134
TargetLoweringObjectFile.h
llvm::GlobalValue::WeakODRLinkage
@ WeakODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:53
uint32_t
llvm::BTFDebug::getArrayIndexTypeId
uint32_t getArrayIndexTypeId()
Get the special array index type id.
Definition: BTFDebug.h:350
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::ConstantInt::getSExtValue
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
Definition: Constants.h:148
llvm::BPFCoreSharedInfo::ENUM_VALUE_EXISTENCE
@ ENUM_VALUE_EXISTENCE
Definition: BPFCORE.h:33
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:297
llvm::MCContext::createTempSymbol
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:303
llvm::BTF::BTFEnum::Val
int32_t Val
Enum member value.
Definition: BTF.h:145
llvm::BTF::BTFArray::ElemType
uint32_t ElemType
Element type.
Definition: BTF.h:150
llvm::BTF::BTFEnum::NameOff
uint32_t NameOff
Enum name offset in the string table.
Definition: BTF.h:144
llvm::MCSection::getName
StringRef getName() const
Definition: MCSection.h:122
llvm::DIType::isForwardDecl
bool isForwardDecl() const
Definition: DebugInfoMetadata.h:730
llvm::BTFTypeStruct::getName
std::string getName()
Definition: BTFDebug.cpp:268
llvm::DITypeRefArray::size
unsigned size() const
Definition: DebugInfoMetadata.h:82
llvm::DIType::getOffsetInBits
uint64_t getOffsetInBits() const
Definition: DebugInfoMetadata.h:704
llvm::BTF::BPFLineInfoSize
@ BPFLineInfoSize
Definition: BTF.h:70
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
llvm::pdb::PDB_SymType::Label
@ Label
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::BTF::CommonType::Info
uint32_t Info
"Info" bits arrangement: Bits 0-15: vlen (e.g.
Definition: BTF.h:110
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:588
llvm::BTFFuncInfo::TypeId
uint32_t TypeId
Type id referring to .BTF type section.
Definition: BTFDebug.h:230
llvm::BTFDebug::beginFunctionImpl
void beginFunctionImpl(const MachineFunction *MF) override
Gather pre-function debug information.
Definition: BTFDebug.cpp:908
llvm::BTFTypeBase::Id
uint32_t Id
Definition: BTFDebug.h:43
llvm::AMDGPU::HSAMD::Kernel::Arg::Key::TypeName
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
Definition: AMDGPUMetadata.h:170
llvm::BTFTypeArray::completeType
void completeType(BTFDebug &BDebug) override
Represent a BTF array.
Definition: BTFDebug.cpp:204
llvm::BTFTypeBase::emitType
virtual void emitType(MCStreamer &OS)
Emit types for this BTF type entry.
Definition: BTFDebug.cpp:35
llvm::DISubroutineType::getTypeArray
DITypeRefArray getTypeArray() const
Definition: DebugInfoMetadata.h:1305
llvm::BTFKindVar::emitType
void emitType(MCStreamer &OS) override
Emit types for this BTF type entry.
Definition: BTFDebug.cpp:347
llvm::BTFTypeFunc::emitType
void emitType(MCStreamer &OS) override
Emit types for this BTF type entry.
Definition: BTFDebug.cpp:333
BPFCORE.h
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:82
llvm::DIDerivedType
Derived types.
Definition: DebugInfoMetadata.h:917
llvm::BTF::BPFFuncInfoSize
@ BPFFuncInfoSize
Definition: BTF.h:69
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
llvm::BPFCoreSharedInfo::AmaAttr
static constexpr StringRef AmaAttr
The attribute attached to globals representing a field access.
Definition: BPFCORE.h:61
llvm::BTF::CommonType::NameOff
uint32_t NameOff
Type name offset in the string table.
Definition: BTF.h:101
llvm::BTF::VAR_GLOBAL_ALLOCATED
@ VAR_GLOBAL_ALLOCATED
Linkage: ExternalLinkage.
Definition: BTF.h:189
llvm::BTFTypeEnum::BTFTypeEnum
BTFTypeEnum(const DICompositeType *ETy, uint32_t NumValues)
Definition: BTFDebug.cpp:155
llvm::BTFFieldReloc::RelocKind
uint32_t RelocKind
What to patch the instruction.
Definition: BTFDebug.h:247
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:278
llvm::AsmPrinter::TM
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:85
N
#define N
MCStreamer.h
llvm::MCSymbol::isInSection
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
Definition: MCSymbol.h:247
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
llvm::to_string
std::string to_string(const T &Value)
Definition: ScopedPrinter.h:63
llvm::BTF::HeaderSize
@ HeaderSize
Definition: BTF.h:58
llvm::BTFTypeFunc::BTFTypeFunc
BTFTypeFunc(StringRef FuncName, uint32_t ProtoTypeId, uint32_t Scope)
Definition: BTFDebug.cpp:317
llvm::pdb::PDB_DataKind::Global
@ Global
llvm::DebugHandlerBase::MMI
MachineModuleInfo * MMI
Collected machine module information.
Definition: DebugHandlerBase.h:61
llvm::DebugHandlerBase
Base class for debug information backends.
Definition: DebugHandlerBase.h:53
llvm::MCStreamer::emitBytes
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:1187
llvm::DISubprogram
Subprogram description.
Definition: DebugInfoMetadata.h:1802
llvm::BTF::SecFuncInfoSize
@ SecFuncInfoSize
Definition: BTF.h:66
llvm::BTF::CommonType::Type
uint32_t Type
Definition: BTF.h:120
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::BTFLineInfo::LineOff
uint32_t LineOff
line offset in the .BTF string table
Definition: BTFDebug.h:237
llvm::StringRef::find_first_of
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
Definition: StringRef.h:410
llvm::BTFTypeInt::completeType
void completeType(BTFDebug &BDebug) override
Complete BTF type generation after all related DebugInfo types have been visited so their BTF type id...
Definition: BTFDebug.cpp:141
llvm::BTFTypeBase::IsCompleted
bool IsCompleted
Definition: BTFDebug.h:42
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::BTFTypeArray::BTFTypeArray
BTFTypeArray(uint32_t ElemTypeId, uint32_t NumElems)
Definition: BTFDebug.cpp:193
llvm::GlobalValue::ExternalWeakLinkage
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition: GlobalValue.h:57
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:221
llvm::MemoryBuffer::getMemBufferCopy
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
Definition: MemoryBuffer.cpp:136
llvm::BTF::SecFieldRelocSize
@ SecFieldRelocSize
Definition: BTF.h:68
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
llvm::MCStreamer::SwitchSection
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:1209
llvm::MachineModuleInfo::getModule
const Module * getModule() const
Definition: MachineModuleInfo.h:174
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::BTF::CommonType::Size
uint32_t Size
Definition: BTF.h:119
llvm::BTFKindDataSec::completeType
void completeType(BTFDebug &BDebug) override
Complete BTF type generation after all related DebugInfo types have been visited so their BTF type id...
Definition: BTFDebug.cpp:359
llvm::BTFTypeFwd::completeType
void completeType(BTFDebug &BDebug) override
Complete BTF type generation after all related DebugInfo types have been visited so their BTF type id...
Definition: BTFDebug.cpp:104
File
Instrumentation for Order File
Definition: InstrOrderFile.cpp:206
llvm::BTFDebug::endModule
void endModule() override
Complete all the types and emit the BTF sections.
Definition: BTFDebug.cpp:1323
llvm::MCStreamer::AddComment
virtual void AddComment(const Twine &T, bool EOL=true)
Add a textual comment.
Definition: MCStreamer.h:340
llvm::BTFKindVar::BTFKindVar
BTFKindVar(StringRef VarName, uint32_t TypeId, uint32_t VarInfo)
Definition: BTFDebug.cpp:335
llvm::BTFTypeDerived::emitType
void emitType(MCStreamer &OS) override
Emit types for this BTF type entry.
Definition: BTFDebug.cpp:91
llvm::BTFDebug::beginInstruction
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
Definition: BTFDebug.cpp:1058
llvm::BTFTypeFwd::emitType
void emitType(MCStreamer &OS) override
Emit types for this BTF type entry.
Definition: BTFDebug.cpp:112
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58
llvm::DIScope::getFile
DIFile * getFile() const
Definition: DebugInfoMetadata.h:484
llvm::MachineOperand::isGlobal
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
Definition: MachineOperand.h:339
llvm::BTFTypeBase::roundupToBytes
uint32_t roundupToBytes(uint32_t NumBits)
Definition: BTFDebug.h:51