0xcc, 0xcc // INT 3; INT 3
};
+const uint8_t FuncAtomContentARMNT[] = {
+ 0x40, 0xf2, 0x00, 0x0c, // mov.w ip, #0
+ 0xc0, 0xf2, 0x00, 0x0c, // mov.t ip, #0
+ 0xdc, 0xf8, 0x00, 0xf0, // ldr.w pc, [ip]
+};
+
static void setJumpInstTarget(COFFLinkerInternalAtom *src, const Atom *dst,
int off, MachineTypes machine) {
COFFReference *ref;
+
switch (machine) {
+ default: llvm::report_fatal_error("unsupported machine type");
case llvm::COFF::IMAGE_FILE_MACHINE_I386:
ref = new COFFReference(dst, off, llvm::COFF::IMAGE_REL_I386_DIR32,
Reference::KindArch::x86);
ref = new COFFReference(dst, off, llvm::COFF::IMAGE_REL_AMD64_REL32,
Reference::KindArch::x86_64);
break;
- default:
- llvm::report_fatal_error("unsupported machine type");
+ case llvm::COFF::IMAGE_FILE_MACHINE_ARMNT:
+ ref = new COFFReference(dst, off, llvm::COFF::IMAGE_REL_ARM_MOV32T,
+ Reference::KindArch::ARM);
+ break;
}
+
src->addReference(std::unique_ptr<COFFReference>(ref));
}
public:
FuncAtom(const File &file, StringRef symbolName,
const COFFSharedLibraryAtom *impAtom, MachineTypes machine)
- : COFFLinkerInternalAtom(file, /*oridnal*/ 0, createContent(),
+ : COFFLinkerInternalAtom(file, /*oridnal*/ 0, createContent(machine),
symbolName) {
- setJumpInstTarget(this, impAtom, 2, machine);
+ size_t Offset;
+
+ switch (machine) {
+ default: llvm::report_fatal_error("unsupported machine type");
+ case llvm::COFF::IMAGE_FILE_MACHINE_I386:
+ case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
+ Offset = 2;
+ break;
+ case llvm::COFF::IMAGE_FILE_MACHINE_ARMNT:
+ Offset = 0;
+ break;
+ }
+
+ setJumpInstTarget(this, impAtom, Offset, machine);
}
uint64_t ordinal() const override { return 0; }
ContentPermissions permissions() const override { return permR_X; }
private:
- std::vector<uint8_t> createContent() const {
- return std::vector<uint8_t>(
- FuncAtomContentX86, FuncAtomContentX86 + sizeof(FuncAtomContentX86));
+ std::vector<uint8_t> createContent(MachineTypes machine) const {
+ const uint8_t *Data;
+ size_t Size;
+
+ switch (machine) {
+ default: llvm::report_fatal_error("unsupported machine type");
+ case llvm::COFF::IMAGE_FILE_MACHINE_I386:
+ case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
+ Data = FuncAtomContentX86;
+ Size = sizeof(FuncAtomContentX86);
+ break;
+ case llvm::COFF::IMAGE_FILE_MACHINE_ARMNT:
+ Data = FuncAtomContentARMNT;
+ Size = sizeof(FuncAtomContentARMNT);
+ break;
+ }
+
+ return std::vector<uint8_t>(Data, Data + Size);
}
};
--- /dev/null
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_ARMNT
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 40F20000C0F2000000680047
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: __imp_function
+ Type: 17
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 12
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: mainCRTStartup
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __imp_function
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...