This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

x86 - linker optimization of "call *constant_variable" - feasible?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]