function pointer and thumb/arm mode change

X call a function pointer Y

X is ARM mode
Y is ARM or thumb mode
is it workable?

Answer: yes, because
BX Rm and BLX Rm derive the target state from bit[0] of Rm:
  • if bit[0] of Rm is 0, the processor changes to, or remains in, ARM state
  • if bit[0] of Rm is 1, the processor changes to, or remains in, Thumb state.

before link, symbol table
12: 00000000     8 FUNC    GLOBAL DEFAULT    1 foo2  
12: 00000001     2 FUNC    GLOBAL DEFAULT    1 foo1

after link, symbol table
 3105: 00008d6c     8 FUNC    GLOBAL DEFAULT    3 foo2   <==compile into arm

 3106: 00008d69     2 FUNC    GLOBAL DEFAULT    3 foo1   <==compile into thumb


留言

這個網誌中的熱門文章

我們能利用machine learning去幫助compiler的optimization演算法變強嗎?

The Speed Game: Automated Trading Systems in C++

被討厭的勇氣 自我啟發之父阿德勒的教導