[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/12494] Relaxation leads to wrong code optimization (computed got

From: bjoern.m.haase at web dot de
Subject: [Bug ld/12494] Relaxation leads to wrong code optimization (computed goto)
Date: Tue, 26 Jul 2011 15:26:18 +0000


--- Comment #8 from Bjoern Haase <bjoern.m.haase at web dot de> 2011-07-26 
15:26:13 UTC ---
Maybe the two following hints are helpful:

1.) As a fast fix, there is a command line switch for the linker that disables
the problematic rcall ret optimization. Execute your avr-ld with "-h" and you
get the information on the options to configure the relaxation optimization.

2.) The source of the problem is that the present relaxation algorithm does not
check wether relocations point to the return instruction. The place to fix the
issue is the file


and the function to place the fix is

static bfd_boolean
elf32_avr_relax_section (bfd *abfd,
             asection *sec,
                         struct bfd_link_info *link_info,
                         bfd_boolean *again)

The part of the function to fix is around line 1912 where the relaxation
algorithm tries to identify call/ret and rcall/ret sequences.

#code fragment to look for

            /* Here we look for rcall/ret or call/ret sequences that could be
               safely replaced by rjmp/ret or jmp/ret.  */

#end of code fragment

What is missing is code that checks wether there is somebody actually needing
the seemingly useless ret instruction before it is deleted. 

Code that does this job can be taken from the code part some lines later that
deletes ret instructions that immediately follow jumps and rjmps. Note that one
needs to check for three possible uses of the "ret" instruction
 a) global labels refering to the ret
 b) local labels refering to the ret
 c) relocations refering to the ret

The required code already exists and the method for these checks could be taken
from about line 2062

#code fragment to look for

                       /* We now only have to make sure that there is no
                           local label defined at the address of the ret
                           instruction and that there is no local relocation
                           in this section pointing to the ret.  */

                        int deleting_ret_is_safe = 1;
                        unsigned int section_offset_of_ret_insn =
                                          irel->r_offset + insn_size;
                        Elf_Internal_Sym *isym, *isymend;
                        unsigned int sec_shndx;

                        sec_shndx =
              _bfd_elf_section_from_bfd_section (abfd, sec);

                        /* Check for local symbols.  */


                        /* Now check for global symbols.  */

                        /* Now we check for relocations pointing to ret.  */

#end of code fragment

Since these checks obviously are required at three places, it might be useful
to move the checking code above to a seperate function, in order to avoid code



Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]