Staticke linkovani

Ladislav Vaiz spam na nagano.cz
Čtvrtek Březen 8 21:17:27 CET 2007


Tak to zkusíme naprosto konkrétně :-)
Triviální příklad:

#include <pthread.h>
#include <unistd.h>
int main(void){
    write(1, "a", 1);
}  

Cílem je přilinkovat libpthread (náhodně zvolená knihovna) staticky a 
libc dynamicky, aby se používaly správné moduly libnss_* .
Vše zkoušeno na Debianu Sarge i386, gcc 3.3.5, libc 2.3.2.


gcc -o test test.c -Wl,-Bstatic -lpthread
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status


gcc -o test test.c -Wl,-Bstatic -lpthread -Wl,-Bdynamic
/usr/lib/gcc-lib/i486-linux/3.3.5/../../../libpthread.a(ptw-write.o)(.text+0x25): 
In function `write':
: undefined reference to `__syscall_error'
/usr/lib/gcc-lib/i486-linux/3.3.5/../../../libpthread.a(ptw-write.o)(.text+0x55): 
In function `write':
: undefined reference to `__syscall_error'
/usr/lib/gcc-lib/i486-linux/3.3.5/../../../libpthread.a(ptw-read.o)(.text+0x25): 
In function `read':
: undefined reference to `__syscall_error'
/usr/lib/gcc-lib/i486-linux/3.3.5/../../../libpthread.a(ptw-read.o)(.text+0x55): 
In function `read':
: undefined reference to `__syscall_error'
/usr/lib/gcc-lib/i486-linux/3.3.5/../../../libpthread.a(ptw-close.o)(.text+0x1f): 
In function `close':
: undefined reference to `__syscall_error'
/usr/lib/gcc-lib/i486-linux/3.3.5/../../../libpthread.a(ptw-close.o)(.text+0x4a): 
more undefined references to `__syscall_error' follow
collect2: ld returned 1 exit status


To samé vypisuje
gcc -o test test.c -Wl,-Bstatic /usr/lib/libpthread.a -Wl,-Bdynamic
a dokonce i
gcc -o test test.c /usr/lib/libpthread.a

Pod Etchem je chyb ještě více.

Cituji z http://sources.redhat.com/bugzilla/show_bug.cgi?id=231 :
__syscall_error reference comes from PSEUDO macro 
(sysdep/unix/alpha/sysdep.h).
It's defined in libc(.a) objects, but not exported in libc.so

Takže podle mě to nemá řešení a pokud někdo nepřijde s nadějnou cestou 
jak dál, tak další experimenty vzdávám.


Díky za pomoc
Láďa



Další informace o konferenci Linux