[lld] r277836 - COFF ARM: Clear the J1 and J2 bits when applying relocations to 24 bit branches

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 5 10:28:21 PDT 2016


Author: compnerd
Date: Fri Aug  5 12:28:21 2016
New Revision: 277836

URL: http://llvm.org/viewvc/llvm-project?rev=277836&view=rev
Log:
COFF ARM: Clear the J1 and J2 bits when applying relocations to 24 bit branches

The opcode for the bl branches can initially be F000 F800, i.e.
the J1 and J2 bits are already set. Therefore mask these bits out
before or'ing in the new bits.

Patch by Martin Storsjö!

Modified:
    lld/trunk/COFF/Chunks.cpp
    lld/trunk/test/COFF/reloc-arm.test

Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=277836&r1=277835&r2=277836&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Fri Aug  5 12:28:21 2016
@@ -103,7 +103,8 @@ static void applyBranch24T(uint8_t *Off,
   uint32_t J1 = ((~V >> 23) & 1) ^ S;
   uint32_t J2 = ((~V >> 22) & 1) ^ S;
   or16(Off, (S << 10) | ((V >> 12) & 0x3ff));
-  or16(Off + 2, (J1 << 13) | (J2 << 11) | ((V >> 1) & 0x7ff));
+  // Clear out the J1 and J2 bits which may be set.
+  write16le(Off + 2, (read16le(Off + 2) & 0xd000) | (J1 << 13) | (J2 << 11) | ((V >> 1) & 0x7ff));
 }
 
 void SectionChunk::applyRelARM(uint8_t *Off, uint16_t Type, Defined *Sym,

Modified: lld/trunk/test/COFF/reloc-arm.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/reloc-arm.test?rev=277836&r1=277835&r2=277836&view=diff
==============================================================================
--- lld/trunk/test/COFF/reloc-arm.test (original)
+++ lld/trunk/test/COFF/reloc-arm.test Fri Aug  5 12:28:21 2016
@@ -9,7 +9,7 @@
 # CHECK: 402030 fe07e62f 00000000 00000000 00000000
 # CHECK: 402040 3e04de2f 00000000 00000000 00000000
 # CHECK: 402050 fe07d62f 00000000 00000000 00000000
-# CHECK: 402060 00000000 00000000 00000000 00000000
+# CHECK: 402060 fef0cef7 00000000 00000000 00000000
 
 --- !COFF
 header:
@@ -23,7 +23,7 @@ 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:       4096
-    SectionData:     00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+    SectionData:     00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f000f8000000000000000000000000
     Relocations:
       - VirtualAddress:  0
         SymbolName:      foo
@@ -43,6 +43,9 @@ sections:
       - VirtualAddress:  80
         SymbolName:      foo
         Type:            21  # IMAGE_REL_AMD64_BLX23T
+      - VirtualAddress:  96
+        SymbolName:      bar
+        Type:            20  # IMAGE_REL_ARM_BRANCH24T
 symbols:
   - Name:            .aaa
     Value:           0
@@ -67,5 +70,11 @@ symbols:
     SectionNumber:   1
     SimpleType:      IMAGE_SYM_TYPE_NULL
     ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
+  - Name:            bar
+    Value:           0x500000
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
     StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
 ...




More information about the llvm-commits mailing list