[PATCH] MIPS gas: Fix broken relocation sorting

David Daney ddaney@avtrex.com
Tue Nov 7 20:51:00 GMT 2006


The problem here is that some explicit relocations were not getting 
sorted properly.  The %got() and %lo() were being separated by another 
%got()/%lo() pair.  This resulted in incorrect relocations being applied 
by the linker.

At first I thought this was a GCC bug, but Ian Lance Taylor set me 
straight here.  For those interested, the GCC bug report is here:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29721

The root of the problem is that the relocations are against a local 
symbol in another section which get converted to relocations against the 
global section symbol.  The relocation sorting was not done for 
relocations against global symbols.

There are as far as I can see two easy ways to fix it:

1) In mips_fix_adjustable, don't allow the conversion if it would affect 
a relocation that could possibly need sorting.

2) In mips_from_file, do the sorting with relocations against global 
symbols also.

I chose the second option, as it looked like the exclusion of global 
relocations from the sorting was probably just an optimization.  The 
first option would result in many %got() relocations that have no 
corresponding %lo() not being converted to be against the section.

Tested with a mipsel-linux cross build with no regressions.  A bootstrap 
of GCC 4.2 branch is underway, but test results will not be available 
for about 5 days.

OK to commit?

This bug causes bad code with both gcc-4.2 and the gcc trunk and perhaps 
any gcc with explicit relocs.  Would it make sense to put this on the 
2.17 branch and make a 2.17.1 release before gcc-4.2 is released?


gas:
2006-11-06  David Daney  <ddaney@avtrex.com>

	* config/tc-mips.c (mips_frob_file): Don't check for global symbol.

gas/testsuite:
2006-11-06  David Daney  <ddaney@avtrex.com>

	* gas/mips/elf-rel26.s: New test.
	* gas/mips/elf-rel26.d: Ditto.
	* gas/mips/mips.exp: Run it.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gas.diff.txt
URL: <https://sourceware.org/pipermail/binutils/attachments/20061107/d46f03fd/attachment.txt>


More information about the Binutils mailing list