From ba664c1d047a7ec1ac86adaf178bf829cdfd5961 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Fri, 10 Nov 2017 22:27:41 +0000 Subject: [PATCH] [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 --- llvm/lib/Object/WindowsResource.cpp | 19 +++++-------------- llvm/test/tools/llvm-cvtres/machine.test | 15 +++++++++++++++ llvm/tools/llvm-cvtres/llvm-cvtres.cpp | 4 ++++ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Object/WindowsResource.cpp b/llvm/lib/Object/WindowsResource.cpp index 693494a..b844955 100644 --- a/llvm/lib/Object/WindowsResource.cpp +++ b/llvm/lib/Object/WindowsResource.cpp @@ -441,19 +441,7 @@ std::unique_ptr WindowsResourceCOFFWriter::write() { void WindowsResourceCOFFWriter::writeCOFFHeader() { // Write the COFF header. auto *Header = reinterpret_cast(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); } diff --git a/llvm/test/tools/llvm-cvtres/machine.test b/llvm/test/tools/llvm-cvtres/machine.test index 58096d1..cac3606 100644 --- a/llvm/test/tools/llvm-cvtres/machine.test +++ b/llvm/test/tools/llvm-cvtres/machine.test @@ -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 diff --git a/llvm/tools/llvm-cvtres/llvm-cvtres.cpp b/llvm/tools/llvm-cvtres/llvm-cvtres.cpp index 433a75f..2f33afd 100644 --- a/llvm/tools/llvm-cvtres/llvm-cvtres.cpp +++ b/llvm/tools/llvm-cvtres/llvm-cvtres.cpp @@ -126,6 +126,7 @@ int main(int argc_, const char *argv_[]) { std::string MachineString = InputArgs.getLastArgValue(OPT_MACHINE).upper(); MachineType = StringSwitch(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; -- 2.7.4