Don't lose the thumb bit by using relocations with sections.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 11 Apr 2014 19:18:01 +0000 (19:18 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 11 Apr 2014 19:18:01 +0000 (19:18 +0000)
This fixes a regression from r205076.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206047 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/ELFObjectWriter.cpp
test/MC/ARM/elf-thumbfunc-reloc.s

index e802c01fea1f4224a6f9cdda1aa2a0ac667aa5ea..cd92b75a7f06a3f296688d3e46c6d722b50236a7 100644 (file)
@@ -813,6 +813,13 @@ bool ELFObjectWriter::shouldRelocateWithSymbol(const MCSymbolRefExpr *RefA,
   if (Flags & ELF::SHF_TLS)
     return true;
 
   if (Flags & ELF::SHF_TLS)
     return true;
 
+  // If the symbol is a thumb function the final relocation must set the lowest
+  // bit. With a symbol that is done by just having the symbol have that bit
+  // set, so we would lose the bit if we relocated with the section.
+  // FIXME: We could use the section but add the bit to the relocation value.
+  if (SD->getFlags() & ELF_Other_ThumbFunc)
+    return true;
+
   if (TargetObjectWriter->needsRelocateWithSymbol(Type))
     return true;
   return false;
   if (TargetObjectWriter->needsRelocateWithSymbol(Type))
     return true;
   return false;
index 614702012f0c9fa2a93006e57c96d8e3ec0935e9..ea7d507a7e834e4480bdbdb72f33c46eb8c4b206 100644 (file)
@@ -5,7 +5,6 @@
 
        .syntax unified
         .text
 
        .syntax unified
         .text
-        .globl  f
         .align  2
         .type   f,%function
         .code   16
         .align  2
         .type   f,%function
         .code   16
@@ -16,9 +15,21 @@ f:
         bl      g
         pop     {r7, pc}
 
         bl      g
         pop     {r7, pc}
 
+       .section        .data.rel.local,"aw",%progbits
+ptr:
+       .long   f
+
+
 @@ make sure an R_ARM_THM_CALL relocation is generated for the call to g
 @CHECK:      Relocations [
 @CHECK-NEXT:   Section (2) .rel.text {
 @CHECK-NEXT:     0x4 R_ARM_THM_CALL g 0x0
 @CHECK-NEXT:   }
 @@ make sure an R_ARM_THM_CALL relocation is generated for the call to g
 @CHECK:      Relocations [
 @CHECK-NEXT:   Section (2) .rel.text {
 @CHECK-NEXT:     0x4 R_ARM_THM_CALL g 0x0
 @CHECK-NEXT:   }
+
+
+@@ make sure the relocation is with f. That is one way to make sure it includes
+@@ the thumb bit.
+@CHECK-NEXT:   Section (6) .rel.data.rel.local {
+@CHECK-NEXT:     0x0 R_ARM_ABS32 f 0x0
+@CHECK-NEXT:   }
 @CHECK-NEXT: ]
 @CHECK-NEXT: ]