Changeset 17341d4 in mainline for uspace/lib/c/generic/rtld/rtld.c


Ignore:
Timestamp:
2016-04-20T17:25:48Z (8 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
dc0d8b52
Parents:
13dfa3f9
Message:

Move rtld internals out of loader. Stop misusing rtld instance from current environment for loading dynamically linked executables.

File:
1 edited

Legend:

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

    r13dfa3f9 r17341d4  
    3535 */
    3636
     37#include <errno.h>
     38#include <rtld/module.h>
    3739#include <rtld/rtld.h>
     40#include <rtld/rtld_debug.h>
     41#include <stdlib.h>
    3842
    39 runtime_env_t *runtime_env;
    40 static runtime_env_t rt_env_static;
     43rtld_t *runtime_env;
     44static rtld_t rt_env_static;
     45static module_t prog_mod;
    4146
    42 /** Initialize the loder for use in a statically-linked binary. */
     47/** Initialize the runtime linker for use in a statically-linked executable. */
    4348void rtld_init_static(void)
    4449{
     
    4954}
    5055
     56/** Initialize and process a dynamically linked executable.
     57 *
     58 * @param p_info Program info
     59 * @return EOK on success or non-zero error code
     60 */
     61int rtld_prog_process(elf_finfo_t *p_info, rtld_t **rre)
     62{
     63        rtld_t *env;
     64
     65        DPRINTF("Load dynamically linked program.\n");
     66
     67        /* Allocate new RTLD environment to pass to the loaded program */
     68        env = calloc(1, sizeof(rtld_t));
     69        if (env == NULL)
     70                return ENOMEM;
     71
     72        /*
     73         * First we need to process dynamic sections of the executable
     74         * program and insert it into the module graph.
     75         */
     76
     77        DPRINTF("Parse program .dynamic section at %p\n", p_info->dynamic);
     78        dynamic_parse(p_info->dynamic, 0, &prog_mod.dyn);
     79        prog_mod.bias = 0;
     80        prog_mod.dyn.soname = "[program]";
     81        prog_mod.rtld = env;
     82
     83        /* Initialize list of loaded modules */
     84        list_initialize(&env->modules);
     85        list_append(&prog_mod.modules_link, &env->modules);
     86
     87        /* Pointer to program module. Used as root of the module graph. */
     88        env->program = &prog_mod;
     89
     90        /* Work around non-existent memory space allocation. */
     91        env->next_bias = 0x1000000;
     92
     93        /*
     94         * Now we can continue with loading all other modules.
     95         */
     96
     97        DPRINTF("Load all program dependencies\n");
     98        module_load_deps(&prog_mod);
     99
     100        /*
     101         * Now relocate/link all modules together.
     102         */
     103
     104        /* Process relocations in all modules */
     105        DPRINTF("Relocate all modules\n");
     106        modules_process_relocs(env, &prog_mod);
     107
     108        *rre = env;
     109        return EOK;
     110}
     111
    51112/** @}
    52113 */
Note: See TracChangeset for help on using the changeset viewer.