x86 - linker optimization of "call *constant_variable" - feasible?
Zack Weinberg
zack@codesourcery.com
Wed Aug 13 04:28:00 GMT 2003
Consider the following pair of x86 assembly source files:
; file1.s
.section .rodata
.globl B
B:
.long A
; file2.s
.section .text
.globl foo
foo:
call A
call *B
The object code for file2.s looks like this:
00000000 <foo>:
0: e8 fc ff ff ff call 1 <foo+0x1>
1: R_386_PC32 B
5: ff 15 00 00 00 00 call *0x0
7: R_386_32 A
The second call is significantly slower than the first, because of the
extra memory fetch. I'm wondering whether it is feasible for the
linker to optimize the second call into the first. Obviously this can
only be done when the relocation for A points into a read-only segment.
This sort of code shows up, for instance, when you have written C++
wrappers around a C library using function pointers as data members.
zw
More information about the Binutils
mailing list