Changeset f570cdf in mainline for uspace/lib/c/generic/rtld/module.c


Ignore:
Timestamp:
2016-05-24T15:32:57Z (9 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c170438
Parents:
dcc150cb (diff), 0a981e3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/rtld/module.c

    rdcc150cb rf570cdf  
    3737#include <adt/list.h>
    3838#include <elf/elf_load.h>
     39#include <errno.h>
    3940#include <fcntl.h>
    4041#include <loader/pcb.h>
     
    4849#include <rtld/rtld_arch.h>
    4950#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}
    5084
    5185/** (Eagerly) process all relocation tables in a module.
     
    135169
    136170        m = calloc(1, sizeof(module_t));
    137         if (!m) {
     171        if (m == NULL) {
    138172                printf("malloc failed\n");
    139173                exit(1);
     
    141175
    142176        m->rtld = rtld;
     177        m->id = rtld_get_next_id(rtld);
     178
    143179        if ((flags & mlf_local) != 0)
    144180                m->local = true;
     
    181217        /* Insert into the list of loaded modules */
    182218        list_append(&m->modules_link, &rtld->modules);
     219
     220        /* Copy TLS info */
     221        m->tdata = info.tls.tdata;
     222        m->tdata_size = info.tls.tdata_size;
     223        m->tbss_size = info.tls.tbss_size;
     224        m->tls_align = info.tls.tls_align;
     225
     226        DPRINTF("tdata at %p size %zu, tbss size %zu\n",
     227            m->tdata, m->tdata_size, m->tbss_size);
    183228
    184229        return m;
     
    243288}
    244289
     290/** Find module structure by ID. */
     291module_t *module_by_id(rtld_t *rtld, unsigned long id)
     292{
     293        list_foreach(rtld->modules, modules_link, module_t, m) {
     294                if (m->id == id)
     295                        return m;
     296        }
     297
     298        return NULL;
     299}
     300
    245301/** Process relocations in modules.
    246302 *
     
    260316}
    261317
     318void modules_process_tls(rtld_t *rtld)
     319{
     320#ifdef CONFIG_TLS_VARIANT_1
     321        list_foreach(rtld->modules, modules_link, module_t, m) {
     322                m->ioffs = rtld->tls_size;
     323                list_append(&m->imodules_link, &rtmd->imodules);
     324                rtld->tls_size += m->tdata_size + m->tbss_size;
     325        }
     326#else /* CONFIG_TLS_VARIANT_2 */
     327        size_t offs;
     328
     329        list_foreach(rtld->modules, modules_link, module_t, m) {
     330                rtld->tls_size += m->tdata_size + m->tbss_size;
     331        }
     332
     333        offs = 0;
     334        list_foreach(rtld->modules, modules_link, module_t, m) {
     335                offs += m->tdata_size + m->tbss_size;
     336                m->ioffs = rtld->tls_size - offs;
     337                list_append(&m->imodules_link, &rtld->imodules);
     338        }
     339#endif
     340}
     341
    262342/** Clear BFS tags of all modules.
    263343 */
Note: See TracChangeset for help on using the changeset viewer.