forked from OSchip/llvm-project
Clean up some things in the WindowsResource changes.
llvm-svn: 305596
This commit is contained in:
parent
74b4ded0c2
commit
7687f04672
|
@ -30,7 +30,6 @@
|
|||
#define LLVM_INCLUDE_LLVM_OBJECT_RESFILE_H
|
||||
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/BinaryFormat/COFF.h"
|
||||
#include "llvm/Object/Binary.h"
|
||||
#include "llvm/Object/Error.h"
|
||||
|
@ -44,7 +43,6 @@
|
|||
#include <map>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
namespace object {
|
||||
|
||||
class WindowsResource;
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Object/WindowsResource.h"
|
||||
#include "llvm/BinaryFormat/COFF.h"
|
||||
#include "llvm/Object/COFF.h"
|
||||
#include "llvm/Support/FileOutputBuffer.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
|
@ -22,6 +21,7 @@
|
|||
#include <system_error>
|
||||
|
||||
using namespace llvm;
|
||||
using namespace object;
|
||||
|
||||
namespace llvm {
|
||||
namespace object {
|
||||
|
@ -248,14 +248,14 @@ WindowsResourceParser::TreeNode::addChild(ArrayRef<UTF16> NameRef,
|
|||
std::string NameString;
|
||||
ArrayRef<UTF16> CorrectedName;
|
||||
std::vector<UTF16> EndianCorrectedName;
|
||||
if (llvm::sys::IsBigEndianHost) {
|
||||
if (sys::IsBigEndianHost) {
|
||||
EndianCorrectedName.resize(NameRef.size() + 1);
|
||||
std::copy(NameRef.begin(), NameRef.end(), EndianCorrectedName.begin() + 1);
|
||||
EndianCorrectedName[0] = UNI_UTF16_BYTE_ORDER_MARK_SWAPPED;
|
||||
CorrectedName = makeArrayRef(EndianCorrectedName);
|
||||
} else
|
||||
CorrectedName = NameRef;
|
||||
llvm::convertUTF16ToUTF8String(CorrectedName, NameString);
|
||||
convertUTF16ToUTF8String(CorrectedName, NameString);
|
||||
|
||||
auto Child = StringChildren.find(NameString);
|
||||
if (Child == StringChildren.end()) {
|
||||
|
@ -284,17 +284,17 @@ void WindowsResourceParser::TreeNode::print(ScopedPrinter &Writer,
|
|||
// the directory strings or the relocations of the .rsrc section.
|
||||
uint32_t WindowsResourceParser::TreeNode::getTreeSize() const {
|
||||
uint32_t Size = (IDChildren.size() + StringChildren.size()) *
|
||||
sizeof(llvm::object::coff_resource_dir_entry);
|
||||
sizeof(coff_resource_dir_entry);
|
||||
|
||||
// Reached a node pointing to a data entry.
|
||||
if (IsDataNode) {
|
||||
Size += sizeof(llvm::object::coff_resource_data_entry);
|
||||
Size += sizeof(coff_resource_data_entry);
|
||||
return Size;
|
||||
}
|
||||
|
||||
// If the node does not point to data, it must have a directory table pointing
|
||||
// to other nodes.
|
||||
Size += sizeof(llvm::object::coff_resource_dir_table);
|
||||
Size += sizeof(coff_resource_dir_table);
|
||||
|
||||
for (auto const &Child : StringChildren) {
|
||||
Size += Child.second->getTreeSize();
|
||||
|
@ -358,10 +358,10 @@ WindowsResourceCOFFWriter::WindowsResourceCOFFWriter(
|
|||
|
||||
void WindowsResourceCOFFWriter::performFileLayout() {
|
||||
// Add size of COFF header.
|
||||
FileSize = llvm::COFF::Header16Size;
|
||||
FileSize = COFF::Header16Size;
|
||||
|
||||
// one .rsrc section header for directory tree, another for resource data.
|
||||
FileSize += 2 * llvm::COFF::SectionSize;
|
||||
FileSize += 2 * COFF::SectionSize;
|
||||
|
||||
performSectionOneLayout();
|
||||
performSectionTwoLayout();
|
||||
|
@ -369,9 +369,9 @@ void WindowsResourceCOFFWriter::performFileLayout() {
|
|||
// We have reached the address of the symbol table.
|
||||
SymbolTableOffset = FileSize;
|
||||
|
||||
FileSize += llvm::COFF::Symbol16Size; // size of the @feat.00 symbol.
|
||||
FileSize += 4 * llvm::COFF::Symbol16Size; // symbol + aux for each section.
|
||||
FileSize += Data.size() * llvm::COFF::Symbol16Size; // 1 symbol per resource.
|
||||
FileSize += COFF::Symbol16Size; // size of the @feat.00 symbol.
|
||||
FileSize += 4 * COFF::Symbol16Size; // symbol + aux for each section.
|
||||
FileSize += Data.size() * COFF::Symbol16Size; // 1 symbol per resource.
|
||||
FileSize += 4; // four null bytes for the string table.
|
||||
}
|
||||
|
||||
|
@ -392,8 +392,8 @@ void WindowsResourceCOFFWriter::performSectionOneLayout() {
|
|||
// account for the relocations of section one.
|
||||
SectionOneRelocations = FileSize + SectionOneSize;
|
||||
FileSize += SectionOneSize;
|
||||
FileSize += Data.size() *
|
||||
llvm::COFF::RelocationSize; // one relocation for each resource.
|
||||
FileSize +=
|
||||
Data.size() * COFF::RelocationSize; // one relocation for each resource.
|
||||
FileSize = alignTo(FileSize, SECTION_ALIGNMENT);
|
||||
}
|
||||
|
||||
|
@ -404,7 +404,7 @@ void WindowsResourceCOFFWriter::performSectionTwoLayout() {
|
|||
SectionTwoSize = 0;
|
||||
for (auto const &Entry : Data) {
|
||||
DataOffsets.push_back(SectionTwoSize);
|
||||
SectionTwoSize += llvm::alignTo(Entry.size(), sizeof(uint64_t));
|
||||
SectionTwoSize += alignTo(Entry.size(), sizeof(uint64_t));
|
||||
}
|
||||
FileSize += SectionTwoSize;
|
||||
FileSize = alignTo(FileSize, SECTION_ALIGNMENT);
|
||||
|
@ -433,20 +433,19 @@ Error WindowsResourceCOFFWriter::write() {
|
|||
|
||||
void WindowsResourceCOFFWriter::writeCOFFHeader() {
|
||||
// Write the COFF header.
|
||||
auto *Header =
|
||||
reinterpret_cast<llvm::object::coff_file_header *>(BufferStart);
|
||||
auto *Header = reinterpret_cast<coff_file_header *>(BufferStart);
|
||||
switch (MachineType) {
|
||||
case COFF::IMAGE_FILE_MACHINE_ARMNT:
|
||||
Header->Machine = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT;
|
||||
Header->Machine = COFF::IMAGE_FILE_MACHINE_ARMNT;
|
||||
break;
|
||||
case COFF::IMAGE_FILE_MACHINE_AMD64:
|
||||
Header->Machine = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
|
||||
Header->Machine = COFF::IMAGE_FILE_MACHINE_AMD64;
|
||||
break;
|
||||
case COFF::IMAGE_FILE_MACHINE_I386:
|
||||
Header->Machine = llvm::COFF::IMAGE_FILE_MACHINE_I386;
|
||||
Header->Machine = COFF::IMAGE_FILE_MACHINE_I386;
|
||||
break;
|
||||
default:
|
||||
Header->Machine = llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
|
||||
Header->Machine = COFF::IMAGE_FILE_MACHINE_UNKNOWN;
|
||||
}
|
||||
Header->NumberOfSections = 2;
|
||||
Header->TimeDateStamp = getTime();
|
||||
|
@ -454,15 +453,15 @@ void WindowsResourceCOFFWriter::writeCOFFHeader() {
|
|||
// One symbol for every resource plus 2 for each section and @feat.00
|
||||
Header->NumberOfSymbols = Data.size() + 5;
|
||||
Header->SizeOfOptionalHeader = 0;
|
||||
Header->Characteristics = llvm::COFF::IMAGE_FILE_32BIT_MACHINE;
|
||||
Header->Characteristics = COFF::IMAGE_FILE_32BIT_MACHINE;
|
||||
}
|
||||
|
||||
void WindowsResourceCOFFWriter::writeFirstSectionHeader() {
|
||||
// Write the first section header.
|
||||
CurrentOffset += sizeof(llvm::object::coff_file_header);
|
||||
auto *SectionOneHeader = reinterpret_cast<llvm::object::coff_section *>(
|
||||
BufferStart + CurrentOffset);
|
||||
strncpy(SectionOneHeader->Name, ".rsrc$01", (size_t)llvm::COFF::NameSize);
|
||||
CurrentOffset += sizeof(coff_file_header);
|
||||
auto *SectionOneHeader =
|
||||
reinterpret_cast<coff_section *>(BufferStart + CurrentOffset);
|
||||
strncpy(SectionOneHeader->Name, ".rsrc$01", (size_t)COFF::NameSize);
|
||||
SectionOneHeader->VirtualSize = 0;
|
||||
SectionOneHeader->VirtualAddress = 0;
|
||||
SectionOneHeader->SizeOfRawData = SectionOneSize;
|
||||
|
@ -471,20 +470,18 @@ void WindowsResourceCOFFWriter::writeFirstSectionHeader() {
|
|||
SectionOneHeader->PointerToLinenumbers = 0;
|
||||
SectionOneHeader->NumberOfRelocations = Data.size();
|
||||
SectionOneHeader->NumberOfLinenumbers = 0;
|
||||
SectionOneHeader->Characteristics = llvm::COFF::IMAGE_SCN_ALIGN_1BYTES;
|
||||
SectionOneHeader->Characteristics +=
|
||||
llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
|
||||
SectionOneHeader->Characteristics +=
|
||||
llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
|
||||
SectionOneHeader->Characteristics += llvm::COFF::IMAGE_SCN_MEM_READ;
|
||||
SectionOneHeader->Characteristics = COFF::IMAGE_SCN_ALIGN_1BYTES;
|
||||
SectionOneHeader->Characteristics += COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
|
||||
SectionOneHeader->Characteristics += COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
|
||||
SectionOneHeader->Characteristics += COFF::IMAGE_SCN_MEM_READ;
|
||||
}
|
||||
|
||||
void WindowsResourceCOFFWriter::writeSecondSectionHeader() {
|
||||
// Write the second section header.
|
||||
CurrentOffset += sizeof(llvm::object::coff_section);
|
||||
auto *SectionTwoHeader = reinterpret_cast<llvm::object::coff_section *>(
|
||||
BufferStart + CurrentOffset);
|
||||
strncpy(SectionTwoHeader->Name, ".rsrc$02", (size_t)llvm::COFF::NameSize);
|
||||
CurrentOffset += sizeof(coff_section);
|
||||
auto *SectionTwoHeader =
|
||||
reinterpret_cast<coff_section *>(BufferStart + CurrentOffset);
|
||||
strncpy(SectionTwoHeader->Name, ".rsrc$02", (size_t)COFF::NameSize);
|
||||
SectionTwoHeader->VirtualSize = 0;
|
||||
SectionTwoHeader->VirtualAddress = 0;
|
||||
SectionTwoHeader->SizeOfRawData = SectionTwoSize;
|
||||
|
@ -493,14 +490,13 @@ void WindowsResourceCOFFWriter::writeSecondSectionHeader() {
|
|||
SectionTwoHeader->PointerToLinenumbers = 0;
|
||||
SectionTwoHeader->NumberOfRelocations = 0;
|
||||
SectionTwoHeader->NumberOfLinenumbers = 0;
|
||||
SectionTwoHeader->Characteristics =
|
||||
llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
|
||||
SectionTwoHeader->Characteristics += llvm::COFF::IMAGE_SCN_MEM_READ;
|
||||
SectionTwoHeader->Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
|
||||
SectionTwoHeader->Characteristics += COFF::IMAGE_SCN_MEM_READ;
|
||||
}
|
||||
|
||||
void WindowsResourceCOFFWriter::writeFirstSection() {
|
||||
// Write section one.
|
||||
CurrentOffset += sizeof(llvm::object::coff_section);
|
||||
CurrentOffset += sizeof(coff_section);
|
||||
|
||||
writeDirectoryTree();
|
||||
writeDirectoryStringTable();
|
||||
|
@ -523,70 +519,65 @@ void WindowsResourceCOFFWriter::writeSecondSection() {
|
|||
void WindowsResourceCOFFWriter::writeSymbolTable() {
|
||||
// Now write the symbol table.
|
||||
// First, the feat symbol.
|
||||
auto *Symbol = reinterpret_cast<llvm::object::coff_symbol16 *>(BufferStart +
|
||||
CurrentOffset);
|
||||
strncpy(Symbol->Name.ShortName, "@feat.00", (size_t)llvm::COFF::NameSize);
|
||||
auto *Symbol = reinterpret_cast<coff_symbol16 *>(BufferStart + CurrentOffset);
|
||||
strncpy(Symbol->Name.ShortName, "@feat.00", (size_t)COFF::NameSize);
|
||||
Symbol->Value = 0x11;
|
||||
Symbol->SectionNumber = 0xffff;
|
||||
Symbol->Type = llvm::COFF::IMAGE_SYM_DTYPE_NULL;
|
||||
Symbol->StorageClass = llvm::COFF::IMAGE_SYM_CLASS_STATIC;
|
||||
Symbol->Type = COFF::IMAGE_SYM_DTYPE_NULL;
|
||||
Symbol->StorageClass = COFF::IMAGE_SYM_CLASS_STATIC;
|
||||
Symbol->NumberOfAuxSymbols = 0;
|
||||
CurrentOffset += sizeof(llvm::object::coff_symbol16);
|
||||
CurrentOffset += sizeof(coff_symbol16);
|
||||
|
||||
// Now write the .rsrc1 symbol + aux.
|
||||
Symbol = reinterpret_cast<llvm::object::coff_symbol16 *>(BufferStart +
|
||||
CurrentOffset);
|
||||
strncpy(Symbol->Name.ShortName, ".rsrc$01", (size_t)llvm::COFF::NameSize);
|
||||
Symbol = reinterpret_cast<coff_symbol16 *>(BufferStart + CurrentOffset);
|
||||
strncpy(Symbol->Name.ShortName, ".rsrc$01", (size_t)COFF::NameSize);
|
||||
Symbol->Value = 0;
|
||||
Symbol->SectionNumber = 1;
|
||||
Symbol->Type = llvm::COFF::IMAGE_SYM_DTYPE_NULL;
|
||||
Symbol->StorageClass = llvm::COFF::IMAGE_SYM_CLASS_STATIC;
|
||||
Symbol->Type = COFF::IMAGE_SYM_DTYPE_NULL;
|
||||
Symbol->StorageClass = COFF::IMAGE_SYM_CLASS_STATIC;
|
||||
Symbol->NumberOfAuxSymbols = 1;
|
||||
CurrentOffset += sizeof(llvm::object::coff_symbol16);
|
||||
auto *Aux = reinterpret_cast<llvm::object::coff_aux_section_definition *>(
|
||||
BufferStart + CurrentOffset);
|
||||
CurrentOffset += sizeof(coff_symbol16);
|
||||
auto *Aux = reinterpret_cast<coff_aux_section_definition *>(BufferStart +
|
||||
CurrentOffset);
|
||||
Aux->Length = SectionOneSize;
|
||||
Aux->NumberOfRelocations = Data.size();
|
||||
Aux->NumberOfLinenumbers = 0;
|
||||
Aux->CheckSum = 0;
|
||||
Aux->NumberLowPart = 0;
|
||||
Aux->Selection = 0;
|
||||
CurrentOffset += sizeof(llvm::object::coff_aux_section_definition);
|
||||
CurrentOffset += sizeof(coff_aux_section_definition);
|
||||
|
||||
// Now write the .rsrc2 symbol + aux.
|
||||
Symbol = reinterpret_cast<llvm::object::coff_symbol16 *>(BufferStart +
|
||||
CurrentOffset);
|
||||
strncpy(Symbol->Name.ShortName, ".rsrc$02", (size_t)llvm::COFF::NameSize);
|
||||
Symbol = reinterpret_cast<coff_symbol16 *>(BufferStart + CurrentOffset);
|
||||
strncpy(Symbol->Name.ShortName, ".rsrc$02", (size_t)COFF::NameSize);
|
||||
Symbol->Value = 0;
|
||||
Symbol->SectionNumber = 2;
|
||||
Symbol->Type = llvm::COFF::IMAGE_SYM_DTYPE_NULL;
|
||||
Symbol->StorageClass = llvm::COFF::IMAGE_SYM_CLASS_STATIC;
|
||||
Symbol->Type = COFF::IMAGE_SYM_DTYPE_NULL;
|
||||
Symbol->StorageClass = COFF::IMAGE_SYM_CLASS_STATIC;
|
||||
Symbol->NumberOfAuxSymbols = 1;
|
||||
CurrentOffset += sizeof(llvm::object::coff_symbol16);
|
||||
Aux = reinterpret_cast<llvm::object::coff_aux_section_definition *>(
|
||||
BufferStart + CurrentOffset);
|
||||
CurrentOffset += sizeof(coff_symbol16);
|
||||
Aux = reinterpret_cast<coff_aux_section_definition *>(BufferStart +
|
||||
CurrentOffset);
|
||||
Aux->Length = SectionTwoSize;
|
||||
Aux->NumberOfRelocations = 0;
|
||||
Aux->NumberOfLinenumbers = 0;
|
||||
Aux->CheckSum = 0;
|
||||
Aux->NumberLowPart = 0;
|
||||
Aux->Selection = 0;
|
||||
CurrentOffset += sizeof(llvm::object::coff_aux_section_definition);
|
||||
CurrentOffset += sizeof(coff_aux_section_definition);
|
||||
|
||||
// Now write a symbol for each relocation.
|
||||
for (unsigned i = 0; i < Data.size(); i++) {
|
||||
char RelocationName[9];
|
||||
sprintf(RelocationName, "$R%06X", DataOffsets[i]);
|
||||
Symbol = reinterpret_cast<llvm::object::coff_symbol16 *>(BufferStart +
|
||||
CurrentOffset);
|
||||
strncpy(Symbol->Name.ShortName, RelocationName,
|
||||
(size_t)llvm::COFF::NameSize);
|
||||
Symbol = reinterpret_cast<coff_symbol16 *>(BufferStart + CurrentOffset);
|
||||
strncpy(Symbol->Name.ShortName, RelocationName, (size_t)COFF::NameSize);
|
||||
Symbol->Value = DataOffsets[i];
|
||||
Symbol->SectionNumber = 1;
|
||||
Symbol->Type = llvm::COFF::IMAGE_SYM_DTYPE_NULL;
|
||||
Symbol->StorageClass = llvm::COFF::IMAGE_SYM_CLASS_STATIC;
|
||||
Symbol->Type = COFF::IMAGE_SYM_DTYPE_NULL;
|
||||
Symbol->StorageClass = COFF::IMAGE_SYM_CLASS_STATIC;
|
||||
Symbol->NumberOfAuxSymbols = 0;
|
||||
CurrentOffset += sizeof(llvm::object::coff_symbol16);
|
||||
CurrentOffset += sizeof(coff_symbol16);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -601,18 +592,18 @@ void WindowsResourceCOFFWriter::writeDirectoryTree() {
|
|||
// COFF objects.
|
||||
std::queue<const WindowsResourceParser::TreeNode *> Queue;
|
||||
Queue.push(&Resources);
|
||||
uint32_t NextLevelOffset = sizeof(llvm::object::coff_resource_dir_table) +
|
||||
(Resources.getStringChildren().size() +
|
||||
Resources.getIDChildren().size()) *
|
||||
sizeof(llvm::object::coff_resource_dir_entry);
|
||||
uint32_t NextLevelOffset =
|
||||
sizeof(coff_resource_dir_table) + (Resources.getStringChildren().size() +
|
||||
Resources.getIDChildren().size()) *
|
||||
sizeof(coff_resource_dir_entry);
|
||||
std::vector<const WindowsResourceParser::TreeNode *> DataEntriesTreeOrder;
|
||||
uint32_t CurrentRelativeOffset = 0;
|
||||
|
||||
while (!Queue.empty()) {
|
||||
auto CurrentNode = Queue.front();
|
||||
Queue.pop();
|
||||
auto *Table = reinterpret_cast<llvm::object::coff_resource_dir_table *>(
|
||||
BufferStart + CurrentOffset);
|
||||
auto *Table = reinterpret_cast<coff_resource_dir_table *>(BufferStart +
|
||||
CurrentOffset);
|
||||
Table->Characteristics = CurrentNode->getCharacteristics();
|
||||
Table->TimeDateStamp = 0;
|
||||
Table->MajorVersion = CurrentNode->getMajorVersion();
|
||||
|
@ -621,63 +612,63 @@ void WindowsResourceCOFFWriter::writeDirectoryTree() {
|
|||
auto &StringChildren = CurrentNode->getStringChildren();
|
||||
Table->NumberOfNameEntries = StringChildren.size();
|
||||
Table->NumberOfIDEntries = IDChildren.size();
|
||||
CurrentOffset += sizeof(llvm::object::coff_resource_dir_table);
|
||||
CurrentRelativeOffset += sizeof(llvm::object::coff_resource_dir_table);
|
||||
CurrentOffset += sizeof(coff_resource_dir_table);
|
||||
CurrentRelativeOffset += sizeof(coff_resource_dir_table);
|
||||
|
||||
// Write the directory entries immediately following each directory table.
|
||||
for (auto const &Child : StringChildren) {
|
||||
auto *Entry = reinterpret_cast<llvm::object::coff_resource_dir_entry *>(
|
||||
BufferStart + CurrentOffset);
|
||||
auto *Entry = reinterpret_cast<coff_resource_dir_entry *>(BufferStart +
|
||||
CurrentOffset);
|
||||
Entry->Identifier.NameOffset =
|
||||
StringTableOffsets[Child.second->getStringIndex()];
|
||||
if (Child.second->checkIsDataNode()) {
|
||||
Entry->Offset.DataEntryOffset = NextLevelOffset;
|
||||
NextLevelOffset += sizeof(llvm::object::coff_resource_data_entry);
|
||||
NextLevelOffset += sizeof(coff_resource_data_entry);
|
||||
DataEntriesTreeOrder.push_back(Child.second.get());
|
||||
} else {
|
||||
Entry->Offset.SubdirOffset = NextLevelOffset + (1 << 31);
|
||||
NextLevelOffset += sizeof(llvm::object::coff_resource_dir_table) +
|
||||
NextLevelOffset += sizeof(coff_resource_dir_table) +
|
||||
(Child.second->getStringChildren().size() +
|
||||
Child.second->getIDChildren().size()) *
|
||||
sizeof(llvm::object::coff_resource_dir_entry);
|
||||
sizeof(coff_resource_dir_entry);
|
||||
Queue.push(Child.second.get());
|
||||
}
|
||||
CurrentOffset += sizeof(llvm::object::coff_resource_dir_entry);
|
||||
CurrentRelativeOffset += sizeof(llvm::object::coff_resource_dir_entry);
|
||||
CurrentOffset += sizeof(coff_resource_dir_entry);
|
||||
CurrentRelativeOffset += sizeof(coff_resource_dir_entry);
|
||||
}
|
||||
for (auto const &Child : IDChildren) {
|
||||
auto *Entry = reinterpret_cast<llvm::object::coff_resource_dir_entry *>(
|
||||
BufferStart + CurrentOffset);
|
||||
auto *Entry = reinterpret_cast<coff_resource_dir_entry *>(BufferStart +
|
||||
CurrentOffset);
|
||||
Entry->Identifier.ID = Child.first;
|
||||
if (Child.second->checkIsDataNode()) {
|
||||
Entry->Offset.DataEntryOffset = NextLevelOffset;
|
||||
NextLevelOffset += sizeof(llvm::object::coff_resource_data_entry);
|
||||
NextLevelOffset += sizeof(coff_resource_data_entry);
|
||||
DataEntriesTreeOrder.push_back(Child.second.get());
|
||||
} else {
|
||||
Entry->Offset.SubdirOffset = NextLevelOffset + (1 << 31);
|
||||
NextLevelOffset += sizeof(llvm::object::coff_resource_dir_table) +
|
||||
NextLevelOffset += sizeof(coff_resource_dir_table) +
|
||||
(Child.second->getStringChildren().size() +
|
||||
Child.second->getIDChildren().size()) *
|
||||
sizeof(llvm::object::coff_resource_dir_entry);
|
||||
sizeof(coff_resource_dir_entry);
|
||||
Queue.push(Child.second.get());
|
||||
}
|
||||
CurrentOffset += sizeof(llvm::object::coff_resource_dir_entry);
|
||||
CurrentRelativeOffset += sizeof(llvm::object::coff_resource_dir_entry);
|
||||
CurrentOffset += sizeof(coff_resource_dir_entry);
|
||||
CurrentRelativeOffset += sizeof(coff_resource_dir_entry);
|
||||
}
|
||||
}
|
||||
|
||||
RelocationAddresses.resize(Data.size());
|
||||
// Now write all the resource data entries.
|
||||
for (auto DataNodes : DataEntriesTreeOrder) {
|
||||
auto *Entry = reinterpret_cast<llvm::object::coff_resource_data_entry *>(
|
||||
BufferStart + CurrentOffset);
|
||||
auto *Entry = reinterpret_cast<coff_resource_data_entry *>(BufferStart +
|
||||
CurrentOffset);
|
||||
RelocationAddresses[DataNodes->getDataIndex()] = CurrentRelativeOffset;
|
||||
Entry->DataRVA = 0; // Set to zero because it is a relocation.
|
||||
Entry->DataSize = Data[DataNodes->getDataIndex()].size();
|
||||
Entry->Codepage = 0;
|
||||
Entry->Reserved = 0;
|
||||
CurrentOffset += sizeof(llvm::object::coff_resource_data_entry);
|
||||
CurrentRelativeOffset += sizeof(llvm::object::coff_resource_data_entry);
|
||||
CurrentOffset += sizeof(coff_resource_data_entry);
|
||||
CurrentRelativeOffset += sizeof(coff_resource_data_entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -704,24 +695,24 @@ void WindowsResourceCOFFWriter::writeFirstSectionRelocations() {
|
|||
// .rsrc section.
|
||||
uint32_t NextSymbolIndex = 5;
|
||||
for (unsigned i = 0; i < Data.size(); i++) {
|
||||
auto *Reloc = reinterpret_cast<llvm::object::coff_relocation *>(
|
||||
BufferStart + CurrentOffset);
|
||||
auto *Reloc =
|
||||
reinterpret_cast<coff_relocation *>(BufferStart + CurrentOffset);
|
||||
Reloc->VirtualAddress = RelocationAddresses[i];
|
||||
Reloc->SymbolTableIndex = NextSymbolIndex++;
|
||||
switch (MachineType) {
|
||||
case COFF::IMAGE_FILE_MACHINE_ARMNT:
|
||||
Reloc->Type = llvm::COFF::IMAGE_REL_ARM_ADDR32NB;
|
||||
Reloc->Type = COFF::IMAGE_REL_ARM_ADDR32NB;
|
||||
break;
|
||||
case COFF::IMAGE_FILE_MACHINE_AMD64:
|
||||
Reloc->Type = llvm::COFF::IMAGE_REL_AMD64_ADDR32NB;
|
||||
Reloc->Type = COFF::IMAGE_REL_AMD64_ADDR32NB;
|
||||
break;
|
||||
case COFF::IMAGE_FILE_MACHINE_I386:
|
||||
Reloc->Type = llvm::COFF::IMAGE_REL_I386_DIR32NB;
|
||||
Reloc->Type = COFF::IMAGE_REL_I386_DIR32NB;
|
||||
break;
|
||||
default:
|
||||
Reloc->Type = 0;
|
||||
}
|
||||
CurrentOffset += sizeof(llvm::object::coff_relocation);
|
||||
CurrentOffset += sizeof(coff_relocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm-cvtres.h"
|
||||
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/Object/Binary.h"
|
||||
#include "llvm/Object/WindowsResource.h"
|
||||
|
@ -29,6 +27,8 @@
|
|||
#include "llvm/Support/Signals.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
#include <system_error>
|
||||
|
||||
using namespace llvm;
|
||||
using namespace object;
|
||||
|
||||
|
@ -142,8 +142,8 @@ int main(int argc_, const char *argv_[]) {
|
|||
if (InputArgs.hasArg(OPT_OUT)) {
|
||||
OutputFile = InputArgs.getLastArgValue(OPT_OUT);
|
||||
} else {
|
||||
OutputFile = llvm::sys::path::filename(StringRef(InputFiles[0]));
|
||||
llvm::sys::path::replace_extension(OutputFile, ".obj");
|
||||
OutputFile = sys::path::filename(StringRef(InputFiles[0]));
|
||||
sys::path::replace_extension(OutputFile, ".obj");
|
||||
}
|
||||
|
||||
if (Verbose) {
|
||||
|
@ -163,8 +163,7 @@ int main(int argc_, const char *argv_[]) {
|
|||
WindowsResourceParser Parser;
|
||||
|
||||
for (const auto &File : InputFiles) {
|
||||
Expected<object::OwningBinary<object::Binary>> BinaryOrErr =
|
||||
object::createBinary(File);
|
||||
Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(File);
|
||||
if (!BinaryOrErr)
|
||||
reportError(File, errorToErrorCode(BinaryOrErr.takeError()));
|
||||
|
||||
|
@ -193,7 +192,6 @@ int main(int argc_, const char *argv_[]) {
|
|||
|
||||
if (Verbose) {
|
||||
Parser.printTree(outs());
|
||||
Parser.printTree(errs());
|
||||
}
|
||||
|
||||
std::unique_ptr<MemoryBuffer> OutputBuffer;
|
||||
|
@ -209,8 +207,7 @@ int main(int argc_, const char *argv_[]) {
|
|||
error(FileBuffer->commit());
|
||||
|
||||
if (Verbose) {
|
||||
Expected<object::OwningBinary<object::Binary>> BinaryOrErr =
|
||||
object::createBinary(OutputFile);
|
||||
Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(OutputFile);
|
||||
if (!BinaryOrErr)
|
||||
reportError(OutputFile, errorToErrorCode(BinaryOrErr.takeError()));
|
||||
Binary &Binary = *BinaryOrErr.get().getBinary();
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
//===- llvm-cvtres.h ------------------------------------------ *- C++ --*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TOOLS_LLVMCVTRES_LLVMCVTRES_H
|
||||
#define LLVM_TOOLS_LLVMCVTRES_LLVMCVTRES_H
|
||||
|
||||
#include <system_error>
|
||||
|
||||
void error(std::error_code EC);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue