Changeset 153c7a29 in mainline


Ignore:
Timestamp:
2016-05-22T17:46:10Z (9 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0dc2fec
Parents:
2112a79
Message:

Since dlopen() sets up runtime_env, we would no longer use the static TLS. Thus set up runtime_env right away and convert static TLS to dynamic TLS.

Location:
uspace
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/dlfcn.c

    r2112a79 r153c7a29  
    4949        module_t *m;
    5050
    51         if (runtime_env == NULL) {
    52                 printf("Dynamic linker not set up -- initializing.\n");
    53                 rtld_init_static();
    54         }
    55 
    56         printf("dlopen(\"%s\", %d)\n", path, flag);
    57 
    58         printf("module_find('%s')\n", path);
    5951        m = module_find(runtime_env, path);
    6052        if (m == NULL) {
    61                 printf("NULL. module_load('%s')\n", path);
    6253                m = module_load(runtime_env, path, mlf_local);
    63                 printf("module_load_deps(m)\n");
    6454                module_load_deps(m, mlf_local);
    6555                /* Now relocate. */
    66                 printf("module_process_relocs(m)\n");
    6756                module_process_relocs(m);
    68         } else {
    69                 printf("not NULL\n");
    7057        }
    7158
     
    8168        module_t *sm;
    8269
    83         printf("dlsym(0x%lx, \"%s\")\n", (long)mod, sym_name);
    8470        sd = symbol_bfs_find(sym_name, (module_t *) mod, &sm);
    8571        if (sd != NULL) {
  • uspace/lib/c/generic/libc.c

    r2112a79 r153c7a29  
    4141 */
    4242
     43#include <errno.h>
    4344#include <libc.h>
    4445#include <stdlib.h>
     
    6566void __main(void *pcb_ptr)
    6667{
     68        /* Initialize user task run-time environment */
     69        __malloc_init();
     70       
    6771        /* Save the PCB pointer */
    6872        __pcb = (pcb_t *) pcb_ptr;
     
    7175        if (__pcb != NULL && __pcb->rtld_runtime != NULL) {
    7276                runtime_env = (rtld_t *) __pcb->rtld_runtime;
     77        } else {
     78                if (rtld_init_static() != EOK)
     79                        abort();
    7380        }
    7481#endif
    75         /* Initialize user task run-time environment */
    76         __malloc_init();
    7782       
    7883        fibril_t *fibril = fibril_setup();
  • uspace/lib/c/generic/rtld/module.c

    r2112a79 r153c7a29  
    4949#include <rtld/rtld_arch.h>
    5050#include <rtld/module.h>
     51
     52/** Create module for static executable.
     53 *
     54 * @param rtld Run-time dynamic linker
     55 * @param rmodule Place to store pointer to new module or @c NULL
     56 * @return EOK on success, ENOMEM if out of memory
     57 */
     58int module_create_static_exec(rtld_t *rtld, module_t **rmodule)
     59{
     60        module_t *module;
     61
     62        module = calloc(1, sizeof(module_t));
     63        if (module == NULL)
     64                return ENOMEM;
     65
     66        module->id = rtld_get_next_id(rtld);
     67        module->dyn.soname = "[program]";
     68
     69        module->rtld = rtld;
     70        module->exec = true;
     71        module->local = true;
     72
     73        module->tdata = &_tdata_start;
     74        module->tdata_size = &_tdata_end - &_tdata_start;
     75        module->tbss_size = &_tbss_end - &_tbss_start;
     76        module->tls_align = (uintptr_t)&_tls_alignment;
     77
     78        list_append(&module->modules_link, &rtld->modules);
     79
     80        if (rmodule != NULL)
     81                *rmodule = module;
     82        return EOK;
     83}
    5184
    5285/** (Eagerly) process all relocation tables in a module.
     
    191224        m->tls_align = info.tls.tls_align;
    192225
    193         printf("tdata at %p size %zu, tbss size %zu\n",
     226        DPRINTF("tdata at %p size %zu, tbss size %zu\n",
    194227            m->tdata, m->tdata_size, m->tbss_size);
    195228
  • uspace/lib/c/generic/rtld/rtld.c

    r2112a79 r153c7a29  
    4545
    4646/** Initialize the runtime linker for use in a statically-linked executable. */
    47 void rtld_init_static(void)
    48 {
     47int rtld_init_static(void)
     48{
     49        int rc;
     50
    4951        runtime_env = &rt_env_static;
    5052        list_initialize(&runtime_env->modules);
     
    5254        runtime_env->next_bias = 0x2000000;
    5355        runtime_env->program = NULL;
     56        runtime_env->next_id = 1;
     57
     58        rc = module_create_static_exec(runtime_env, NULL);
     59        if (rc != EOK)
     60                return rc;
     61
     62        modules_process_tls(runtime_env);
     63
     64        return EOK;
    5465}
    5566
     
    98109        prog->tls_align = p_info->tls.tls_align;
    99110
    100         printf("prog tdata at %p size %zu, tbss size %zu\n",
     111        DPRINTF("prog tdata at %p size %zu, tbss size %zu\n",
    101112            prog->tdata, prog->tdata_size, prog->tbss_size);
    102113
  • uspace/lib/c/include/rtld/module.h

    r2112a79 r153c7a29  
    4242#include <types/rtld/rtld.h>
    4343
     44extern int module_create_static_exec(rtld_t *, module_t **);
    4445extern void module_process_relocs(module_t *);
    4546extern module_t *module_find(rtld_t *, const char *);
  • uspace/lib/c/include/rtld/rtld.h

    r2112a79 r153c7a29  
    4646extern rtld_t *runtime_env;
    4747
    48 extern void rtld_init_static(void);
     48extern int rtld_init_static(void);
    4949extern int rtld_prog_process(elf_finfo_t *, rtld_t **);
    5050extern tcb_t *rtld_tls_make(rtld_t *);
  • uspace/srv/loader/main.c

    r2112a79 r153c7a29  
    269269       
    270270        pcb.filc = filc;
    271         printf("dynamic=%p rtld_env=%p\n", pcb.dynamic, pcb.rtld_runtime);
    272271       
    273272        async_answer_0(rid, rc);
Note: See TracChangeset for help on using the changeset viewer.