dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / sgs / librtld / common / syms.c
blob2de6edd7d92db848e905e8951e0cc6cdd9d14d3a
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 * Update the symbol table entries:
28 * o If addr is non-zero then every symbol entry is updated to indicate the
29 * new location to which the object will be mapped.
31 * o The address of the `_edata' and `_end' symbols, and their associated
32 * section, is updated to reflect any new heap addition.
34 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <libelf.h>
37 #include <string.h>
38 #include "sgs.h"
39 #include "machdep.h"
40 #include "msg.h"
41 #include "_librtld.h"
43 void
44 update_sym(Cache *cache, Cache *_cache, Addr edata, Half endx, Addr addr)
46 char *strs;
47 Sym *syms;
48 Shdr *shdr;
49 Xword symn, cnt;
52 * Set up to read the symbol table and its associated string table.
54 shdr = _cache->c_shdr;
55 syms = (Sym *)_cache->c_data->d_buf;
56 symn = shdr->sh_size / shdr->sh_entsize;
58 strs = (char *)cache[shdr->sh_link].c_data->d_buf;
61 * Loop through the symbol table looking for `_end' and `_edata'.
63 for (cnt = 0; cnt < symn; cnt++, syms++) {
64 char *name = strs + syms->st_name;
66 if (addr) {
67 if (syms->st_value)
68 syms->st_value += addr;
71 if ((name[0] != '_') || (name[1] != 'e'))
72 continue;
73 if (strcmp(name, MSG_ORIG(MSG_SYM_END)) &&
74 strcmp(name, MSG_ORIG(MSG_SYM_EDATA)))
75 continue;
77 syms->st_value = edata + addr;
78 if (endx)
79 syms->st_shndx = endx;
83 int
84 syminfo(Cache *_cache, Alist **nodirect)
86 Syminfo *info;
87 Shdr *shdr;
88 Word num, ndx;
90 shdr = _cache->c_shdr;
91 info = (Syminfo *)_cache->c_data->d_buf;
92 num = (Word)(shdr->sh_size / shdr->sh_entsize);
95 * Traverse the syminfo section recording the index of all nodirect
96 * symbols.
98 for (ndx = 1, info++; ndx < num; ndx++, info++) {
99 if ((info->si_flags & SYMINFO_FLG_NOEXTDIRECT) == 0)
100 continue;
102 if (alist_append(nodirect, &ndx, sizeof (Word), 20) == 0)
103 return (1);
105 return (0);