xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Support/ELFAttributes.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===-- ELFAttributes.h - ELF Attributes ------------------------*- C++ -*-===//
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 #ifndef LLVM_SUPPORT_ELFATTRIBUTES_H
10 #define LLVM_SUPPORT_ELFATTRIBUTES_H
11 
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/Compiler.h"
15 #include <optional>
16 
17 namespace llvm {
18 
19 // Tag to string: ELF compact build attribute section
20 struct TagNameItem {
21   unsigned attr;
22   StringRef tagName;
23 };
24 
25 using TagNameMap = ArrayRef<TagNameItem>;
26 
27 // Build Attribute storage for ELF extended attribute section
28 struct BuildAttributeItem {
29   enum Types : uint8_t {
30     NumericAttribute = 0,
31     TextAttribute,
32   } Type;
33   unsigned Tag;
34   unsigned IntValue;
35   std::string StringValue;
BuildAttributeItemBuildAttributeItem36   BuildAttributeItem(Types Ty, unsigned Tg, unsigned IV, std::string SV)
37       : Type(Ty), Tag(Tg), IntValue(IV), StringValue(std::move(SV)) {}
38 };
39 struct BuildAttributeSubSection {
40   std::string Name;
41   unsigned IsOptional;
42   unsigned ParameterType;
43   SmallVector<BuildAttributeItem, 64> Content;
44 };
45 
46 // Tag to string: ELF extended build attribute section
47 struct SubsectionAndTagToTagName {
48   StringRef SubsectionName;
49   unsigned Tag;
50   StringRef TagName;
SubsectionAndTagToTagNameSubsectionAndTagToTagName51   SubsectionAndTagToTagName(StringRef SN, unsigned Tg, StringRef TN)
52       : SubsectionName(SN), Tag(Tg), TagName(TN) {}
53 };
54 
55 namespace ELFAttrs {
56 
57 enum AttrType : unsigned { File = 1, Section = 2, Symbol = 3 };
58 
59 LLVM_ABI StringRef attrTypeAsString(unsigned attr, TagNameMap tagNameMap,
60                                     bool hasTagPrefix = true);
61 LLVM_ABI std::optional<unsigned> attrTypeFromString(StringRef tag,
62                                                     TagNameMap tagNameMap);
63 
64 // Magic numbers for ELF attributes.
65 enum AttrMagic { Format_Version = 0x41 };
66 
67 } // namespace ELFAttrs
68 } // namespace llvm
69 #endif
70