This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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]

Re: Idea for code size reduction


"Philipp Marek" <philipp@marek.priv.at> writes:

>>   Shouldn't this be done in the linker instead?
> Well, can the linker change the instruction sequences? Ie. put a JMP
> instead of other code?

Sure.  The linker can do whatever it likes.  The usual problem is that
by the time the linker sees the code, it no longer knows about PC
relative references within the same section.  So if you have

    call foo
    ...
    sequence to remove
    ...
foo:

and the call is PC-relative, then when the linker removes the sequence
of instructions it will not know that it needs to adjust the call to
foo.

What you are describing is a type of linker relaxation, and the same
issues arise there.  The usual solution is to force the assembler to
emit all PC-relative relocations, so that the linker knows about them
and is able to adjust them.

Linker relaxation is used routinely in special sections, such as the
.eh_frame section used to hold stack unwind information for throwing
exceptions.  It is also used for code sequences on some processors,
but normally not on the i386/x86_64.

Ian


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