This is the mail archive of the binutils@sourceware.cygnus.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]

Re: a question on the definition of -relax in ld


   Date: Wed, 15 Mar 2000 01:45:08 -0500
   From: Kazu Hirata <kazu@hxi.com>

   It seems that the -relax option in ld means relaxing only insn with a
   reloc in it. I have a patch that also relaxes insn without reloc. Could
   such a patch be considered?

The -relax option just means to relax.  There is no requirement that
the instruction have a reloc.

However, there is a requirement that the linker behave correctly in
the presence of an unusual initialized const array, such as
    const char a[] = { 0xf0, 0x0f };
If the linker searches the .text section for the sequence 0xf00f, and
finds such an array, and relaxes it, then the linker has made a
mistake.

The usual way to avoid such a problem is to have the assembler issue a
reloc for a relaxable instruction.  The assembler can not be confused
as to whether it is looking at an instruction or data.  This reloc
serves as a marker to the linker indicating that the data really is an
instruction and is safe to relax.

If you use some other mechanism to ensure that you only relax
instructions, then it is fine to not require a reloc.

For example, the SH relaxing uses explicit CODE and DATA relocs,
emitted by the assembler, to permit the linker to distinguish
sequences of instructions from data.  This permits the SH relaxation
to not require a relocation on each instruction to be relaxed.  The
SH1 through SH3 happen to execute load instructions more efficiently
if they are aligned on a four byte boundary, so the linker uses the
CODE and DATA relocs to scan instructions sequences for misaligned
load instructions.  (Looking at it now, I find it hard to believe that
this code works correctly, even though I wrote it myself.)

Ian

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