LLVM  14.0.0git
DebugChecksumsSubsection.cpp
Go to the documentation of this file.
1 //===- DebugChecksumsSubsection.cpp ---------------------------------------===//
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 
10 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/Support/Endian.h"
16 #include "llvm/Support/Error.h"
18 #include <cassert>
19 #include <cstdint>
20 #include <cstring>
21 
22 using namespace llvm;
23 using namespace llvm::codeview;
24 
27 
28  ulittle32_t FileNameOffset; // Byte offset of filename in global string table.
29  uint8_t ChecksumSize; // Number of bytes of checksum.
30  uint8_t ChecksumKind; // FileChecksumKind
31  // Checksum bytes follow.
32 };
33 
36  BinaryStreamReader Reader(Stream);
37 
38  const FileChecksumEntryHeader *Header;
39  if (auto EC = Reader.readObject(Header))
40  return EC;
41 
42  Item.FileNameOffset = Header->FileNameOffset;
43  Item.Kind = static_cast<FileChecksumKind>(Header->ChecksumKind);
44  if (auto EC = Reader.readBytes(Item.Checksum, Header->ChecksumSize))
45  return EC;
46 
47  Len = alignTo(Header->ChecksumSize + sizeof(FileChecksumEntryHeader), 4);
48  return Error::success();
49 }
50 
52  if (auto EC = Reader.readArray(Checksums, Reader.bytesRemaining()))
53  return EC;
54 
55  return Error::success();
56 }
57 
60  return initialize(Reader);
61 }
62 
65  : DebugSubsection(DebugSubsectionKind::FileChecksums), Strings(Strings) {}
66 
69  ArrayRef<uint8_t> Bytes) {
70  FileChecksumEntry Entry;
71  if (!Bytes.empty()) {
72  uint8_t *Copy = Storage.Allocate<uint8_t>(Bytes.size());
73  ::memcpy(Copy, Bytes.data(), Bytes.size());
74  Entry.Checksum = makeArrayRef(Copy, Bytes.size());
75  }
76 
77  Entry.FileNameOffset = Strings.insert(FileName);
78  Entry.Kind = Kind;
79  Checksums.push_back(Entry);
80 
81  // This maps the offset of this string in the string table to the offset
82  // of this checksum entry in the checksum buffer.
83  OffsetMap[Entry.FileNameOffset] = SerializedSize;
84  assert(SerializedSize % 4 == 0);
85 
86  uint32_t Len = alignTo(sizeof(FileChecksumEntryHeader) + Bytes.size(), 4);
87  SerializedSize += Len;
88 }
89 
91  return SerializedSize;
92 }
93 
95  for (const auto &FC : Checksums) {
97  Header.ChecksumKind = uint8_t(FC.Kind);
98  Header.ChecksumSize = FC.Checksum.size();
99  Header.FileNameOffset = FC.FileNameOffset;
100  if (auto EC = Writer.writeObject(Header))
101  return EC;
102  if (auto EC = Writer.writeArray(makeArrayRef(FC.Checksum)))
103  return EC;
104  if (auto EC = Writer.padToAlignment(4))
105  return EC;
106  }
107  return Error::success();
108 }
109 
111  uint32_t Offset = Strings.getIdForString(FileName);
112  auto Iter = OffsetMap.find(Offset);
113  assert(Iter != OffsetMap.end());
114  return Iter->second;
115 }
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:148
BinaryStreamReader.h
MathExtras.h
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::BinaryStreamReader::readBytes
Error readBytes(ArrayRef< uint8_t > &Buffer, uint32_t Size)
Read Size bytes from the underlying stream at the current offset and and set Buffer to the resulting ...
Definition: BinaryStreamReader.cpp:37
llvm::support::detail::packed_endian_specific_integral
Definition: Endian.h:206
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition: BinaryStreamWriter.h:31
llvm::codeview::DebugStringTableSubsection::insert
uint32_t insert(StringRef S)
Definition: DebugStringTableSubsection.cpp:47
llvm::codeview::FileChecksumKind
FileChecksumKind
Definition: CodeView.h:564
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
R600_InstFlag::FC
@ FC
Definition: R600Defines.h:32
Error.h
llvm::codeview::DebugStringTableSubsection
Represents a read-write view of a CodeView string table.
Definition: DebugStringTableSubsection.h:56
llvm::codeview::FileChecksumEntry::FileNameOffset
uint32_t FileNameOffset
Definition: DebugChecksumsSubsection.h:32
llvm::BinaryStreamReader::bytesRemaining
uint64_t bytesRemaining() const
Definition: BinaryStreamReader.h:257
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::codeview::DebugChecksumsSubsection::DebugChecksumsSubsection
DebugChecksumsSubsection(DebugStringTableSubsection &Strings)
Definition: DebugChecksumsSubsection.cpp:63
llvm::BinaryStreamWriter::writeArray
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
Definition: BinaryStreamWriter.h:151
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:160
llvm::codeview::DebugSubsection::Kind
DebugSubsectionKind Kind
Definition: DebugSubsection.h:45
llvm::ArrayRef::data
const T * data() const
Definition: ArrayRef.h:162
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
DebugChecksumsSubsection.h
llvm::BumpPtrAllocatorImpl::Allocate
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:145
FileChecksumEntryHeader::FileNameOffset
ulittle32_t FileNameOffset
Definition: DebugChecksumsSubsection.cpp:28
llvm::codeview::DebugSubsectionKind::FileChecksums
@ FileChecksums
llvm::codeview::FileChecksumEntry
Definition: DebugChecksumsSubsection.h:31
llvm::VarStreamArrayExtractor::operator()
Error operator()(BinaryStreamRef Stream, uint32_t &Len, T &Item) const =delete
Definition: DebugChecksumsSubsection.cpp:35
FileChecksumEntryHeader
Definition: DebugChecksumsSubsection.cpp:25
CodeView.h
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::BinaryStreamReader
Provides read only access to a subclass of BinaryStream.
Definition: BinaryStreamReader.h:31
llvm::support::ulittle32_t
detail::packed_endian_specific_integral< uint32_t, little, unaligned > ulittle32_t
Definition: Endian.h:272
FileChecksumEntryHeader::ChecksumSize
uint8_t ChecksumSize
Definition: DebugChecksumsSubsection.cpp:29
llvm::codeview::DebugChecksumsSubsection::mapChecksumOffset
uint32_t mapChecksumOffset(StringRef FileName) const
Definition: DebugChecksumsSubsection.cpp:110
llvm::codeview::FrameCookieKind::Copy
@ Copy
ArrayRef.h
llvm::DenseMapBase::find
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:150
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::codeview::FileChecksumEntry::Kind
FileChecksumKind Kind
Definition: DebugChecksumsSubsection.h:33
memcpy
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
llvm::codeview::CompileSym2Flags::EC
@ EC
llvm::BinaryStreamReader::readObject
Error readObject(const T *&Dest)
Get a pointer to an object of type T from the underlying stream, as if by memcpy, and store the resul...
Definition: BinaryStreamReader.h:169
llvm::ArrayRef< uint8_t >
llvm::BinaryStreamWriter::writeObject
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Definition: BinaryStreamWriter.h:135
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
llvm::codeview::DebugSubsection
Definition: DebugSubsection.h:32
llvm::DenseMapBase::end
iterator end()
Definition: DenseMap.h:83
llvm::BinaryStreamWriter::padToAlignment
Error padToAlignment(uint32_t Align)
Definition: BinaryStreamWriter.cpp:95
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
FileChecksumEntryHeader::ChecksumKind
uint8_t ChecksumKind
Definition: DebugChecksumsSubsection.cpp:30
DebugStringTableSubsection.h
llvm::codeview::DebugSubsectionKind
DebugSubsectionKind
Definition: CodeView.h:313
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
llvm::codeview::FileChecksumEntry::Checksum
ArrayRef< uint8_t > Checksum
Definition: DebugChecksumsSubsection.h:34
llvm::codeview::DebugChecksumsSubsection::addChecksum
void addChecksum(StringRef FileName, FileChecksumKind Kind, ArrayRef< uint8_t > Bytes)
Definition: DebugChecksumsSubsection.cpp:67
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
BinaryStreamWriter.h
llvm::codeview::DebugStringTableSubsection::getIdForString
uint32_t getIdForString(StringRef S) const
Definition: DebugStringTableSubsection.cpp:97
llvm::codeview::DebugChecksumsSubsection::commit
Error commit(BinaryStreamWriter &Writer) const override
Definition: DebugChecksumsSubsection.cpp:94
llvm::codeview::DebugChecksumsSubsection::calculateSerializedSize
uint32_t calculateSerializedSize() const override
Definition: DebugChecksumsSubsection.cpp:90
Endian.h
llvm::codeview::DebugChecksumsSubsectionRef::initialize
Error initialize(BinaryStreamReader Reader)
Definition: DebugChecksumsSubsection.cpp:51
llvm::BinaryStreamReader::readArray
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...
Definition: BinaryStreamReader.h:187
llvm::BinaryStreamRef
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Definition: BinaryStreamRef.h:156