[uClinux-dev] elf2flt and mips nommu again

Mile Davidovic Mile.Davidovic at micronasnit.com
Wed Mar 5 08:16:54 EST 2003


Hi all

I am trying to port elf2flt for MIPS without MMU but I have trouble 
with general picture about handling relocations. 

Mr. Qiulm from xipotech said that if use PIC code then R_MIPS_LO16, R_MIPS_HI16 and R_MIPS_26 won't show up. 

My question is: is it enough to have DOPIC=y in .config file uclibc?
Dumped crt0.o saw that we still have R_MIPS_HI16, R_MIPS_LO16 and R_MIPS_26 relocations. 

Disassembly of section .text:
00000000 <__start>:
   0:	0000f821 	move	ra,zero
   4:	8fa40000 	lw	a0,0(sp)
   8:	27a50004 	addiu	a1,sp,4
   c:	24860001 	addiu	a2,a0,1
  10:	00063080 	sll	a2,a2,0x2
  14:	00c53020 	add	a2,a2,a1
  18:	3c070000 	lui	a3,0x0
			18: R_MIPS_HI16	_init
  1c:	24e70000 	addiu	a3,a3,0
			1c: R_MIPS_LO16	_init
  20:	27bdffe8 	addiu	sp,sp,-24
  24:	3c020000 	lui	v0,0x0
			24: R_MIPS_HI16	_fini
  28:	24420000 	addiu	v0,v0,0
			28: R_MIPS_LO16	_fini
  2c:	0c000000 	jal	0 <__start>
			2c: R_MIPS_26	__uClibc_main
  30:	afa20010 	sw	v0,16(sp)
  34:	27bd0018 	addiu	sp,sp,24

When I set -Wa,-KPIC in compiler command line options, to pass assembler -KPIC, I got next crt0 dump:
00000000 <__start>:
   0:	0000f821 	move	ra,zero
   4:	8fa40000 	lw	a0,0(sp)
   8:	27a50004 	addiu	a1,sp,4
   c:	24860001 	addiu	a2,a0,1
  10:	00063080 	sll	a2,a2,0x2
  14:	00c53020 	add	a2,a2,a1
  18:	8f870000 	lw	a3,0(gp)
			18: R_MIPS_GOT16	_init
  1c:	27bdffe8 	addiu	sp,sp,-24
  20:	8f820000 	lw	v0,0(gp)
			20: R_MIPS_GOT16	_fini
  24:	00000000 	nop
  28:	afa20010 	sw	v0,16(sp)
  2c:	8f990000 	lw	t9,0(gp)
			2c: R_MIPS_CALL16	__uClibc_main
  30:	00000000 	nop
  34:	0320f809 	jalr	t9
  38:	00000000 	nop
  3c:	27bd0018 	addiu	sp,sp,24

When I set -Wa,--mebedded-pic or -mebedded-pic I got same result:
00000000 <__start>:
   0:	0000f821 	move	ra,zero
   4:	8fa40000 	lw	a0,0(sp)
   8:	27a50004 	addiu	a1,sp,4
   c:	24860001 	addiu	a2,a0,1
  10:	00063080 	sll	a2,a2,0x2
  14:	00c53020 	add	a2,a2,a1
  18:	27870000 	addiu	a3,gp,0
			18: R_MIPS_GPREL16	_init
  1c:	27bdffe8 	addiu	sp,sp,-24
  20:	27820000 	addiu	v0,gp,0
			20: R_MIPS_GPREL16	_fini
  24:	0411ffff 	bal	24 <__start+0x24>
			24: R_MIPS_GNU_REL16_S2	__uClibc_main
  28:	afa20010 	sw	v0,16(sp)
  2c:	27bd0018 	addiu	sp,sp,24

My question are: what combination is correct? Do I have to recompile
all uclibc with these options? 

Another question is: what relocations ld-elf2flt script handle?

>From xipotech site I downloaded elf2flt. In this elf2flt I saw sample
of R_MIPS_32 relocation:

case R_MIPS_32:
	//sym_vma = bfd_section_vma(abs_bfd, sym_section);
	//section_vma = sym_vma;
	sym_vma = section_vma;
	relocation_needed = 1;
	break;

from mr. YH Lin <yhlin at viosoft.com> I saw:
case R_MIPS_32:
	relocation_needed = 1;
	sym_vma = bfd_section_vma(abs_bfd, sym_section);
	sym_addr += ((sym_vma + q->addend) & q->howto->dst_mask);
	break;

In MIPS ABI for R_MIPS_32 calculation is: S + A, but I am confused
with & q->howto->dst_mask part;

>From MIPS abi I read something like this (page 81), for R_MIPS_26:

if symboll is local then  (((A<<2) | (P & 0xf0000000) + S) >> 2
if symboll is extern then (sign_extend(A<<2) + S) >> 2

where is A addend and P represents the place (section offset or address) of the storage unit being relocated (computed using r_offset).

That relocation exist in crt0.o for 
My questions are:
How I can determine is symbol local or extern?
How I can calculate P?

TIA
Mile




More information about the uClinux-dev mailing list