[commit: ghc] ghc-8.2: [Elf/arm] Thumb indicator bit only for STT_FUNC (df58be5)

git at git.haskell.org git at git.haskell.org
Tue Apr 11 02:22:02 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-8.2
Link       : http://ghc.haskell.org/trac/ghc/changeset/df58be5bd0d974175ff24cbdc062368c94d9c6cb/ghc

>---------------------------------------------------------------

commit df58be5bd0d974175ff24cbdc062368c94d9c6cb
Author: Moritz Angermann <moritz.angermann at gmail.com>
Date:   Mon Apr 10 21:39:19 2017 -0400

    [Elf/arm] Thumb indicator bit only for STT_FUNC
    
    Reviewers: rwbarton, bgamari, austin, erikd, simonmar, trofi
    
    Reviewed By: trofi
    
    Subscribers: trofi, thomie
    
    Differential Revision: https://phabricator.haskell.org/D3438
    
    (cherry picked from commit e662a6cb9fb6459e0a15abbff25ae7b80f91b281)


>---------------------------------------------------------------

df58be5bd0d974175ff24cbdc062368c94d9c6cb
 rts/linker/Elf.c | 40 +++++++++++++++++++++++++++++++---------
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
index 66b8f71..086a323 100644
--- a/rts/linker/Elf.c
+++ b/rts/linker/Elf.c
@@ -992,15 +992,37 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC,
          IF_DEBUG(linker,debugBelch( "`%s' resolves to %p\n", symbol, (void*)S ));
 
 #ifdef arm_HOST_ARCH
-         // Thumb instructions have bit 0 of symbol's st_value set
-         is_target_thm = S & 0x1;
-
-         T = sym.st_info & STT_FUNC && is_target_thm;
-
-         // Make sure we clear bit 0. Strictly speaking we should have done
-         // this to st_value above but I believe alignment requirements should
-         // ensure that no instructions start on an odd address
-         S &= ~1;
+          /*
+           * 4.5.3 Symbol Values
+           *
+           * In addition to the normal rules for symbol values the following
+           * rules shall also apply to symbols of type STT_FUNC:
+           * - If the symbol addresses an ARM instruction, its value is the
+           *   address of the instruction (in a relocatable object, the
+           *   offset of the instruction from the start of the section
+           *   containing it).
+           * - If the symbol addresses a Thumb instruction, its value is the
+           *   address of the instruction with bit zero set (in a relocatable
+           *   object, the section offset with bit zero set).
+           * - For the purposes of relocation the value used shall be the
+           *   address of the instruction (st_value & ~1).
+           *
+           *  Note: This allows a linker to distinguish ARM and Thumb code
+           *        symbols without having to refer to the map. An ARM symbol
+           *        will always have an even value, while a Thumb symbol will
+           *        always have an odd value. However, a linker should strip
+           *        the discriminating bit from the value before using it for
+           *        relocation.
+           *
+           * (source: ELF for the ARM Architecture
+           *          ARM IHI 0044F, current through ABI release 2.10
+           *          24th November 2015)
+           */
+          if(ELF_ST_TYPE(sym.st_info) == STT_FUNC) {
+              is_target_thm = S & 0x1;
+              T = is_target_thm;
+              S &= ~1;
+          }
 #endif
       }
 



More information about the ghc-commits mailing list