Sat Jun 4 15:39:51 CEST 2011

What are __restore and __restore_rt ?

I ran into these missing symbols in an eCos synthetic target build[1].
I have no idea where these functions should be defined, and what the
meaning is of the construct in the eCos code:

        .align 16
        .global cyg_hal_sys_restore_rt
        movl    $SYS_rt_sigreturn, %eax
        int     $0x80
        .type __restore_rt,@function
        .size __restore_rt,1b - __restore_rt
        .align 8
        .global cyg_hal_sys_restore
        popl    %eax
        movl    $SYS_sigreturn, %eax
        int     $0x80
        .type __restore,@function
        .size __restore,1b - __restore

The build fails like this:

make[1]: Entering directory `/opt/xc/ecos/build/cvs/linux/hal/synth/i386linux/current'
gcc -c  -I/opt/xc/ecos/build/cvs/linux/install/include -I/opt/xc/ecos/src/cvs//packages/hal/synth/i386linux/current -I/opt/xc/ecos/src/cvs//packages/hal/synth/i386linux/current/src -I/opt/xc/ecos/src/cvs//packages/hal/synth/i386linux/current/tests -I. -I/opt/xc/ecos/src/cvs//packages/hal/synth/i386linux/current/src/ -finline-limit=7000 -Wall -Wpointer-arith -Wstrict-prototypes -Wundef  -Wno-write-strings -g -O2 -ffunction-sections -fdata-sections  -fno-exceptions -Wp,-MD,src/syscall-i386-linux-1.0.tmp -o src/hal_synth_i386linux_syscall-i386-linux-1.0.o /opt/xc/ecos/src/cvs//packages/hal/synth/i386linux/current/src/syscall-i386-linux-1.0.S
/tmp/ccIPQc1w.s: Assembler messages:
/tmp/ccIPQc1w.s: Error: .size expression for __restore_rt does not evaluate to a constant
/tmp/ccIPQc1w.s: Error: .size expression for __restore does not evaluate to a constant
make[1]: *** [src/syscall-i386-linux-1.0.o.d] Error 1
make[1]: Leaving directory `/opt/xc/ecos/build/cvs/linux/hal/synth/i386linux/current'
make: *** [build] Error 2
make: Leaving directory `/opt/xc/ecos/build/cvs/linux'

According to something I found in google code search[2], these
functions are trampolines.  It's a part of gdb code[3].  It says:

    ... as of version 2.1.2, the GNU C Library uses signal trampolines
    (named __restore and __restore_rt) that are identical to the ones
    used by the kernel.

Maybe that is something that changed?  I used objdump -T to find these
symbols in any of the libraries in /lib and /usr/lib and I didn't find
anything.  Maybe it's in libgcc or so?

So let's see what that code actually means.  The .type[4] directive
records the symbol table type for the associated symbol.  So it seems
that ".type" in

        .type __restore,@function
        .size __restore,1b - __restore

does not much more thanannotate the symbol "__restore": it does not
define it.  Same for ".size": it records the size associated to the

Maybe what is meant here is to just refer to the "cyg_hal_sys_restore"
symbol, and not the "__restore" symbol?  I.e. the code probably has
changed at some point to incorportate a name change, but somebody
forgot to update that directive.  It's not necessary for the code to
work so it was only detected when binutils got stricter.

See fix next post.

[1] http://ecos.sourceware.org/ml/ecos-discuss/2011-06/msg00013.html
[2] http://www.google.com/codesearch?as_q=__restore_rt&btnG=Search+Code&hl=en&as_package=&as_lang=&as_filename=&as_class=&as_function=&as_license=&as_case=
[3] http://www.google.com/codesearch/p?hl=en#pFm0LxzAWvs/darwinsource/tarballs/other/gdb-203.tar.gz%7CYXbJTYT1R-s/gdb-203/src/gdb/i386-linux-tdep.c&q=__restore_rt
[4] http://tigcc.ticalc.org/doc/gnuasm.html#SEC133