编译器会把跳表放在函数的结尾吗? [英] Would compiler put jump table at the end of function?
问题描述
例如,这是一个带有跳转表的程序集
movl $ 5,-4(%ebp)
cmpl $ 10,-4(%ebp)
ja L13
movl -4(%ebp),%eax
sall $ 2,%eax
movl L14(%eax) eax
jmp *%eax
.section .rdata,dr
.align 4
L14:
.long L13
.long L3
.long L4
.long L5
.long L6
.long L7
.long L8
.long L9
.long L10
.long L11
.long L12
.text
L3:
movl $ LC0,(%esp)
call _printf
jmp L2 $ b $我的问题是,是可能的编译器像GCC或ICC放置跳转表在函数的结尾而不是在函数的中间?解决方案表不会结束在中间功能。如果仔细观察,您可能会注意到这一行:
.section .rdata,dr
它告诉汇编器将以下数据放入名为.rdata的部分。
并且以下 .text
告诉汇编器切换回.text段。因此,函数代码实际上将被连续地放置(在 .text
),并且跳转表将被单独存储(在 .rdata
)。
For example, this is an assembly with jump table
movl $5, -4(%ebp)
cmpl $10, -4(%ebp)
ja L13
movl -4(%ebp), %eax
sall $2, %eax
movl L14(%eax), %eax
jmp *%eax
.section .rdata,"dr"
.align 4
L14:
.long L13
.long L3
.long L4
.long L5
.long L6
.long L7
.long L8
.long L9
.long L10
.long L11
.long L12
.text
L3:
movl $LC0, (%esp)
call _printf
jmp L2
...
My question is, is that possible for compiler like GCC or ICC to put jump table at the end of the function instead of in the middle of function?
解决方案 The table won't end up in the middle of the function. If you look carefully you may notice this line:
.section .rdata,"dr"
It tells the assembler to put the following data into the section named ".rdata".
And the following .text
tells the assembler to switch back to the .text section. So the function code will actually be placed contiguously (in .text
), and the jump table will be stored separately (in .rdata
).
这篇关于编译器会把跳表放在函数的结尾吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!