Skip to content

Commit

Permalink
Revert "[DWARFYAML] Add support for referencing different abbrev tabl…
Browse files Browse the repository at this point in the history
…es."

This reverts commit f7ff0ac.

This change is causing build failure.

http://lab.llvm.org:8011/builders/clang-cmake-armv7-global-isel/builds/10400
  • Loading branch information
higuoxing committed Aug 21, 2020
1 parent 7d9a162 commit 6d242a7
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 498 deletions.
7 changes: 0 additions & 7 deletions llvm/include/llvm/ObjectYAML/DWARFYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "llvm/ObjectYAML/YAML.h"
#include "llvm/Support/YAMLTraits.h"
#include <cstdint>
#include <unordered_map>
#include <vector>

namespace llvm {
Expand All @@ -41,7 +40,6 @@ struct Abbrev {
};

struct AbbrevTable {
Optional<uint64_t> ID;
std::vector<Abbrev> Table;
};

Expand Down Expand Up @@ -112,7 +110,6 @@ struct Unit {
uint16_t Version;
Optional<uint8_t> AddrSize;
llvm::dwarf::UnitType Type; // Added in DWARF 5
Optional<uint64_t> AbbrevTableID;
yaml::Hex64 AbbrOffset;
std::vector<Entry> Entries;
};
Expand Down Expand Up @@ -231,10 +228,6 @@ struct Data {
bool isEmpty() const;

SetVector<StringRef> getNonEmptySectionNames() const;
Expected<uint64_t> getAbbrevTableIndexByID(uint64_t ID) const;

private:
mutable std::unordered_map<uint64_t, uint64_t> AbbrevTableID2Index;
};

} // end namespace DWARFYAML
Expand Down
27 changes: 10 additions & 17 deletions llvm/lib/ObjectYAML/DWARFEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ Error DWARFYAML::emitDebugGNUPubtypes(raw_ostream &OS, const Data &DI) {
/*IsGNUStyle=*/true);
}

