[llvm-cvtres] Add support for ARM64

Also change some default cases into llvm_unreachable in
WindowsResourceCOFFWriter, to make it easier to find if they
are triggerd from within e.g. lld, which supported ARM64 earlier
than llvm-cvtres did.

Differential Revision: https://reviews.llvm.org/D39892

llvm-svn: 317942
This commit is contained in:
Martin Storsjo 2017-11-10 22:27:41 +00:00
parent 2861b61472
commit 89757c2b38
3 changed files with 24 additions and 14 deletions

View File

@ -441,19 +441,7 @@ std::unique_ptr<MemoryBuffer> WindowsResourceCOFFWriter::write() {
void WindowsResourceCOFFWriter::writeCOFFHeader() {
// Write the COFF header.
auto *Header = reinterpret_cast<coff_file_header *>(BufferStart);
switch (MachineType) {
case COFF::IMAGE_FILE_MACHINE_ARMNT:
Header->Machine = COFF::IMAGE_FILE_MACHINE_ARMNT;
break;
case COFF::IMAGE_FILE_MACHINE_AMD64:
Header->Machine = COFF::IMAGE_FILE_MACHINE_AMD64;
break;
case COFF::IMAGE_FILE_MACHINE_I386:
Header->Machine = COFF::IMAGE_FILE_MACHINE_I386;
break;
default:
Header->Machine = COFF::IMAGE_FILE_MACHINE_UNKNOWN;
}
Header->Machine = MachineType;
Header->NumberOfSections = 2;
Header->TimeDateStamp = getTime();
Header->PointerToSymbolTable = SymbolTableOffset;
@ -714,8 +702,11 @@ void WindowsResourceCOFFWriter::writeFirstSectionRelocations() {
case COFF::IMAGE_FILE_MACHINE_I386:
Reloc->Type = COFF::IMAGE_REL_I386_DIR32NB;
break;
case COFF::IMAGE_FILE_MACHINE_ARM64:
Reloc->Type = COFF::IMAGE_REL_ARM64_ADDR32NB;
break;
default:
Reloc->Type = 0;
llvm_unreachable("unknown machine type");
}
CurrentOffset += sizeof(coff_relocation);
}

View File

@ -22,6 +22,9 @@ RUN: llvm-readobj -h -relocations %t | FileCheck %s -check-prefix=X64
RUN: llvm-cvtres /machine:ARM /out:%t %p/Inputs/test_resource.res
RUN: llvm-readobj -h -relocations %t | FileCheck %s -check-prefix=ARM
RUN: llvm-cvtres /machine:ARM64 /out:%t %p/Inputs/test_resource.res
RUN: llvm-readobj -h -relocations %t | FileCheck %s -check-prefix=ARM64
X86: Machine: IMAGE_FILE_MACHINE_I386 (0x14C)
X86-DAG: Relocations [
X86-DAG: .rsrc$01 {
@ -57,3 +60,15 @@ ARM-NEXT: 0x1D8 IMAGE_REL_ARM_ADDR32NB $R000698
ARM-NEXT: 0x1F8 IMAGE_REL_ARM_ADDR32NB $R000708
ARM-NEXT: 0x1B8 IMAGE_REL_ARM_ADDR32NB $R000720
ARM-NEXT: 0x188 IMAGE_REL_ARM_ADDR32NB $R000750
ARM64: Machine: IMAGE_FILE_MACHINE_ARM64 (0xAA64)
ARM64-DAG: Relocations [
ARM64-DAG: .rsrc$01 {
ARM64-NEXT: 0x1E8 IMAGE_REL_ARM64_ADDR32NB $R000000
ARM64-NEXT: 0x198 IMAGE_REL_ARM64_ADDR32NB $R000018
ARM64-NEXT: 0x1A8 IMAGE_REL_ARM64_ADDR32NB $R000340
ARM64-NEXT: 0x1C8 IMAGE_REL_ARM64_ADDR32NB $R000668
ARM64-NEXT: 0x1D8 IMAGE_REL_ARM64_ADDR32NB $R000698
ARM64-NEXT: 0x1F8 IMAGE_REL_ARM64_ADDR32NB $R000708
ARM64-NEXT: 0x1B8 IMAGE_REL_ARM64_ADDR32NB $R000720
ARM64-NEXT: 0x188 IMAGE_REL_ARM64_ADDR32NB $R000750

View File

@ -126,6 +126,7 @@ int main(int argc_, const char *argv_[]) {
std::string MachineString = InputArgs.getLastArgValue(OPT_MACHINE).upper();
MachineType = StringSwitch<COFF::MachineTypes>(MachineString)
.Case("ARM", COFF::IMAGE_FILE_MACHINE_ARMNT)
.Case("ARM64", COFF::IMAGE_FILE_MACHINE_ARM64)
.Case("X64", COFF::IMAGE_FILE_MACHINE_AMD64)
.Case("X86", COFF::IMAGE_FILE_MACHINE_I386)
.Default(COFF::IMAGE_FILE_MACHINE_UNKNOWN);
@ -155,6 +156,9 @@ int main(int argc_, const char *argv_[]) {
if (Verbose) {
outs() << "Machine: ";
switch (MachineType) {
case COFF::IMAGE_FILE_MACHINE_ARM64:
outs() << "ARM64\n";
break;
case COFF::IMAGE_FILE_MACHINE_ARMNT:
outs() << "ARM\n";
break;