mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-23 19:17:17 +00:00
[Object/COFF]: Expose getSectionName.
Also add some documentation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153050 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2d7ea04e28
commit
b35a896e07
@ -88,7 +88,14 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// @brief Create a Binary from Source, autodetecting the file type.
|
||||||
|
///
|
||||||
|
/// @param Source The data to create the Binary from. Ownership is transfered
|
||||||
|
/// to Result if successful. If an error is returned, Source is destroyed
|
||||||
|
/// by createBinary before returning.
|
||||||
|
/// @param Result A pointer to the resulting Binary if no error occured.
|
||||||
error_code createBinary(MemoryBuffer *Source, OwningPtr<Binary> &Result);
|
error_code createBinary(MemoryBuffer *Source, OwningPtr<Binary> &Result);
|
||||||
|
|
||||||
error_code createBinary(StringRef Path, OwningPtr<Binary> &Result);
|
error_code createBinary(StringRef Path, OwningPtr<Binary> &Result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -177,6 +177,7 @@ public:
|
|||||||
return ec;
|
return ec;
|
||||||
}
|
}
|
||||||
error_code getSymbolName(const coff_symbol *symbol, StringRef &Res) const;
|
error_code getSymbolName(const coff_symbol *symbol, StringRef &Res) const;
|
||||||
|
error_code getSectionName(const coff_section *Sec, StringRef &Res) const;
|
||||||
|
|
||||||
static inline bool classof(const Binary *v) {
|
static inline bool classof(const Binary *v) {
|
||||||
return v->isCOFF();
|
return v->isCOFF();
|
||||||
|
@ -300,25 +300,7 @@ error_code COFFObjectFile::getSectionNext(DataRefImpl Sec,
|
|||||||
error_code COFFObjectFile::getSectionName(DataRefImpl Sec,
|
error_code COFFObjectFile::getSectionName(DataRefImpl Sec,
|
||||||
StringRef &Result) const {
|
StringRef &Result) const {
|
||||||
const coff_section *sec = toSec(Sec);
|
const coff_section *sec = toSec(Sec);
|
||||||
StringRef name;
|
return getSectionName(sec, Result);
|
||||||
if (sec->Name[7] == 0)
|
|
||||||
// Null terminated, let ::strlen figure out the length.
|
|
||||||
name = sec->Name;
|
|
||||||
else
|
|
||||||
// Not null terminated, use all 8 bytes.
|
|
||||||
name = StringRef(sec->Name, 8);
|
|
||||||
|
|
||||||
// Check for string table entry. First byte is '/'.
|
|
||||||
if (name[0] == '/') {
|
|
||||||
uint32_t Offset;
|
|
||||||
if (name.substr(1).getAsInteger(10, Offset))
|
|
||||||
return object_error::parse_failed;
|
|
||||||
if (error_code ec = getString(Offset, name))
|
|
||||||
return ec;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result = name;
|
|
||||||
return object_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error_code COFFObjectFile::getSectionAddress(DataRefImpl Sec,
|
error_code COFFObjectFile::getSectionAddress(DataRefImpl Sec,
|
||||||
@ -631,6 +613,29 @@ error_code COFFObjectFile::getSymbolName(const coff_symbol *symbol,
|
|||||||
return object_error::success;
|
return object_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_code COFFObjectFile::getSectionName(const coff_section *Sec,
|
||||||
|
StringRef &Res) const {
|
||||||
|
StringRef Name;
|
||||||
|
if (Sec->Name[7] == 0)
|
||||||
|
// Null terminated, let ::strlen figure out the length.
|
||||||
|
Name = Sec->Name;
|
||||||
|
else
|
||||||
|
// Not null terminated, use all 8 bytes.
|
||||||
|
Name = StringRef(Sec->Name, 8);
|
||||||
|
|
||||||
|
// Check for string table entry. First byte is '/'.
|
||||||
|
if (Name[0] == '/') {
|
||||||
|
uint32_t Offset;
|
||||||
|
if (Name.substr(1).getAsInteger(10, Offset))
|
||||||
|
return object_error::parse_failed;
|
||||||
|
if (error_code ec = getString(Offset, Name))
|
||||||
|
return ec;
|
||||||
|
}
|
||||||
|
|
||||||
|
Res = Name;
|
||||||
|
return object_error::success;
|
||||||
|
}
|
||||||
|
|
||||||
const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const {
|
const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const {
|
||||||
return reinterpret_cast<const coff_relocation*>(Rel.p);
|
return reinterpret_cast<const coff_relocation*>(Rel.p);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user