source: mainline/uspace/lib/c/generic/rtld/rtld.c@ fe036fe

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fe036fe was 5035ba05, checked in by Jiri Svoboda <jiri@…>, 9 years ago

Default symbol search vs. dlsym's BFS search.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * Copyright (c) 2008 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup rtld rtld
30 * @brief
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <errno.h>
38#include <rtld/module.h>
39#include <rtld/rtld.h>
40#include <rtld/rtld_debug.h>
41#include <stdlib.h>
42
43rtld_t *runtime_env;
44static rtld_t rt_env_static;
45static module_t prog_mod;
46
47/** Initialize the runtime linker for use in a statically-linked executable. */
48void rtld_init_static(void)
49{
50 runtime_env = &rt_env_static;
51 list_initialize(&runtime_env->modules);
52 runtime_env->next_bias = 0x2000000;
53 runtime_env->program = NULL;
54}
55
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 prog_mod.exec = true;
83 prog_mod.local = false;
84
85 /* Initialize list of loaded modules */
86 list_initialize(&env->modules);
87 list_append(&prog_mod.modules_link, &env->modules);
88
89 /* Pointer to program module. Used as root of the module graph. */
90 env->program = &prog_mod;
91
92 /* Work around non-existent memory space allocation. */
93 env->next_bias = 0x1000000;
94
95 /*
96 * Now we can continue with loading all other modules.
97 */
98
99 DPRINTF("Load all program dependencies\n");
100 module_load_deps(&prog_mod, 0);
101
102 /*
103 * Now relocate/link all modules together.
104 */
105
106 /* Process relocations in all modules */
107 DPRINTF("Relocate all modules\n");
108 modules_process_relocs(env, &prog_mod);
109
110 *rre = env;
111 return EOK;
112}
113
114/** @}
115 */
Note: See TracBrowser for help on using the repository browser.