[lld] r243202 - COFF: ARM: Implement BRANCH24T relocation.
Rui Ueyama
ruiu at google.com
Fri Jul 24 20:19:35 PDT 2015
Author: ruiu
Date: Fri Jul 24 22:19:34 2015
New Revision: 243202
URL: http://llvm.org/viewvc/llvm-project?rev=243202&view=rev
Log:
COFF: ARM: Implement BRANCH24T relocation.
Added:
lld/trunk/test/COFF/armnt-branch24t.test
Modified:
lld/trunk/COFF/Chunks.cpp
Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=243202&r1=243201&r2=243202&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Fri Jul 24 22:19:34 2015
@@ -92,12 +92,21 @@ static void applyMOV32T(uint8_t *Off, ui
or16(Off + 6, ((X & 0x700) << 4) | (X & 0xff));
}
+static void applyBranch24T(uint8_t *Off, int32_t V) {
+ uint32_t S = V < 0 ? 1 : 0;
+ uint32_t J1 = ((~V >> 23) & 1) ^ S;
+ uint32_t J2 = ((~V >> 22) & 1) ^ S;
+ or16(Off, ((V >> 12) & 0x3ff) | (S << 10));
+ or16(Off + 2, ((V >> 1) & 0x7ff) | (J2 << 11) | (J1 << 13));
+}
+
void SectionChunk::applyRelARM(uint8_t *Off, uint16_t Type, uint64_t S,
uint64_t P) {
switch (Type) {
- case IMAGE_REL_ARM_ADDR32: add32(Off, S + Config->ImageBase); break;
- case IMAGE_REL_ARM_ADDR32NB: add32(Off, S); break;
- case IMAGE_REL_ARM_MOV32T: applyMOV32T(Off, S + Config->ImageBase); break;
+ case IMAGE_REL_ARM_ADDR32: add32(Off, S + Config->ImageBase); break;
+ case IMAGE_REL_ARM_ADDR32NB: add32(Off, S); break;
+ case IMAGE_REL_ARM_MOV32T: applyMOV32T(Off, S + Config->ImageBase); break;
+ case IMAGE_REL_ARM_BRANCH24T: applyBranch24T(Off, S - P - 4); break;
default:
llvm::report_fatal_error("Unsupported relocation type");
}
Added: lld/trunk/test/COFF/armnt-branch24t.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/armnt-branch24t.test?rev=243202&view=auto
==============================================================================
--- lld/trunk/test/COFF/armnt-branch24t.test (added)
+++ lld/trunk/test/COFF/armnt-branch24t.test Fri Jul 24 22:19:34 2015
@@ -0,0 +1,58 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE
+# RUN: lld -flavor link2 /base:0x400000 /entry:function \
+# RUN: /subsystem:console /out:%t.exe %t.obj
+# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER
+
+# BEFORE: Disassembly of section .text:
+# BEFORE: 0: 70 47 bx lr
+# BEFORE: 2: 00 bf nop
+# BEFORE: 4: 20 20 movs r0, #32
+# BEFORE: 6: 00 f0 00 b8 b.w #0
+
+# AFTER: Disassembly of section .text:
+# AFTER: .text:
+# AFTER: 1000: 70 47 bx lr
+# AFTER: 1002: 00 bf nop
+# AFTER: 1004: 20 20 movs r0, #32
+# AFTER: 1006: ff f7 fb bf b.w #-10
+
+---
+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: 704700BF202000F000B8
+ Relocations:
+ - VirtualAddress: 6
+ SymbolName: identity
+ Type: 20
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 10
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: identity
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: function
+ Value: 4
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
More information about the llvm-commits
mailing list