This is the mail archive of the 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]

[PATCH] Fix MIPS symbol difference calculation

When targetting MIPS, gas can miscalculate the difference between two symbols when used in %hi relocation operators.

	li	$2, %hi(LAB3-LAB1)
	addiu	$2, %lo(LAB3-LAB1)
	.fill 32760
	li	$2, %hi(LAB2-LAB4)
	addiu	$2, %lo(LAB2-LAB4)

The problem occurs because fixups are created for all the relocation operators except %lo(LAB2-LAB4), because both LAB2 and LAB4 have been encountered by the time it is processed.

adjust_reloc_syms() in write.c changes these relocs to be relative to .text, so the second and third relocs effectively become:


mips_frob_file() in tc-mips.c then mistakenly pairs these two together when looking for a corresponding %lo for the %hi, because there is no corresponding %lo(LAB2-LAB4) fixup, and the earlier %lo appears to be an offset from the same symbol .text (ignoring the subtracted symbol). mips_frob_file() then overwrites the offset of the %hi with that of the %lo, so it becomes:


This corrupts the offset, so fixup_segment() later ends up calculating the wrong value for this %hi.

This patch works around this by preventing %hi expressions from being processed by mips_frob_file() if it contains a subtracted symbol. This should be safe as the relocation-pairing is only necessary if the relocations actually make it into the output object file, but GAS cannot express the difference between two symbols as a relocation on MIPS, so any such fixups that are not fully resolvable will result in an error anyway.

fixup_has_matching_lo_p() is also modified to check the subtracted symbol to avoid mispairings of remaining %hi relocations with %lo relocations containing a subtracted symbol.

I have also added the above example as a DejaGnu test.


Attachment: mips_hi_subsy.patch
Description: Text document

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