xref: /titanic_52/usr/src/cmd/sgs/librtld/common/syms.c (revision 1ae0874509b6811fdde1dfd46f0d93fd09867a3f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	Copyright (c) 1995-2001 by Sun Microsystems, Inc.
24  *	All rights reserved.
25  *
26  * Update the symbol table entries:
27  *
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.
30  *
31  *  o	The address of the `_edata' and `_end' symbols, and their associated
32  *	section, is updated to reflect any new heap addition.
33  */
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #include	<libelf.h>
37 #include	<string.h>
38 #include	"sgs.h"
39 #include	"machdep.h"
40 #include	"msg.h"
41 #include	"_librtld.h"
42 
43 void
44 update_sym(Cache *cache, Cache *_cache, Addr edata, Half endx, Addr addr)
45 {
46 	char	*strs;
47 	Sym	*syms;
48 	Shdr	*shdr;
49 	Xword	symn, cnt;
50 
51 	/*
52 	 * Set up to read the symbol table and its associated string table.
53 	 */
54 	shdr = _cache->c_shdr;
55 	syms = (Sym *)_cache->c_data->d_buf;
56 	symn = shdr->sh_size / shdr->sh_entsize;
57 
58 	strs = (char *)cache[shdr->sh_link].c_data->d_buf;
59 
60 	/*
61 	 * Loop through the symbol table looking for `_end' and `_edata'.
62 	 */
63 	for (cnt = 0; cnt < symn; cnt++, syms++) {
64 		char	*name = strs + syms->st_name;
65 
66 		if (addr) {
67 			if (syms->st_value)
68 				syms->st_value += addr;
69 		}
70 
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;
76 
77 		syms->st_value = edata + addr;
78 		if (endx)
79 			syms->st_shndx = endx;
80 	}
81 }
82