Use macro STATIC_LIB_REQUIRE to declare a symbol should be linked into

static binary.
This commit is contained in:
David Xu 2006-01-10 04:53:03 +00:00
parent 174cda8010
commit 9572a73405
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=154160
2 changed files with 74 additions and 95 deletions

View file

@ -33,36 +33,22 @@
* $FreeBSD$ * $FreeBSD$
*/ */
/* Allocate space for global thread variables here: */
#define GLOBAL_PTHREAD_PRIVATE
#include "namespace.h" #include "namespace.h"
#include <sys/param.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/signalvar.h> #include <sys/signalvar.h>
#include <machine/reg.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/uio.h>
#include <sys/socket.h>
#include <sys/event.h>
#include <sys/stat.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/ttycom.h> #include <sys/ttycom.h>
#include <sys/wait.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <dirent.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <paths.h> #include <paths.h>
#include <pthread.h> #include <pthread.h>
#include <pthread_np.h> #include <pthread_np.h>
#include <signal.h> #include <signal.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include "un-namespace.h" #include "un-namespace.h"
@ -133,62 +119,59 @@ static void init_main_thread(struct pthread *thread);
* All weak references used within libc should be in this table. * All weak references used within libc should be in this table.
* This is so that static libraries will work. * This is so that static libraries will work.
*/ */
static void *references[] = { STATIC_LIB_REQUIRE(_accept);
&_accept, STATIC_LIB_REQUIRE(_bind);
&_bind, STATIC_LIB_REQUIRE(_close);
&_close, STATIC_LIB_REQUIRE(_connect);
&_connect, STATIC_LIB_REQUIRE(_dup);
&_dup, STATIC_LIB_REQUIRE(_dup2);
&_dup2, STATIC_LIB_REQUIRE(_execve);
&_execve, STATIC_LIB_REQUIRE(_fcntl);
&_fcntl, STATIC_LIB_REQUIRE(_flock);
&_flock, STATIC_LIB_REQUIRE(_flockfile);
&_flockfile, STATIC_LIB_REQUIRE(_fstat);
&_fstat, STATIC_LIB_REQUIRE(_fstatfs);
&_fstatfs, STATIC_LIB_REQUIRE(_fsync);
&_fsync, STATIC_LIB_REQUIRE(_getdirentries);
&_funlockfile, STATIC_LIB_REQUIRE(_getlogin);
&_getdirentries, STATIC_LIB_REQUIRE(_getpeername);
&_getlogin, STATIC_LIB_REQUIRE(_getsockname);
&_getpeername, STATIC_LIB_REQUIRE(_getsockopt);
&_getsockname, STATIC_LIB_REQUIRE(_ioctl);
&_getsockopt, STATIC_LIB_REQUIRE(_kevent);
&_ioctl, STATIC_LIB_REQUIRE(_listen);
&_kevent, STATIC_LIB_REQUIRE(_nanosleep);
&_listen, STATIC_LIB_REQUIRE(_open);
&_nanosleep, STATIC_LIB_REQUIRE(_pthread_getspecific);
&_open, STATIC_LIB_REQUIRE(_pthread_key_create);
&_pthread_getspecific, STATIC_LIB_REQUIRE(_pthread_key_delete);
&_pthread_key_create, STATIC_LIB_REQUIRE(_pthread_mutex_destroy);
&_pthread_key_delete, STATIC_LIB_REQUIRE(_pthread_mutex_init);
&_pthread_mutex_destroy, STATIC_LIB_REQUIRE(_pthread_mutex_lock);
&_pthread_mutex_init, STATIC_LIB_REQUIRE(_pthread_mutex_trylock);
&_pthread_mutex_lock, STATIC_LIB_REQUIRE(_pthread_mutex_unlock);
&_pthread_mutex_trylock, STATIC_LIB_REQUIRE(_pthread_mutexattr_init);
&_pthread_mutex_unlock, STATIC_LIB_REQUIRE(_pthread_mutexattr_destroy);
&_pthread_mutexattr_init, STATIC_LIB_REQUIRE(_pthread_mutexattr_settype);
&_pthread_mutexattr_destroy, STATIC_LIB_REQUIRE(_pthread_once);
&_pthread_mutexattr_settype, STATIC_LIB_REQUIRE(_pthread_setspecific);
&_pthread_once, STATIC_LIB_REQUIRE(_read);
&_pthread_setspecific, STATIC_LIB_REQUIRE(_readv);
&_read, STATIC_LIB_REQUIRE(_recvfrom);
&_readv, STATIC_LIB_REQUIRE(_recvmsg);
&_recvfrom, STATIC_LIB_REQUIRE(_select);
&_recvmsg, STATIC_LIB_REQUIRE(_sendmsg);
&_select, STATIC_LIB_REQUIRE(_sendto);
&_sendmsg, STATIC_LIB_REQUIRE(_setsockopt);
&_sendto, STATIC_LIB_REQUIRE(_sigaction);
&_setsockopt, STATIC_LIB_REQUIRE(_sigprocmask);
&_sigaction, STATIC_LIB_REQUIRE(_sigsuspend);
&_sigprocmask, STATIC_LIB_REQUIRE(_socket);
&_sigsuspend, STATIC_LIB_REQUIRE(_socketpair);
&_socket, STATIC_LIB_REQUIRE(_thread_init_hack);
&_socketpair, STATIC_LIB_REQUIRE(_wait4);
&_thread_init_hack, STATIC_LIB_REQUIRE(_write);
&_wait4, STATIC_LIB_REQUIRE(_writev);
&_write,
&_writev
};
/* /*
* These are needed when linking statically. All references within * These are needed when linking statically. All references within
@ -196,19 +179,20 @@ static void *references[] = {
* if they are not (strongly) referenced by the application or other * if they are not (strongly) referenced by the application or other
* libraries, then the actual functions will not be loaded. * libraries, then the actual functions will not be loaded.
*/ */
static void *libgcc_references[] = { STATIC_LIB_REQUIRE(_pthread_once);
&_pthread_once, STATIC_LIB_REQUIRE(_pthread_key_create);
&_pthread_key_create, STATIC_LIB_REQUIRE(_pthread_key_delete);
&_pthread_key_delete, STATIC_LIB_REQUIRE(_pthread_getspecific);
&_pthread_getspecific, STATIC_LIB_REQUIRE(_pthread_setspecific);
&_pthread_setspecific, STATIC_LIB_REQUIRE(_pthread_mutex_init);
&_pthread_mutex_init, STATIC_LIB_REQUIRE(_pthread_mutex_destroy);
&_pthread_mutex_destroy, STATIC_LIB_REQUIRE(_pthread_mutex_lock);
&_pthread_mutex_lock, STATIC_LIB_REQUIRE(_pthread_mutex_trylock);
&_pthread_mutex_trylock, STATIC_LIB_REQUIRE(_pthread_mutex_unlock);
&_pthread_mutex_unlock, STATIC_LIB_REQUIRE(_pthread_create);
&_pthread_create
}; /* Pull in all symbols required by libthread_db */
STATIC_LIB_REQUIRE(_thread_state_running);
#define DUAL_ENTRY(entry) \ #define DUAL_ENTRY(entry) \
(pthread_func_t)entry, (pthread_func_t)entry (pthread_func_t)entry, (pthread_func_t)entry
@ -247,7 +231,6 @@ static pthread_func_t jmp_table[][2] = {
{DUAL_ENTRY(_pthread_sigmask)} /* PJT_SIGMASK */ {DUAL_ENTRY(_pthread_sigmask)} /* PJT_SIGMASK */
}; };
extern int _thread_state_running;
static int init_once = 0; static int init_once = 0;
/* /*
@ -293,16 +276,6 @@ _libpthread_init(struct pthread *curthread)
/* Only initialize the threaded application once. */ /* Only initialize the threaded application once. */
return; return;
/*
* Make gcc quiescent about {,libgcc_}references not being
* referenced:
*/
if ((references[0] == NULL) || (libgcc_references[0] == NULL))
PANIC("Failed loading mandatory references in _thread_init");
/* Pull debug symbols in for static binary */
_thread_state_running = PS_RUNNING;
/* /*
* Check the size of the jump table to make sure it is preset * Check the size of the jump table to make sure it is preset
* with the correct number of entries. * with the correct number of entries.

View file

@ -83,6 +83,12 @@ typedef TAILQ_HEAD(atfork_head, pthread_atfork) atfork_head;
#define THR_ASSERT(cond, msg) #define THR_ASSERT(cond, msg)
#endif #endif
#ifdef PIC
# define STATIC_LIB_REQUIRE(name)
#else
# define STATIC_LIB_REQUIRE(name) __asm (".globl " #name)
#endif
#define TIMESPEC_ADD(dst, src, val) \ #define TIMESPEC_ADD(dst, src, val) \
do { \ do { \
(dst)->tv_sec = (src)->tv_sec + (val)->tv_sec; \ (dst)->tv_sec = (src)->tv_sec + (val)->tv_sec; \