0

例如,这是一个带有跳转表的程序集

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
...

我的问题是,像 GCC 或 ICC 这样的编译器是否可以将跳转表放在函数的末尾而不是函数的中间?

4

1 回答 1

5

表格不会出现在函数的中间。如果你仔细看,你可能会注意到这一行:

.section .rdata,"dr"

它告诉汇编器将以下数据放入名为“.rdata”的部分中。

下面.text告诉汇编器切换回 .text 部分。所以函数代码实际上会连续放置(in .text),跳转表会单独存放(in .rdata)。

于 2013-11-08T12:08:30.927 回答