forked from OSchip/llvm-project
Print symbol names in relocations when dumping COFF as YAML.
llvm-svn: 183403
This commit is contained in:
parent
c9e304afbd
commit
e2e741ecdd
|
@ -35,11 +35,17 @@ inline SectionCharacteristics operator|(SectionCharacteristics a,
|
||||||
// The structure of the yaml files is not an exact 1:1 match to COFF. In order
|
// The structure of the yaml files is not an exact 1:1 match to COFF. In order
|
||||||
// to use yaml::IO, we use these structures which are closer to the source.
|
// to use yaml::IO, we use these structures which are closer to the source.
|
||||||
namespace COFFYAML {
|
namespace COFFYAML {
|
||||||
|
struct Relocation {
|
||||||
|
uint32_t VirtualAddress;
|
||||||
|
uint16_t Type;
|
||||||
|
StringRef SymbolName;
|
||||||
|
};
|
||||||
|
|
||||||
struct Section {
|
struct Section {
|
||||||
COFF::section Header;
|
COFF::section Header;
|
||||||
unsigned Alignment;
|
unsigned Alignment;
|
||||||
object::yaml::BinaryRef SectionData;
|
object::yaml::BinaryRef SectionData;
|
||||||
std::vector<COFF::relocation> Relocations;
|
std::vector<Relocation> Relocations;
|
||||||
StringRef Name;
|
StringRef Name;
|
||||||
Section();
|
Section();
|
||||||
};
|
};
|
||||||
|
@ -64,7 +70,7 @@ namespace COFFYAML {
|
||||||
|
|
||||||
LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
|
LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
|
||||||
LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
|
LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
|
||||||
LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::relocation)
|
LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
namespace yaml {
|
namespace yaml {
|
||||||
|
@ -105,8 +111,8 @@ struct ScalarBitSetTraits<COFF::SectionCharacteristics> {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct MappingTraits<COFF::relocation> {
|
struct MappingTraits<COFFYAML::Relocation> {
|
||||||
static void mapping(IO &IO, COFF::relocation &Rel);
|
static void mapping(IO &IO, COFFYAML::Relocation &Rel);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
|
|
@ -229,11 +229,12 @@ struct NType {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MappingTraits<COFF::relocation>::mapping(IO &IO, COFF::relocation &Rel) {
|
void MappingTraits<COFFYAML::Relocation>::mapping(IO &IO,
|
||||||
|
COFFYAML::Relocation &Rel) {
|
||||||
MappingNormalization<NType, uint16_t> NT(IO, Rel.Type);
|
MappingNormalization<NType, uint16_t> NT(IO, Rel.Type);
|
||||||
|
|
||||||
IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
|
IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
|
||||||
IO.mapRequired("SymbolTableIndex", Rel.SymbolTableIndex);
|
IO.mapRequired("SymbolName", Rel.SymbolName);
|
||||||
IO.mapRequired("Type", NT->Type);
|
IO.mapRequired("Type", NT->Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,17 +12,17 @@ sections:
|
||||||
Relocations:
|
Relocations:
|
||||||
- !Relocation
|
- !Relocation
|
||||||
VirtualAddress: 0xe
|
VirtualAddress: 0xe
|
||||||
SymbolTableIndex: 5
|
SymbolName: L_.str
|
||||||
Type: IMAGE_REL_I386_DIR32
|
Type: IMAGE_REL_I386_DIR32
|
||||||
|
|
||||||
- !Relocation
|
- !Relocation
|
||||||
VirtualAddress: 0x13
|
VirtualAddress: 0x13
|
||||||
SymbolTableIndex: 6
|
SymbolName: _puts
|
||||||
Type: IMAGE_REL_I386_REL32
|
Type: IMAGE_REL_I386_REL32
|
||||||
|
|
||||||
- !Relocation
|
- !Relocation
|
||||||
VirtualAddress: 0x18
|
VirtualAddress: 0x18
|
||||||
SymbolTableIndex: 7
|
SymbolName: _SomeOtherFunction
|
||||||
Type: IMAGE_REL_I386_REL32
|
Type: IMAGE_REL_I386_REL32
|
||||||
|
|
||||||
- !Section
|
- !Section
|
||||||
|
|
|
@ -11,17 +11,17 @@ sections:
|
||||||
Relocations:
|
Relocations:
|
||||||
- !Relocation
|
- !Relocation
|
||||||
VirtualAddress: 0xf
|
VirtualAddress: 0xf
|
||||||
SymbolTableIndex: 5
|
SymbolName: L.str
|
||||||
Type: IMAGE_REL_AMD64_REL32
|
Type: IMAGE_REL_AMD64_REL32
|
||||||
|
|
||||||
- !Relocation
|
- !Relocation
|
||||||
VirtualAddress: 0x14
|
VirtualAddress: 0x14
|
||||||
SymbolTableIndex: 6
|
SymbolName: puts
|
||||||
Type: IMAGE_REL_AMD64_REL32
|
Type: IMAGE_REL_AMD64_REL32
|
||||||
|
|
||||||
- !Relocation
|
- !Relocation
|
||||||
VirtualAddress: 0x19
|
VirtualAddress: 0x19
|
||||||
SymbolTableIndex: 7
|
SymbolName: SomeOtherFunction
|
||||||
Type: IMAGE_REL_AMD64_REL32
|
Type: IMAGE_REL_AMD64_REL32
|
||||||
|
|
||||||
- !Section
|
- !Section
|
||||||
|
|
|
@ -13,15 +13,15 @@ COFF-I386-NEXT: SectionData: 83EC0CC744240800000000C7042400000000E800000000E
|
||||||
|
|
||||||
COFF-I386: Relocations:
|
COFF-I386: Relocations:
|
||||||
COFF-I386-NEXT: - VirtualAddress: 14
|
COFF-I386-NEXT: - VirtualAddress: 14
|
||||||
COFF-I386-NEXT: SymbolTableIndex: 5
|
COFF-I386-NEXT: SymbolName: L_.str
|
||||||
COFF-I386-NEXT: Type: IMAGE_REL_I386_DIR32
|
COFF-I386-NEXT: Type: IMAGE_REL_I386_DIR32
|
||||||
|
|
||||||
COFF-I386: - VirtualAddress: 19
|
COFF-I386: - VirtualAddress: 19
|
||||||
COFF-I386-NEXT: SymbolTableIndex: 6
|
COFF-I386-NEXT: SymbolName: _puts
|
||||||
COFF-I386-NEXT: Type: IMAGE_REL_I386_REL32
|
COFF-I386-NEXT: Type: IMAGE_REL_I386_REL32
|
||||||
|
|
||||||
COFF-I386: - VirtualAddress: 24
|
COFF-I386: - VirtualAddress: 24
|
||||||
COFF-I386-NEXT: SymbolTableIndex: 7
|
COFF-I386-NEXT: SymbolName: _SomeOtherFunction
|
||||||
COFF-I386-NEXT: Type: IMAGE_REL_I386_REL32
|
COFF-I386-NEXT: Type: IMAGE_REL_I386_REL32
|
||||||
|
|
||||||
COFF-I386: - Name: .data
|
COFF-I386: - Name: .data
|
||||||
|
@ -88,15 +88,15 @@ COFF-X86-64-NEXT: SectionData: 4883EC28C744242400000000488D0D00000000E800000
|
||||||
|
|
||||||
COFF-X86-64: Relocations:
|
COFF-X86-64: Relocations:
|
||||||
COFF-X86-64-NEXT: - VirtualAddress: 15
|
COFF-X86-64-NEXT: - VirtualAddress: 15
|
||||||
COFF-X86-64-NEXT: SymbolTableIndex: 5
|
COFF-X86-64-NEXT: SymbolName: L.str
|
||||||
COFF-X86-64-NEXT: Type: IMAGE_REL_AMD64_REL32
|
COFF-X86-64-NEXT: Type: IMAGE_REL_AMD64_REL32
|
||||||
|
|
||||||
COFF-X86-64: - VirtualAddress: 20
|
COFF-X86-64: - VirtualAddress: 20
|
||||||
COFF-X86-64-NEXT: SymbolTableIndex: 6
|
COFF-X86-64-NEXT: SymbolName: puts
|
||||||
COFF-X86-64-NEXT: Type: IMAGE_REL_AMD64_REL32
|
COFF-X86-64-NEXT: Type: IMAGE_REL_AMD64_REL32
|
||||||
|
|
||||||
COFF-X86-64: - VirtualAddress: 25
|
COFF-X86-64: - VirtualAddress: 25
|
||||||
COFF-X86-64-NEXT: SymbolTableIndex: 7
|
COFF-X86-64-NEXT: SymbolName: SomeOtherFunction
|
||||||
COFF-X86-64-NEXT: Type: IMAGE_REL_AMD64_REL32
|
COFF-X86-64-NEXT: Type: IMAGE_REL_AMD64_REL32
|
||||||
|
|
||||||
COFF-X86-64: - Name: .data
|
COFF-X86-64: - Name: .data
|
||||||
|
|
|
@ -66,13 +66,15 @@ void COFFDumper::dumpSections(unsigned NumSections) {
|
||||||
Obj.getSectionContents(Sect, sectionData);
|
Obj.getSectionContents(Sect, sectionData);
|
||||||
Sec.SectionData = object::yaml::BinaryRef(sectionData);
|
Sec.SectionData = object::yaml::BinaryRef(sectionData);
|
||||||
|
|
||||||
std::vector<COFF::relocation> Relocations;
|
std::vector<COFFYAML::Relocation> Relocations;
|
||||||
for (object::relocation_iterator rIter = iter->begin_relocations();
|
for (object::relocation_iterator rIter = iter->begin_relocations();
|
||||||
rIter != iter->end_relocations(); rIter.increment(ec)) {
|
rIter != iter->end_relocations(); rIter.increment(ec)) {
|
||||||
const object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter);
|
const object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter);
|
||||||
COFF::relocation Rel;
|
COFFYAML::Relocation Rel;
|
||||||
|
object::symbol_iterator Sym = rIter->getSymbol();
|
||||||
|
StringRef Name;
|
||||||
|
Sym->getName(Rel.SymbolName);
|
||||||
Rel.VirtualAddress = reloc->VirtualAddress;
|
Rel.VirtualAddress = reloc->VirtualAddress;
|
||||||
Rel.SymbolTableIndex = reloc->SymbolTableIndex;
|
|
||||||
Rel.Type = reloc->Type;
|
Rel.Type = reloc->Type;
|
||||||
Relocations.push_back(Rel);
|
Relocations.push_back(Rel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,15 +219,25 @@ bool writeCOFF(COFFParser &CP, raw_ostream &OS) {
|
||||||
<< binary_le(i->Header.Characteristics);
|
<< binary_le(i->Header.Characteristics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned CurSymbol = 0;
|
||||||
|
StringMap<unsigned> SymbolTableIndexMap;
|
||||||
|
for (std::vector<COFFYAML::Symbol>::iterator I = CP.Obj.Symbols.begin(),
|
||||||
|
E = CP.Obj.Symbols.end();
|
||||||
|
I != E; ++I) {
|
||||||
|
SymbolTableIndexMap[I->Name] = CurSymbol;
|
||||||
|
CurSymbol += 1 + I->Header.NumberOfAuxSymbols;
|
||||||
|
}
|
||||||
|
|
||||||
// Output section data.
|
// Output section data.
|
||||||
for (std::vector<COFFYAML::Section>::iterator i = CP.Obj.Sections.begin(),
|
for (std::vector<COFFYAML::Section>::iterator i = CP.Obj.Sections.begin(),
|
||||||
e = CP.Obj.Sections.end();
|
e = CP.Obj.Sections.end();
|
||||||
i != e; ++i) {
|
i != e; ++i) {
|
||||||
i->SectionData.writeAsBinary(OS);
|
i->SectionData.writeAsBinary(OS);
|
||||||
for (unsigned I2 = 0, E2 = i->Relocations.size(); I2 != E2; ++I2) {
|
for (unsigned I2 = 0, E2 = i->Relocations.size(); I2 != E2; ++I2) {
|
||||||
const COFF::relocation &R = i->Relocations[I2];
|
const COFFYAML::Relocation &R = i->Relocations[I2];
|
||||||
|
uint32_t SymbolTableIndex = SymbolTableIndexMap[R.SymbolName];
|
||||||
OS << binary_le(R.VirtualAddress)
|
OS << binary_le(R.VirtualAddress)
|
||||||
<< binary_le(R.SymbolTableIndex)
|
<< binary_le(SymbolTableIndex)
|
||||||
<< binary_le(R.Type);
|
<< binary_le(R.Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue