xref: /onnv-gate/usr/src/cmd/sgs/librtld/common/syms.c (revision 2850:689acf945b89)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2850Srie  * Common Development and Distribution License (the "License").
6*2850Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*2850Srie 
220Sstevel@tonic-gate /*
23*2850Srie  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*2850Srie  * Use is subject to license terms.
250Sstevel@tonic-gate  *
260Sstevel@tonic-gate  * Update the symbol table entries:
270Sstevel@tonic-gate  *
280Sstevel@tonic-gate  *  o	If addr is non-zero then every symbol entry is updated to indicate the
290Sstevel@tonic-gate  *	new location to which the object will be mapped.
300Sstevel@tonic-gate  *
310Sstevel@tonic-gate  *  o	The address of the `_edata' and `_end' symbols, and their associated
320Sstevel@tonic-gate  *	section, is updated to reflect any new heap addition.
330Sstevel@tonic-gate  */
340Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #include	<libelf.h>
370Sstevel@tonic-gate #include	<string.h>
380Sstevel@tonic-gate #include	"sgs.h"
390Sstevel@tonic-gate #include	"machdep.h"
400Sstevel@tonic-gate #include	"msg.h"
410Sstevel@tonic-gate #include	"_librtld.h"
420Sstevel@tonic-gate 
430Sstevel@tonic-gate void
update_sym(Cache * cache,Cache * _cache,Addr edata,Half endx,Addr addr)440Sstevel@tonic-gate update_sym(Cache *cache, Cache *_cache, Addr edata, Half endx, Addr addr)
450Sstevel@tonic-gate {
460Sstevel@tonic-gate 	char	*strs;
470Sstevel@tonic-gate 	Sym	*syms;
480Sstevel@tonic-gate 	Shdr	*shdr;
490Sstevel@tonic-gate 	Xword	symn, cnt;
500Sstevel@tonic-gate 
510Sstevel@tonic-gate 	/*
520Sstevel@tonic-gate 	 * Set up to read the symbol table and its associated string table.
530Sstevel@tonic-gate 	 */
540Sstevel@tonic-gate 	shdr = _cache->c_shdr;
550Sstevel@tonic-gate 	syms = (Sym *)_cache->c_data->d_buf;
560Sstevel@tonic-gate 	symn = shdr->sh_size / shdr->sh_entsize;
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 	strs = (char *)cache[shdr->sh_link].c_data->d_buf;
590Sstevel@tonic-gate 
600Sstevel@tonic-gate 	/*
610Sstevel@tonic-gate 	 * Loop through the symbol table looking for `_end' and `_edata'.
620Sstevel@tonic-gate 	 */
630Sstevel@tonic-gate 	for (cnt = 0; cnt < symn; cnt++, syms++) {
640Sstevel@tonic-gate 		char	*name = strs + syms->st_name;
650Sstevel@tonic-gate 
660Sstevel@tonic-gate 		if (addr) {
670Sstevel@tonic-gate 			if (syms->st_value)
680Sstevel@tonic-gate 				syms->st_value += addr;
690Sstevel@tonic-gate 		}
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 		if ((name[0] != '_') || (name[1] != 'e'))
720Sstevel@tonic-gate 			continue;
730Sstevel@tonic-gate 		if (strcmp(name, MSG_ORIG(MSG_SYM_END)) &&
740Sstevel@tonic-gate 		    strcmp(name, MSG_ORIG(MSG_SYM_EDATA)))
750Sstevel@tonic-gate 			continue;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 		syms->st_value = edata + addr;
780Sstevel@tonic-gate 		if (endx)
790Sstevel@tonic-gate 			syms->st_shndx = endx;
800Sstevel@tonic-gate 	}
810Sstevel@tonic-gate }
82*2850Srie 
83*2850Srie int
syminfo(Cache * _cache,Alist ** nodirect)84*2850Srie syminfo(Cache *_cache, Alist **nodirect)
85*2850Srie {
86*2850Srie 	Syminfo	*info;
87*2850Srie 	Shdr	*shdr;
88*2850Srie 	Word	num, ndx;
89*2850Srie 
90*2850Srie 	shdr = _cache->c_shdr;
91*2850Srie 	info = (Syminfo *)_cache->c_data->d_buf;
92*2850Srie 	num = (Word)(shdr->sh_size / shdr->sh_entsize);
93*2850Srie 
94*2850Srie 	/*
95*2850Srie 	 * Traverse the syminfo section recording the index of all nodirect
96*2850Srie 	 * symbols.
97*2850Srie 	 */
98*2850Srie 	for (ndx = 1, info++; ndx < num; ndx++, info++) {
99*2850Srie 		if ((info->si_flags & SYMINFO_FLG_NOEXTDIRECT) == 0)
100*2850Srie 			continue;
101*2850Srie 
102*2850Srie 		if (alist_append(nodirect, &ndx, sizeof (Word), 20) == 0)
103*2850Srie 			return (1);
104*2850Srie 	}
105*2850Srie 	return (0);
106*2850Srie }
107