This is the mail archive of the binutils@sources.redhat.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]
Other format: [Raw text]

[RFA] ARM OABI - pc-relative relocations


(I don't know much about this old ARM ABI, so I may have missed
something.  As for GNU AS, the major differences between arm-oabi and
arm-nabi is that arm-oabi uses RELA while arm-nabi uses REL, and that
arm-nabi defines some additional relocation types, right?)

It seems to me that there is a major bug in the emission of the
pc-relative relocation for arm-oabi. Consider this C file:

--

void r () {
	srrr ();
}

int srrr () {
	printf ("A test\n");
}


--

Here is what GCC generates:

[...]
r:
	mov	ip, sp
	stmfd	sp!, {fp, ip, lr, pc}
	sub	fp, ip, #4
	bl	srrr
	ldmea	fp, {fp, sp, pc}
[...]
srrr:
	@ args = 0, pretend = 0, frame = 0
	@ frame_needed = 1, uses_anonymous_args = 0
	mov	ip, sp
	stmfd	sp!, {fp, ip, lr, pc}
	sub	fp, ip, #4
	ldr	r0, .L3
	bl	printf
	mov	r0, r3
	ldmea	fp, {fp, sp, pc}
[...]


If I run as on it, I get:
sok% arm-oabi-objdump -d -j .text ../../../binutils_fsf/tmp/r_oabi.o

../../../binutils_fsf/tmp/r_oabi.o:     file format elf32-littlearm-oabi

Disassembly of section .text:

00000000 <r>:
   0:   e1a0c00d        mov     ip, sp
   4:   e92dd800        stmdb   sp!, {fp, ip, lr, pc}
   8:   e24cb004        sub     fp, ip, #4      ; 0x4
   c:   ebfffffb        bl      0 <r>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Here is the problem. Even though arm-oabi uses RELA, an implicit addend
has been generated (-0xc). The relocation entry is:

sok% arm-oabi-readelf -r r_oabi.o
[...]
0000000c  00000f01 R_ARM_PC24        00000014   srrr + 0

The computation of R_ARM_PC24, according to the ARM-ELF ABI, is S - P
+ A (S being the symbol, P the place of the relocation and A the sum
of the implicit addend and the explicit addend). In that case, the
target of bl is srrr - 0xc... It should have been srrr.

After investigation, it appears that in tc-arm.c (md_apply_fix3), it
appears that an implicit addend can be generated for
BFD_RELOC_ARM_PCREL_BLX and BFD_RELOC_ARM_PCREL_BRANCH. This patch
fixes the problem. Tested against the simulator, 0 failures.

Changelog entry:

2003-12-12  Jerome Guitton  <guitton@act-europe.fr>

	* tc-arm.c (md_apply_fix3): Make sure that no implicit addend
	will be generated for BFD_RELOC_ARM_PCREL_BLX and
	BFD_RELOC_ARM_PCREL_BRANCH.

-- 
Jerome

Attachment: tc-arm.dif
Description: Text document


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