In a future patch, it will be desirable to skip over all hash data entries for a
particular string. In order to do so, we must know how many bytes each of those
entries have.
In its full specification, Apple tables allow for variable length entries, which
would make the above impossible without reading the data of each entry. However,
this is largely unsupported today (as a FIXME in the code indicates, there is a
bug with hash collisions exactly because we don't know how to skip over data),
and the documentation[1] states that:
> For the current implementations of the “.apple_names” (all functions +
> globals), the “.apple_types” (names of all types that are defined), and the
> “.apple_namespaces” (all namespaces), we currently set the Atom array to be:
> [...]
> This defines the contents to be the DIE offset (eAtomTypeDIEOffset) that is
> encoded as a 32 bit value (DW_FORM_data4).
In other words, we only produce fixed sized entries.
A few tests containing invalid dwarf had to be updated, as the error is now
detected earlier (when the accelerator table is being parsed, instead of inside
the explicit call to "verify").
[1]: https://llvm.org/docs/SourceLevelDebugging.html#fixed-lookup
Depends on D152156
Differential Revision: https://reviews.llvm.org/D152157
Header Hdr;
HeaderData HdrData;
dwarf::FormParams FormParams;
+ uint32_t HashDataEntryLength;
bool IsValid = false;
/// Returns true if we should continue scanning for entries or false if we've
uint32_t getSizeHdr() const;
uint32_t getHeaderDataLength() const;
+ /// Returns the size of one HashData entry.
+ uint32_t getHashDataEntryLength() const { return HashDataEntryLength; }
+
/// Return the Atom description, which can be used to interpret the raw values
/// of the Accelerator Entries in this table.
ArrayRef<std::pair<HeaderData::AtomType, HeaderData::Form>> getAtomsDesc();
HdrData.DIEOffsetBase = AccelSection.getU32(&Offset);
uint32_t NumAtoms = AccelSection.getU32(&Offset);
+ HashDataEntryLength = 0;
+ auto MakeUnsupportedFormError = [](dwarf::Form Form) {
+ return createStringError(errc::not_supported,
+ "Unsupported form:" +
+ dwarf::FormEncodingString(Form));
+ };
+
for (unsigned i = 0; i < NumAtoms; ++i) {
uint16_t AtomType = AccelSection.getU16(&Offset);
auto AtomForm = static_cast<dwarf::Form>(AccelSection.getU16(&Offset));
HdrData.Atoms.push_back(std::make_pair(AtomType, AtomForm));
+
+ std::optional<uint8_t> FormSize =
+ dwarf::getFixedFormByteSize(AtomForm, FormParams);
+ if (!FormSize)
+ return MakeUnsupportedFormError(AtomForm);
+ HashDataEntryLength += *FormSize;
}
IsValid = true;
W.printNumber("DIE offset base", HdrData.DIEOffsetBase);
W.printNumber("Number of atoms", uint64_t(HdrData.Atoms.size()));
+ W.printNumber("Size of each hash data entry", getHashDataEntryLength());
SmallVector<DWARFFormValue, 3> AtomForms;
{
ListScope AtomsScope(W, "Atoms");
CHECK-NEXT: }
CHECK-NEXT: DIE offset base: 0
CHECK-NEXT: Number of atoms: 1
+CHECK-NEXT: Size of each hash data entry: 4
CHECK-NEXT: Atoms [
CHECK-NEXT: Atom 0 {
CHECK-NEXT: Type: DW_ATOM_die_offset
CHECK-NEXT: }
CHECK-NEXT: DIE offset base: 0
CHECK-NEXT: Number of atoms: 4
+CHECK-NEXT: Size of each hash data entry: 11
CHECK-NEXT: Atoms [
CHECK-NEXT: Atom 0 {
CHECK-NEXT: Type: DW_ATOM_die_offset
CHECK-NEXT: }
CHECK-NEXT: DIE offset base: 0
CHECK-NEXT: Number of atoms: 1
+CHECK-NEXT: Size of each hash data entry: 4
CHECK-NEXT: Atoms [
CHECK-NEXT: Atom 0 {
CHECK-NEXT: Type: DW_ATOM_die_offset
CHECK-NEXT: }
CHECK-NEXT: DIE offset base: 0
CHECK-NEXT: Number of atoms: 1
+CHECK-NEXT: Size of each hash data entry: 4
CHECK-NEXT: Atoms [
CHECK-NEXT: Atom 0 {
CHECK-NEXT: Type: DW_ATOM_die_offset
CHECK-NEXT: }
CHECK-NEXT: DIE offset base: 0
CHECK-NEXT: Number of atoms: 1
+CHECK-NEXT: Size of each hash data entry: 4
CHECK-NEXT: Atoms [
CHECK-NEXT: Atom 0 {
CHECK-NEXT: Type: DW_ATOM_die_offset
CHECK-NEXT: }
CHECK-NEXT: DIE offset base: 0
CHECK-NEXT: Number of atoms: 4
+CHECK-NEXT: Size of each hash data entry: 11
CHECK-NEXT: Atoms [
CHECK-NEXT: Atom 0 {
CHECK-NEXT: Type: DW_ATOM_die_offset
CHECK-NEXT: }
CHECK-NEXT: DIE offset base: 0
CHECK-NEXT: Number of atoms: 1
+CHECK-NEXT: Size of each hash data entry: 4
CHECK-NEXT: Atoms [
CHECK-NEXT: Atom 0 {
CHECK-NEXT: Type: DW_ATOM_die_offset
CHECK-NEXT: }
CHECK-NEXT: DIE offset base: 0
CHECK-NEXT: Number of atoms: 1
+CHECK-NEXT: Size of each hash data entry: 4
CHECK-NEXT: Atoms [
CHECK-NEXT: Atom 0 {
CHECK-NEXT: Type: DW_ATOM_die_offset
CHECK-NEXT: }
CHECK-NEXT: DIE offset base: 0
CHECK-NEXT: Number of atoms: 1
+CHECK-NEXT: Size of each hash data entry: 4
CHECK-NEXT: Atoms [
CHECK-NEXT: Atom 0 {
CHECK-NEXT: Type: DW_ATOM_die_offset
# RUN: | FileCheck %s
# CHECK: Verifying .apple_names...
-# CHECK-NEXT: error: Unsupported form: failed to read HashData.
+# CHECK-NEXT: error: Unsupported form:
# This test is meant to verify that the -verify option
# in llvm-dwarfdump, correctly identifies that Atom[0].form is unsupported.
.long 0 ## HeaderData Die Offset Base
.long 1 ## HeaderData Atom Count
.short 1 ## DW_ATOM_die_offset
- .short 400 ## DW_FORM_data4 -- error: unsupported form; failed to read HashData.
+ .short 400 ## not a valid form -- error: unsupported form; failed to read HashData.
.long 0 ## Bucket 0
.long 1 ## Bucket 1
.long 177678 ## Hash in Bucket 0