Line
Link Here
|
0 |
-- uClibc-0.9.27/ldso/ldso/ldso.c |
0 |
++ uClibc-0.9.27/ldso/ldso/ldso.c |
Lines 74-86
void _dl_debug_state(void)
Link Here
|
74 |
static unsigned char *_dl_malloc_addr = 0; /* Lets _dl_malloc use the already allocated memory page */ |
74 |
static unsigned char *_dl_malloc_addr = 0; /* Lets _dl_malloc use the already allocated memory page */ |
75 |
static unsigned char *_dl_mmap_zero = 0; /* Also used by _dl_malloc */ |
75 |
static unsigned char *_dl_mmap_zero = 0; /* Also used by _dl_malloc */ |
76 |
|
76 |
|
77 |
#if defined (__SUPPORT_LD_DEBUG__) |
77 |
static struct elf_resolve **init_fini_list; |
78 |
static void debug_fini (int status, void *arg) |
78 |
static int nlist; |
|
|
79 |
static void __attribute_used__ _dl_fini(void) |
79 |
{ |
80 |
{ |
80 |
(void)status; |
81 |
int i; |
81 |
_dl_dprintf(_dl_debug_file,"\ncalling fini: %s\n\n", (const char*)arg); |
82 |
struct elf_resolve * tpnt; |
82 |
} |
83 |
|
|
|
84 |
for (i = 0; i < nlist; ++i) { |
85 |
tpnt = init_fini_list[i]; |
86 |
if (tpnt->init_flag & FINI_FUNCS_CALLED) |
87 |
continue; |
88 |
tpnt->init_flag |= FINI_FUNCS_CALLED; |
89 |
if (tpnt->dynamic_info[DT_FINI]) { |
90 |
void (*dl_elf_func) (void); |
91 |
|
92 |
dl_elf_func = (void (*)(void)) (intptr_t) (tpnt->loadaddr + tpnt->dynamic_info[DT_FINI]); |
93 |
#if defined (__SUPPORT_LD_DEBUG__) |
94 |
_dl_dprintf(_dl_debug_file,"\ncalling fini: %s\n\n", tpnt->libname); |
83 |
#endif |
95 |
#endif |
|
|
96 |
(*dl_elf_func) (); |
97 |
} |
98 |
} |
99 |
} |
84 |
|
100 |
|
85 |
void _dl_get_ready_to_run(struct elf_resolve *tpnt, unsigned long load_addr, |
101 |
void _dl_get_ready_to_run(struct elf_resolve *tpnt, unsigned long load_addr, |
86 |
Elf32_auxv_t auxvt[AT_EGID + 1], char **envp, |
102 |
Elf32_auxv_t auxvt[AT_EGID + 1], char **envp, |
Lines 89-110
void _dl_get_ready_to_run(struct elf_res
Link Here
|
89 |
ElfW(Phdr) *ppnt; |
112 |
ElfW(Phdr) *ppnt; |
90 |
Elf32_Dyn *dpnt; |
113 |
Elf32_Dyn *dpnt; |
91 |
char *lpntstr; |
114 |
char *lpntstr; |
92 |
int i, nlist, goof = 0, unlazy = 0, trace_loaded_objects = 0; |
115 |
int i, goof = 0, unlazy = 0, trace_loaded_objects = 0; |
93 |
struct elf_resolve **init_fini_list; |
|
|
94 |
struct dyn_elf *rpnt; |
116 |
struct dyn_elf *rpnt; |
95 |
struct elf_resolve *tcurr; |
117 |
struct elf_resolve *tcurr; |
96 |
struct elf_resolve *tpnt1; |
118 |
struct elf_resolve *tpnt1; |
97 |
struct elf_resolve app_tpnt_tmp; |
119 |
struct elf_resolve app_tpnt_tmp; |
98 |
struct elf_resolve *app_tpnt = &app_tpnt_tmp; |
120 |
struct elf_resolve *app_tpnt = &app_tpnt_tmp; |
99 |
struct r_debug *debug_addr; |
121 |
struct r_debug *debug_addr; |
100 |
unsigned long *lpnt; |
122 |
unsigned long *lpnt; |
101 |
int (*_dl_atexit) (void *); |
|
|
102 |
unsigned long *_dl_envp; /* The environment address */ |
123 |
unsigned long *_dl_envp; /* The environment address */ |
103 |
ElfW(Addr) relro_addr = 0; |
124 |
ElfW(Addr) relro_addr = 0; |
104 |
size_t relro_size = 0; |
125 |
size_t relro_size = 0; |
105 |
#if defined (__SUPPORT_LD_DEBUG__) |
|
|
106 |
int (*_dl_on_exit) (void (*FUNCTION)(int STATUS, void *ARG),void*); |
107 |
#endif |
108 |
|
126 |
|
109 |
#ifdef __SUPPORT_LD_DEBUG_EARLY__ |
127 |
#ifdef __SUPPORT_LD_DEBUG_EARLY__ |
110 |
/* Wahoo!!! */ |
128 |
/* Wahoo!!! */ |
Lines 623-634
Link Here
|
623 |
_dl_unmap_cache(); |
638 |
_dl_unmap_cache(); |
624 |
|
639 |
|
625 |
--nlist; /* Exclude the application. */ |
640 |
--nlist; /* Exclude the application. */ |
626 |
|
641 |
init_fini_list = _dl_malloc(nlist * sizeof(struct elf_resolve *)); |
627 |
/* As long as atexit() is used to run the FINI functions, we can use |
|
|
628 |
* alloca here. The use of atexit() should go away at some time as that |
629 |
* will make Valgring happy. |
630 |
*/ |
631 |
init_fini_list = alloca(nlist * sizeof(struct elf_resolve *)); |
632 |
i = 0; |
642 |
i = 0; |
633 |
for (tcurr = _dl_loaded_modules->next; tcurr; tcurr = tcurr->next) { |
643 |
for (tcurr = _dl_loaded_modules->next; tcurr; tcurr = tcurr->next) { |
634 |
init_fini_list[i++] = tcurr; |
644 |
init_fini_list[i++] = tcurr; |
Lines 798-809
next_lib2:
Link Here
|
798 |
} |
808 |
} |
799 |
#endif |
809 |
#endif |
800 |
|
810 |
|
801 |
_dl_atexit = (int (*)(void *)) (intptr_t) _dl_find_hash("atexit", _dl_symbol_tables, NULL, ELF_RTYPE_CLASS_PLT); |
|
|
802 |
#if defined (__SUPPORT_LD_DEBUG__) |
803 |
_dl_on_exit = (int (*)(void (*)(int, void *),void*)) |
804 |
(intptr_t) _dl_find_hash("on_exit", _dl_symbol_tables, NULL, ELF_RTYPE_CLASS_PLT); |
805 |
#endif |
806 |
|
807 |
/* Notify the debugger we have added some objects. */ |
811 |
/* Notify the debugger we have added some objects. */ |
808 |
_dl_debug_addr->r_state = RT_ADD; |
812 |
_dl_debug_addr->r_state = RT_ADD; |
809 |
_dl_debug_state(); |
813 |
_dl_debug_state(); |
Lines 828-853
next_lib2:
Link Here
|
828 |
|
832 |
|
829 |
(*dl_elf_func) (); |
833 |
(*dl_elf_func) (); |
830 |
} |
834 |
} |
831 |
tpnt->init_flag |= FINI_FUNCS_CALLED; |
|
|
832 |
if (_dl_atexit && tpnt->dynamic_info[DT_FINI]) { |
833 |
void (*dl_elf_func) (void); |
834 |
|
835 |
dl_elf_func = (void (*)(void)) (intptr_t) (tpnt->loadaddr + tpnt->dynamic_info[DT_FINI]); |
836 |
(*_dl_atexit) (dl_elf_func); |
837 |
#if defined (__SUPPORT_LD_DEBUG__) |
838 |
if(_dl_debug && _dl_on_exit) { |
839 |
(*_dl_on_exit)(debug_fini, tpnt->libname); |
840 |
} |
841 |
#endif |
842 |
} |
843 |
#if defined (__SUPPORT_LD_DEBUG__) |
844 |
else { |
845 |
if (!_dl_atexit) |
846 |
_dl_dprintf(_dl_debug_file, "%s: The address of atexit () is 0x0.\n", tpnt->libname); |
847 |
} |
848 |
#endif |
849 |
} |
835 |
} |
850 |
|
836 |
|
|
|
837 |
{ |
838 |
void (*__set__dl_fini) (void *); |
839 |
|
840 |
__set__dl_fini = (void (*)(void *)) (intptr_t) _dl_find_hash("_set__dl_fini", |
841 |
_dl_symbol_tables, NULL, ELF_RTYPE_CLASS_PLT); |
842 |
|
843 |
if (__set__dl_fini) |
844 |
(*__set__dl_fini) (_dl_fini); |
845 |
} |
846 |
|
851 |
/* Notify the debugger that all objects are now mapped in. */ |
847 |
/* Notify the debugger that all objects are now mapped in. */ |
852 |
_dl_debug_addr->r_state = RT_CONSISTENT; |
848 |
_dl_debug_addr->r_state = RT_CONSISTENT; |
853 |
_dl_debug_state(); |
849 |
_dl_debug_state(); |
854 |
-- uClibc-0.9.27/libc/misc/internals/__uClibc_main.c |
850 |
++ uClibc-0.9.27/libc/misc/internals/__uClibc_main.c |
Lines 158-163
void __uClibc_init(void)
Link Here
|
158 |
void (*__app_fini)(void) = NULL; |
158 |
void (*__app_fini)(void) = NULL; |
159 |
#endif |
159 |
#endif |
160 |
|
160 |
|
|
|
161 |
void attribute_hidden (*__dl_fini)(void) = NULL; |
162 |
|
163 |
void _set__dl_fini(void *fini_func) |
164 |
{ |
165 |
if (fini_func != NULL) |
166 |
__dl_fini = fini_func; |
167 |
} |
168 |
|
161 |
/* __uClibc_start_main is the new main stub for uClibc. This function is |
169 |
/* __uClibc_start_main is the new main stub for uClibc. This function is |
162 |
* called from crt0 (version 0.9.16 or newer), after ALL shared libraries |
170 |
* called from crt0 (version 0.9.16 or newer), after ALL shared libraries |
163 |
* are initialized, just before we call the application's main function. |
171 |
* are initialized, just before we call the application's main function. |
164 |
-- uClibc-0.9.27/libc/stdlib/atexit.c |
172 |
++ uClibc-0.9.27/libc/stdlib/atexit.c |
Lines 222-227
pthread_mutex_t mylock = PTHREAD_RECURSI
Link Here
|
222 |
extern void (*__app_fini)(void); |
222 |
extern void (*__app_fini)(void); |
223 |
#endif |
223 |
#endif |
224 |
|
224 |
|
|
|
225 |
extern void (*__dl_fini)(void); |
226 |
|
225 |
/* |
227 |
/* |
226 |
* Normal program termination |
228 |
* Normal program termination |
227 |
*/ |
229 |
*/ |
Lines 239-244
void exit(int rv)
Link Here
|
239 |
(__app_fini)(); |
241 |
(__app_fini)(); |
240 |
#endif |
242 |
#endif |
241 |
|
243 |
|
|
|
244 |
if (__dl_fini != NULL) |
245 |
(__dl_fini)(); |
246 |
|
242 |
/* If we are using stdio, try to shut it down. At the very least, |
247 |
/* If we are using stdio, try to shut it down. At the very least, |
243 |
* this will attempt to commit all buffered writes. It may also |
248 |
* this will attempt to commit all buffered writes. It may also |
244 |
* unbuffer all writable files, or close them outright. |
249 |
* unbuffer all writable files, or close them outright. |