mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-27 13:40:30 +00:00
Hopefully one last commit to fix this patch, addresses string reference
issues. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302401 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a2514b9f9e
commit
20c59f10e5
@ -22,6 +22,7 @@
|
|||||||
#include "llvm/Object/ObjectFile.h"
|
#include "llvm/Object/ObjectFile.h"
|
||||||
#include "llvm/Support/BinaryByteStream.h"
|
#include "llvm/Support/BinaryByteStream.h"
|
||||||
#include "llvm/Support/COFF.h"
|
#include "llvm/Support/COFF.h"
|
||||||
|
#include "llvm/Support/ConvertUTF.h"
|
||||||
#include "llvm/Support/Endian.h"
|
#include "llvm/Support/Endian.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/ErrorOr.h"
|
#include "llvm/Support/ErrorOr.h"
|
||||||
@ -1074,7 +1075,7 @@ public:
|
|||||||
ResourceSectionRef() = default;
|
ResourceSectionRef() = default;
|
||||||
explicit ResourceSectionRef(StringRef Ref) : BBS(Ref, support::little) {}
|
explicit ResourceSectionRef(StringRef Ref) : BBS(Ref, support::little) {}
|
||||||
|
|
||||||
ErrorOr<StringRef> getEntryNameString(const coff_resource_dir_entry &Entry);
|
ErrorOr<ArrayRef<UTF16>> getEntryNameString(const coff_resource_dir_entry &Entry);
|
||||||
ErrorOr<const coff_resource_dir_table &>
|
ErrorOr<const coff_resource_dir_table &>
|
||||||
getEntrySubDir(const coff_resource_dir_entry &Entry);
|
getEntrySubDir(const coff_resource_dir_entry &Entry);
|
||||||
ErrorOr<const coff_resource_dir_table &> getBaseTable();
|
ErrorOr<const coff_resource_dir_table &> getBaseTable();
|
||||||
@ -1083,7 +1084,7 @@ private:
|
|||||||
BinaryByteStream BBS;
|
BinaryByteStream BBS;
|
||||||
|
|
||||||
ErrorOr<const coff_resource_dir_table &> getTableAtOffset(uint32_t Offset);
|
ErrorOr<const coff_resource_dir_table &> getTableAtOffset(uint32_t Offset);
|
||||||
ErrorOr<StringRef> getDirStringAtOffset(uint32_t Offset);
|
ErrorOr<ArrayRef<UTF16>> getDirStringAtOffset(uint32_t Offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Corresponds to `_FPO_DATA` structure in the PE/COFF spec.
|
// Corresponds to `_FPO_DATA` structure in the PE/COFF spec.
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include "llvm/Object/ObjectFile.h"
|
#include "llvm/Object/ObjectFile.h"
|
||||||
#include "llvm/Support/BinaryStreamReader.h"
|
#include "llvm/Support/BinaryStreamReader.h"
|
||||||
#include "llvm/Support/COFF.h"
|
#include "llvm/Support/COFF.h"
|
||||||
#include "llvm/Support/ConvertUTF.h"
|
|
||||||
#include "llvm/Support/Endian.h"
|
#include "llvm/Support/Endian.h"
|
||||||
#include "llvm/Support/Error.h"
|
#include "llvm/Support/Error.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
@ -1597,7 +1596,7 @@ std::error_code BaseRelocRef::getRVA(uint32_t &Result) const {
|
|||||||
if (auto EC = errorToErrorCode(X)) \
|
if (auto EC = errorToErrorCode(X)) \
|
||||||
return EC;
|
return EC;
|
||||||
|
|
||||||
ErrorOr<StringRef> ResourceSectionRef::getDirStringAtOffset(uint32_t Offset) {
|
ErrorOr<ArrayRef<UTF16>> ResourceSectionRef::getDirStringAtOffset(uint32_t Offset) {
|
||||||
BinaryStreamReader Reader = BinaryStreamReader(BBS);
|
BinaryStreamReader Reader = BinaryStreamReader(BBS);
|
||||||
Reader.setOffset(Offset);
|
Reader.setOffset(Offset);
|
||||||
uint16_t Length;
|
uint16_t Length;
|
||||||
@ -1606,13 +1605,10 @@ ErrorOr<StringRef> ResourceSectionRef::getDirStringAtOffset(uint32_t Offset) {
|
|||||||
// Strings are stored as 2-byte aligned unicode characters but readFixedString
|
// Strings are stored as 2-byte aligned unicode characters but readFixedString
|
||||||
// assumes byte string, so we double length.
|
// assumes byte string, so we double length.
|
||||||
RETURN_IF_ERROR(Reader.readArray(RawDirString, Length));
|
RETURN_IF_ERROR(Reader.readArray(RawDirString, Length));
|
||||||
std::string DirString;
|
return RawDirString;
|
||||||
if (!llvm::convertUTF16ToUTF8String(RawDirString, DirString))
|
|
||||||
return object_error::parse_failed;
|
|
||||||
return DirString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<StringRef>
|
ErrorOr<ArrayRef<UTF16>>
|
||||||
ResourceSectionRef::getEntryNameString(const coff_resource_dir_entry &Entry) {
|
ResourceSectionRef::getEntryNameString(const coff_resource_dir_entry &Entry) {
|
||||||
return getDirStringAtOffset(Entry.Identifier.getNameOffset());
|
return getDirStringAtOffset(Entry.Identifier.getNameOffset());
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#include "llvm/Support/BinaryByteStream.h"
|
#include "llvm/Support/BinaryByteStream.h"
|
||||||
#include "llvm/Support/BinaryStreamReader.h"
|
#include "llvm/Support/BinaryStreamReader.h"
|
||||||
#include "llvm/Support/COFF.h"
|
#include "llvm/Support/COFF.h"
|
||||||
|
#include "llvm/Support/ConvertUTF.h"
|
||||||
#include "llvm/Support/Casting.h"
|
#include "llvm/Support/Casting.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Support/DataExtractor.h"
|
#include "llvm/Support/DataExtractor.h"
|
||||||
@ -1560,9 +1561,12 @@ void COFFDumper::printResourceDirectoryTable(
|
|||||||
SmallString<20> IDStr;
|
SmallString<20> IDStr;
|
||||||
raw_svector_ostream OS(IDStr);
|
raw_svector_ostream OS(IDStr);
|
||||||
if (i < Table.NumberOfNameEntries) {
|
if (i < Table.NumberOfNameEntries) {
|
||||||
StringRef EntryNameString = unwrapOrError(RSF.getEntryNameString(Entry));
|
ArrayRef<UTF16> RawEntryNameString = unwrapOrError(RSF.getEntryNameString(Entry));
|
||||||
|
std::string EntryNameString;
|
||||||
|
if (!llvm::convertUTF16ToUTF8String(RawEntryNameString, EntryNameString))
|
||||||
|
error(object_error::parse_failed);
|
||||||
OS << ": ";
|
OS << ": ";
|
||||||
OS << EntryNameString.str();
|
OS << EntryNameString;
|
||||||
} else {
|
} else {
|
||||||
if (Level == "Type") {
|
if (Level == "Type") {
|
||||||
ScopedPrinter Printer(OS);
|
ScopedPrinter Printer(OS);
|
||||||
@ -1594,7 +1598,7 @@ void COFFDumper::printResourceDirectoryTable(
|
|||||||
ErrorOr<const coff_resource_dir_entry &>
|
ErrorOr<const coff_resource_dir_entry &>
|
||||||
COFFDumper::getResourceDirectoryTableEntry(const coff_resource_dir_table &Table,
|
COFFDumper::getResourceDirectoryTableEntry(const coff_resource_dir_table &Table,
|
||||||
uint32_t Index) {
|
uint32_t Index) {
|
||||||
if (Index >= Table.NumberOfNameEntries + Table.NumberOfIDEntries)
|
if (Index >= (uint32_t)(Table.NumberOfNameEntries + Table.NumberOfIDEntries))
|
||||||
return object_error::parse_failed;
|
return object_error::parse_failed;
|
||||||
auto TablePtr = reinterpret_cast<const coff_resource_dir_entry *>(&Table + 1);
|
auto TablePtr = reinterpret_cast<const coff_resource_dir_entry *>(&Table + 1);
|
||||||
return TablePtr[Index];
|
return TablePtr[Index];
|
||||||
|
Loading…
Reference in New Issue
Block a user