forked from OSchip/llvm-project
[dsymutil] Allow debug map mappings with no object file address. NFC
This change just changes the data structure that ties symbol names, object file address and linked binary addresses to accept mappings with no object file address. Such symbol mappings are not fed into the debug map yet, so this patch is NFC. A subsequent patch will make use of this functionality for common symbols. llvm-svn: 259317
This commit is contained in:
parent
f42e031c79
commit
d8c33dc2f6
|
@ -24,13 +24,13 @@ DebugMapObject::DebugMapObject(StringRef ObjectFilename,
|
|||
sys::TimeValue Timestamp)
|
||||
: Filename(ObjectFilename), Timestamp(Timestamp) {}
|
||||
|
||||
bool DebugMapObject::addSymbol(StringRef Name, uint64_t ObjectAddress,
|
||||
bool DebugMapObject::addSymbol(StringRef Name, Optional<uint64_t> ObjectAddress,
|
||||
uint64_t LinkedAddress, uint32_t Size) {
|
||||
auto InsertResult = Symbols.insert(
|
||||
std::make_pair(Name, SymbolMapping(ObjectAddress, LinkedAddress, Size)));
|
||||
|
||||
if (InsertResult.second)
|
||||
AddressToMapping[ObjectAddress] = &*InsertResult.first;
|
||||
if (ObjectAddress && InsertResult.second)
|
||||
AddressToMapping[*ObjectAddress] = &*InsertResult.first;
|
||||
return InsertResult.second;
|
||||
}
|
||||
|
||||
|
@ -47,8 +47,11 @@ void DebugMapObject::print(raw_ostream &OS) const {
|
|||
Entries.begin(), Entries.end(),
|
||||
[](const Entry &LHS, const Entry &RHS) { return LHS.first < RHS.first; });
|
||||
for (const auto &Sym : Entries) {
|
||||
OS << format("\t%016" PRIx64 " => %016" PRIx64 "+0x%x\t%s\n",
|
||||
uint64_t(Sym.second.ObjectAddress),
|
||||
if (Sym.second.ObjectAddress)
|
||||
OS << format("\t%016" PRIx64, uint64_t(*Sym.second.ObjectAddress));
|
||||
else
|
||||
OS << "\t????????????????";
|
||||
OS << format(" => %016" PRIx64 "+0x%x\t%s\n",
|
||||
uint64_t(Sym.second.BinaryAddress), uint32_t(Sym.second.Size),
|
||||
Sym.first.data());
|
||||
}
|
||||
|
@ -136,7 +139,7 @@ struct MappingTraits<dsymutil::DebugMapObject>::YamlDMO {
|
|||
void MappingTraits<std::pair<std::string, DebugMapObject::SymbolMapping>>::
|
||||
mapping(IO &io, std::pair<std::string, DebugMapObject::SymbolMapping> &s) {
|
||||
io.mapRequired("sym", s.first);
|
||||
io.mapRequired("objAddr", s.second.ObjectAddress);
|
||||
io.mapOptional("objAddr", s.second.ObjectAddress);
|
||||
io.mapRequired("binAddr", s.second.BinaryAddress);
|
||||
io.mapOptional("size", s.second.Size);
|
||||
}
|
||||
|
@ -237,7 +240,9 @@ MappingTraits<dsymutil::DebugMapObject>::YamlDMO::denormalize(IO &IO) {
|
|||
dsymutil::DebugMapObject Res(Path, TV);
|
||||
for (auto &Entry : Entries) {
|
||||
auto &Mapping = Entry.second;
|
||||
uint64_t ObjAddress = Mapping.ObjectAddress;
|
||||
Optional<uint64_t> ObjAddress;
|
||||
if (Mapping.ObjectAddress)
|
||||
ObjAddress = *Mapping.ObjectAddress;
|
||||
auto AddressIt = SymbolAddresses.find(Entry.first);
|
||||
if (AddressIt != SymbolAddresses.end())
|
||||
ObjAddress = AddressIt->getValue();
|
||||
|
|
|
@ -117,12 +117,15 @@ public:
|
|||
class DebugMapObject {
|
||||
public:
|
||||
struct SymbolMapping {
|
||||
yaml::Hex64 ObjectAddress;
|
||||
Optional<yaml::Hex64> ObjectAddress;
|
||||
yaml::Hex64 BinaryAddress;
|
||||
yaml::Hex32 Size;
|
||||
SymbolMapping(uint64_t ObjectAddress, uint64_t BinaryAddress, uint32_t Size)
|
||||
: ObjectAddress(ObjectAddress), BinaryAddress(BinaryAddress),
|
||||
Size(Size) {}
|
||||
SymbolMapping(Optional<uint64_t> ObjectAddr, uint64_t BinaryAddress,
|
||||
uint32_t Size)
|
||||
: BinaryAddress(BinaryAddress), Size(Size) {
|
||||
if (ObjectAddr)
|
||||
ObjectAddress = *ObjectAddr;
|
||||
}
|
||||
/// For YAML IO support
|
||||
SymbolMapping() = default;
|
||||
};
|
||||
|
@ -132,7 +135,7 @@ public:
|
|||
/// \brief Adds a symbol mapping to this DebugMapObject.
|
||||
/// \returns false if the symbol was already registered. The request
|
||||
/// is discarded in this case.
|
||||
bool addSymbol(llvm::StringRef SymName, uint64_t ObjectAddress,
|
||||
bool addSymbol(llvm::StringRef SymName, Optional<uint64_t> ObjectAddress,
|
||||
uint64_t LinkedAddress, uint32_t Size);
|
||||
|
||||
/// \brief Lookup a symbol mapping.
|
||||
|
|
|
@ -1854,10 +1854,10 @@ void DwarfLinker::startDebugObject(DWARFContext &Dwarf, DebugMapObject &Obj) {
|
|||
// -gline-tables-only on Darwin.
|
||||
for (const auto &Entry : Obj.symbols()) {
|
||||
const auto &Mapping = Entry.getValue();
|
||||
if (Mapping.Size)
|
||||
Ranges[Mapping.ObjectAddress] = std::make_pair(
|
||||
Mapping.ObjectAddress + Mapping.Size,
|
||||
int64_t(Mapping.BinaryAddress) - Mapping.ObjectAddress);
|
||||
if (Mapping.Size && Mapping.ObjectAddress)
|
||||
Ranges[*Mapping.ObjectAddress] = std::make_pair(
|
||||
*Mapping.ObjectAddress + Mapping.Size,
|
||||
int64_t(Mapping.BinaryAddress) - *Mapping.ObjectAddress);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1988,14 +1988,16 @@ hasValidRelocation(uint32_t StartOffset, uint32_t EndOffset,
|
|||
|
||||
const auto &ValidReloc = ValidRelocs[NextValidReloc++];
|
||||
const auto &Mapping = ValidReloc.Mapping->getValue();
|
||||
uint64_t ObjectAddress =
|
||||
Mapping.ObjectAddress ? uint64_t(*Mapping.ObjectAddress) : UINT64_MAX;
|
||||
if (Linker.Options.Verbose)
|
||||
outs() << "Found valid debug map entry: " << ValidReloc.Mapping->getKey()
|
||||
<< " " << format("\t%016" PRIx64 " => %016" PRIx64,
|
||||
uint64_t(Mapping.ObjectAddress),
|
||||
<< " " << format("\t%016" PRIx64 " => %016" PRIx64, ObjectAddress,
|
||||
uint64_t(Mapping.BinaryAddress));
|
||||
|
||||
Info.AddrAdjust = int64_t(Mapping.BinaryAddress) + ValidReloc.Addend -
|
||||
Mapping.ObjectAddress;
|
||||
Info.AddrAdjust = int64_t(Mapping.BinaryAddress) + ValidReloc.Addend;
|
||||
if (Mapping.ObjectAddress)
|
||||
Info.AddrAdjust -= ObjectAddress;
|
||||
Info.InDebugMap = true;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -391,7 +391,7 @@ void MachODebugMapParser::handleStabSymbolTableEntry(uint32_t StringIndex,
|
|||
Twine(Name));
|
||||
if (!ObjectSymIt->getValue())
|
||||
return;
|
||||
if (!CurrentDebugMapObject->addSymbol(Name, *ObjectSymIt->getValue(), Value,
|
||||
if (!CurrentDebugMapObject->addSymbol(Name, ObjectSymIt->getValue(), Value,
|
||||
Size))
|
||||
return Warning(Twine("failed to insert symbol '") + Name +
|
||||
"' in the debug map.");
|
||||
|
|
Loading…
Reference in New Issue