[uClinux-dev] Linking arm thumb code

Adrian von Bidder avbidder at acter.ch
Thu Nov 22 07:41:49 EST 2001


Heyho!

I'm trying to get a thumb-only userspace in uclinux/uclibc on a ARM.

uclibc compiled fine, hello world however crashes. When linking I get a
warning:

ld: Warning: type of symbol `__uClibc_main' changed from 2 to 13 in
__uClibc_main.o

I have no idea what this means. I do, however, know why the program
crashes:

__uClibc_main uses with weak symbols, this causes indirect _call_via_rx
to be used. The address to jump to is loaded with

        ldr     r1, .L3+4
        ldr     r0, [r6, r1]	@ r6 is my pic base register
        bl      _call_via_r0
	...
.L3:
        .word   __environ
        .word   .LC0

and, at the top of the asm output:

        .weak   __init_stdio
        .thumb_set __init_stdio,__uClibc_empty_func
	...
        .section        .rodata
        .align  2
.LC0:
        .word   __init_stdio


Until here, everything is ok - but one thing: r0 contains the address of
the called function (_uClib_empty_func in this case) and this causes the
bx instruction in _call_via_r0 to switch to ARM state.

$ arm-uclinux-objdump -r __uClibc_main.o 

__uClibc_main.o:     file format elf32-littlearm

RELOCATION RECORDS FOR [.text]:
OFFSET   TYPE              VALUE 
...
00000034 R_ARM_ABS32       .rodata
...
RELOCATION RECORDS FOR [.rodata]:
OFFSET   TYPE              VALUE 
00000000 R_ARM_ABS32       __init_stdio

I'm sure I'm not the first one to attempt this...

(Oh, yes: environment is gcc-3.0.2 with my patch to make it produce
disable-got code; binutils-2.11.2 with the armelf_uclinux linker
emulation taken from the old arm toolchain. I can't compare this with
our old gcc-2.96 based toolchain since the latter cannot produce thumb
code properly.)

btw: what is the reasoning behind using _call_via_rx instead of just
doing mov lr, pc; bx rx?

greets from Zürich
-- vbi
This message resent by the uclinux-dev at uclinux.org list server http://www.uClinux.org/



More information about the uClinux-dev mailing list