source: mainline/uspace/lib/c/generic/rtld/dynamic.c@ 1d6dd2a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1d6dd2a was 1d6dd2a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Remove unnecessary includes from <stdio.h>.

  • Property mode set to 100644
File size: 4.5 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 <stdio.h>
38#include <inttypes.h>
39#include <str.h>
40
41#include <rtld/elf_dyn.h>
42#include <rtld/dynamic.h>
43#include <rtld/rtld.h>
44#include <rtld/rtld_debug.h>
45
46void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info)
47{
48 elf_dyn_t *dp = dyn_ptr;
49
50 void *d_ptr;
51 elf_word d_val;
52
53 elf_word soname_idx;
54 elf_word rpath_idx;
55
56 DPRINTF("memset\n");
57 memset(info, 0, sizeof(dyn_info_t));
58
59 soname_idx = 0;
60 rpath_idx = 0;
61
62 DPRINTF("pass 1\n");
63 while (dp->d_tag != DT_NULL) {
64 d_ptr = (void *)((uint8_t *)dp->d_un.d_ptr + bias);
65 d_val = dp->d_un.d_val;
66 DPRINTF("tag=%u ptr=0x%x val=%u\n", (unsigned)dp->d_tag,
67 (unsigned)d_ptr, (unsigned)d_val);
68
69 switch (dp->d_tag) {
70
71 case DT_PLTRELSZ: info->plt_rel_sz = d_val; break;
72 case DT_PLTGOT: info->plt_got = d_ptr; break;
73 case DT_HASH: info->hash = d_ptr; break;
74 case DT_STRTAB: info->str_tab = d_ptr; break;
75 case DT_SYMTAB: info->sym_tab = d_ptr; break;
76 case DT_RELA: info->rela = d_ptr; break;
77 case DT_RELASZ: info->rela_sz = d_val; break;
78 case DT_RELAENT: info->rela_ent = d_val; break;
79 case DT_STRSZ: info->str_sz = d_val; break;
80 case DT_SYMENT: info->sym_ent = d_val; break;
81 case DT_INIT: info->init = d_ptr; break;
82 case DT_FINI: info->fini = d_ptr; break;
83 case DT_SONAME: soname_idx = d_val; break;
84 case DT_RPATH: rpath_idx = d_val; break;
85 case DT_SYMBOLIC: info->symbolic = true; break;
86 case DT_REL: info->rel = d_ptr; break;
87 case DT_RELSZ: info->rel_sz = d_val; break;
88 case DT_RELENT: info->rel_ent = d_val; break;
89 case DT_PLTREL: info->plt_rel = d_val; break;
90 case DT_TEXTREL: info->text_rel = true; break;
91 case DT_JMPREL: info->jmp_rel = d_ptr; break;
92 case DT_BIND_NOW: info->bind_now = true; break;
93
94 default:
95 if (dp->d_tag >= DT_LOPROC && dp->d_tag <= DT_HIPROC)
96 dyn_parse_arch(dp, bias, info);
97 break;
98 }
99
100 ++dp;
101 }
102
103 info->soname = info->str_tab + soname_idx;
104 info->rpath = info->str_tab + rpath_idx;
105
106 /* This will be useful for parsing dependencies later */
107 info->dynamic = dyn_ptr;
108
109 DPRINTF("str_tab=0x%" PRIxPTR ", soname_idx=0x%x, soname=0x%" PRIxPTR "\n",
110 (uintptr_t)info->soname, soname_idx, (uintptr_t)info->soname);
111 DPRINTF("soname='%s'\n", info->soname);
112 DPRINTF("rpath='%s'\n", info->rpath);
113 DPRINTF("hash=0x%" PRIxPTR "\n", (uintptr_t)info->hash);
114 DPRINTF("dt_rela=0x%" PRIxPTR "\n", (uintptr_t)info->rela);
115 DPRINTF("dt_rela_sz=0x%" PRIxPTR "\n", (uintptr_t)info->rela_sz);
116 DPRINTF("dt_rel=0x%" PRIxPTR "\n", (uintptr_t)info->rel);
117 DPRINTF("dt_rel_sz=0x%" PRIxPTR "\n", (uintptr_t)info->rel_sz);
118
119 /*
120 * Now that we have a pointer to the string table,
121 * we can parse DT_NEEDED fields (which contain offsets into it).
122 */
123
124 DPRINTF("pass 2\n");
125 dp = dyn_ptr;
126 while (dp->d_tag != DT_NULL) {
127 d_val = dp->d_un.d_val;
128
129 switch (dp->d_tag) {
130 case DT_NEEDED:
131 /* Assume just for now there's only one dependency */
132 info->needed = info->str_tab + d_val;
133 DPRINTF("needed:'%s'\n", info->needed);
134 break;
135
136 default: break;
137 }
138
139 ++dp;
140 }
141}
142
143/** @}
144 */
Note: See TracBrowser for help on using the repository browser.