static Expected<uint64_t> writeDIE(const DWARFYAML::Data &DI, uint64_t CUIndex,
uint64_t AbbrevTableID,
static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::AbbrevTable> AbbrevTable,
const dwarf::FormParams &Params,
const DWARFYAML::Entry &Entry,
raw_ostream &OS, bool IsLittleEndian) {
Expand All @@ -257,15 +256,12 @@ static Expected<uint64_t> writeDIE(const DWARFYAML::Data &DI, uint64_t CUIndex,
if (AbbrCode == 0 || Entry.Values.empty())
return OS.tell() - EntryBegin;

Expected<uint64_t> AbbrevTableIndexOrErr =
DI.getAbbrevTableIndexByID(AbbrevTableID);
if (!AbbrevTableIndexOrErr)
return createStringError(errc::invalid_argument,
toString(AbbrevTableIndexOrErr.takeError()) +
" for compilation unit with index " +
utostr(CUIndex));
ArrayRef<DWARFYAML::Abbrev> AbbrevDecls(
DI.DebugAbbrev[*AbbrevTableIndexOrErr].Table);
if (AbbrevTable.empty())
return createStringError(
errc::invalid_argument,
"non-empty compilation unit should have an associated abbrev table");

ArrayRef<DWARFYAML::Abbrev> AbbrevDecls(AbbrevTable[0].Table);

if (AbbrCode > AbbrevDecls.size())
return createStringError(
Expand Down Expand Up @@ -388,8 +384,7 @@ static Expected<uint64_t> writeDIE(const DWARFYAML::Data &DI, uint64_t CUIndex,
}

Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
for (uint64_t I = 0; I < DI.CompileUnits.size(); ++I) {
const DWARFYAML::Unit &Unit = DI.CompileUnits[I];
for (const DWARFYAML::Unit &Unit : DI.CompileUnits) {
uint8_t AddrSize;
if (Unit.AddrSize)
AddrSize = *Unit.AddrSize;
Expand All @@ -407,11 +402,9 @@ Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
std::string EntryBuffer;
raw_string_ostream EntryBufferOS(EntryBuffer);

uint64_t AbbrevTableID = Unit.AbbrevTableID.getValueOr(I);
for (const DWARFYAML::Entry &Entry : Unit.Entries) {
if (Expected<uint64_t> EntryLength =
writeDIE(DI, I, AbbrevTableID, Params, Entry, EntryBufferOS,
DI.IsLittleEndian))
if (Expected<uint64_t> EntryLength = writeDIE(
DI.DebugAbbrev, Params, Entry, EntryBufferOS, DI.IsLittleEndian))
Length += *EntryLength;
else
return EntryLength.takeError();
Expand Down
29 changes: 0 additions & 29 deletions llvm/lib/ObjectYAML/DWARFYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

#include "llvm/ObjectYAML/DWARFYAML.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"

namespace llvm {

Expand Down Expand Up @@ -55,31 +53,6 @@ SetVector<StringRef> DWARFYAML::Data::getNonEmptySectionNames() const {
return SecNames;
}

Expected<uint64_t> DWARFYAML::Data::getAbbrevTableIndexByID(uint64_t ID) const {
if (AbbrevTableID2Index.empty()) {
for (auto &AbbrevTable : enumerate(DebugAbbrev)) {
// If the abbrev table's ID isn't specified, we use the index as its ID.
uint64_t AbbrevTableID =
AbbrevTable.value().ID.getValueOr(AbbrevTable.index());
auto It =
AbbrevTableID2Index.insert({AbbrevTableID, AbbrevTable.index()});
if (!It.second)
return createStringError(
errc::invalid_argument,
"the ID (%" PRIu64 ") of abbrev table with index %" PRIu64
" has been used by abbrev table with index %" PRIu64,
AbbrevTableID, AbbrevTable.index(), It.first->second);
}
}

auto It = AbbrevTableID2Index.find(ID);
if (It == AbbrevTableID2Index.end())
return createStringError(errc::invalid_argument,
"cannot find abbrev table whose ID is %" PRIu64,
ID);
return It->second;
}

namespace yaml {

void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) {
Expand Down Expand Up @@ -107,7 +80,6 @@ void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) {

void MappingTraits<DWARFYAML::AbbrevTable>::mapping(
IO &IO, DWARFYAML::AbbrevTable &AbbrevTable) {
IO.mapOptional("ID", AbbrevTable.ID);
IO.mapOptional("Table", AbbrevTable.Table);
}

Expand Down Expand Up @@ -181,7 +153,6 @@ void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) {
IO.mapRequired("Version", Unit.Version);
if (Unit.Version >= 5)
IO.mapRequired("UnitType", Unit.Type);
IO.mapOptional("AbbrevTableID", Unit.AbbrevTableID);
IO.mapRequired("AbbrOffset", Unit.AbbrOffset);
IO.mapOptional("AddrSize", Unit.AddrSize);
IO.mapOptional("Entries", Unit.Entries);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ObjectYAML/ELFEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ static bool shouldEmitDWARF(DWARFYAML::Data &DWARF, StringRef Name) {

template <class ELFT>
Expected<uint64_t> emitDWARF(typename ELFT::Shdr &SHeader, StringRef Name,
DWARFYAML::Data &DWARF,
const DWARFYAML::Data &DWARF,
ContiguousBlobAccumulator &CBA) {
// We are unable to predict the size of debug data, so we request to write 0
// bytes. This should always return us an output stream unless CBA is already
Expand Down
71 changes: 1 addition & 70 deletions llvm/test/ObjectYAML/MachO/DWARF-debug_abbrev.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
## a) Test that yaml2obj is able to emit the __debug_abbrev section and obj2yaml is
## able to convert it back.

# RUN: yaml2obj --docnum=1 %s | obj2yaml | FileCheck %s
# RUN: yaml2obj %s | obj2yaml | FileCheck %s

--- !mach-o
FileHeader:
Expand Down Expand Up @@ -423,69 +420,3 @@ DWARF:
#CHECK: Attributes:
#CHECK: - Attribute: DW_AT_type
#CHECK: Form: DW_FORM_ref4

## b) Test that yaml2obj emits an error message when there are non-empty compilation
## units and multiple abbrev tables are assigned the same ID.

# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=ID-COLLISION

# ID-COLLISION: yaml2obj: error: the ID (1) of abbrev table with index 1 has been used by abbrev table with index 0

--- !mach-o
FileHeader:
magic: 0xFEEDFACF
cputype: 0x01000007
cpusubtype: 0x00000003
filetype: 0x0000000A
ncmds: 1
sizeofcmds: 232
flags: 0x00000000
reserved: 0x00000000
LoadCommands:
- cmd: LC_SEGMENT_64
cmdsize: 232
segname: __DWARF
vmaddr: 0x00
vmsize: 0x00
fileoff: 0x00
filesize: 0x00
maxprot: 0
initprot: 0
nsects: 2
flags: 0
Sections:
- sectname: __debug_abbrev
segname: __DWARF
addr: 0x00
size: 24
offset: 528
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x00000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
- sectname: __debug_info
segname: __DWARF
addr: 0x00
size: 64
offset: 1070
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x00000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
DWARF:
debug_abbrev:
- ID: 1
- ID: 1
debug_info:
- Version: 4
AbbrOffset: 0x00
Entries:
- AbbrCode: 1
Values:
- Value: 0x1234
Loading

0 comments on commit 6d242a7

Please sign in to comment.