[PATCH] D74927: [MC][ARM] make Thumb function also if type attribute is set

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 25 09:42:11 PST 2020


psmith added a comment.

I think using .type symbol, %function is more common when a file has to assemble in both Arm or Thumb state depending on whether -marm or -mthumb is given to the assembler.

Some experiments with GNU as imply that it does:

- .thumb_func always results in a symbol with type STT_FUNC and bit 0 set to 1, regardless of the state at the point.
- .type sym, %function before definition of sym, results in a symbol with type STT_FUNC and bit 0 set if the state at the point of the definition of sym is Thumb, 1 if the state is Arm at the point
- .type sym, %function after the definition of sym will use the state of the first instruction to determine, initial data, such as .word is skipped over.
- If a symbol is set to Thumb ahead of definition, a .type sym, %function after the definition will not correct it.

  For the case where .type comes after the definition. I think that using mapping symbols could work well, although I don't think that they could be used directly as we only record the last mapping symbol and we need the first mapping symbol after the definition. I think that if the pending labels have been flushed then a reverse search up the Symbols defined in MCAssembler looking for the closest mapping symbol in the same fragment as the definition would work.

I think an error message could be a bit more complicated to implement, especially if the type is set at the point of definition as in effect we'd need to catch the next mapping symbol and check with the definition, there is more than one code-path to track down. Maybe a follow up patch.

Test code for GNU as.

    .syntax unified
  
    .section .text.1, "ax", %progbits
    .global sym      
    .thumb_func
  sym:
    .arm
    bx lr      
  
    .section .text.2, "ax", %progbits        
    .thumb
    .global sym2
    .type sym2, %function
  sym2:
    .arm
    bx lr
  
    .section .text.3, "ax", %progbits        
    .thumb
    .global sym3
  sym3:
    bx lr
    .arm
    bx lr
    .type sym3, %function      
  
    .section .text.4, "ax", %progbits        
    .arm
    .global sym4
  sym4:
    bx lr
    .thumb
    bx lr
    .type sym4, %function      
          
   .section .text.5, "ax", %progbits
   .thumb
  sym5:
   bx lr
   .pushsection .text
   .arm
  sym6:
   bx lr
   .type sym5, %function   
   .type sym6, %function
   .popsection .text
          
   .section .text.7, "ax", %progbits
   .arm
   .type sym7, %function       
  sym7:
   .thumb
   bx lr
  
   .thumb
   .section .text.8, "ax", %progbits
   .thumb_func
  sym8:
   .arm
   bx lr
   .type sym8, %function       
  
   .thumb
   .section .text.9, "ax", %progbits
   .type sym9, %function        
  sym9:
   .arm
   bx lr
   .type sym9, %function
  
   .section .text.10, "ax", %progbits
   .arm
   .type sym10, %function
   .thumb       
  sym10:
   .arm
   bx lr
   .type sym10, %function
  
   .section .text.11, "ax", %progbits
   .thumb
  
  sym11:
   .word 0
   bx lr
   .type sym11, %function

Gives:

  16: 00000001     0 FUNC    LOCAL  DEFAULT    8 sym5
  18: 00000000     0 FUNC    LOCAL  DEFAULT    1 sym6
  21: 00000000     0 FUNC    LOCAL  DEFAULT    9 sym7
  24: 00000001     0 FUNC    LOCAL  DEFAULT   10 sym8
  27: 00000001     0 FUNC    LOCAL  DEFAULT   11 sym9
  30: 00000001     0 FUNC    LOCAL  DEFAULT   12 sym10
  33: 00000001     0 FUNC    LOCAL  DEFAULT   13 sym11
  37: 00000001     0 FUNC    GLOBAL DEFAULT    4 sym
  38: 00000001     0 FUNC    GLOBAL DEFAULT    5 sym2
  39: 00000001     0 FUNC    GLOBAL DEFAULT    6 sym3
  40: 00000000     0 FUNC    GLOBAL DEFAULT    7 sym4


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74927/new/

https://reviews.llvm.org/D74927





More information about the llvm-commits mailing list