17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*2926dd2eSrie * Common Development and Distribution License (the "License").
6*2926dd2eSrie * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21*2926dd2eSrie
227c478bd9Sstevel@tonic-gate /*
23*2926dd2eSrie * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24*2926dd2eSrie * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate *
267c478bd9Sstevel@tonic-gate * Update the symbol table entries:
277c478bd9Sstevel@tonic-gate *
287c478bd9Sstevel@tonic-gate * o If addr is non-zero then every symbol entry is updated to indicate the
297c478bd9Sstevel@tonic-gate * new location to which the object will be mapped.
307c478bd9Sstevel@tonic-gate *
317c478bd9Sstevel@tonic-gate * o The address of the `_edata' and `_end' symbols, and their associated
327c478bd9Sstevel@tonic-gate * section, is updated to reflect any new heap addition.
337c478bd9Sstevel@tonic-gate */
347c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate #include <libelf.h>
377c478bd9Sstevel@tonic-gate #include <string.h>
387c478bd9Sstevel@tonic-gate #include "sgs.h"
397c478bd9Sstevel@tonic-gate #include "machdep.h"
407c478bd9Sstevel@tonic-gate #include "msg.h"
417c478bd9Sstevel@tonic-gate #include "_librtld.h"
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate void
update_sym(Cache * cache,Cache * _cache,Addr edata,Half endx,Addr addr)447c478bd9Sstevel@tonic-gate update_sym(Cache *cache, Cache *_cache, Addr edata, Half endx, Addr addr)
457c478bd9Sstevel@tonic-gate {
467c478bd9Sstevel@tonic-gate char *strs;
477c478bd9Sstevel@tonic-gate Sym *syms;
487c478bd9Sstevel@tonic-gate Shdr *shdr;
497c478bd9Sstevel@tonic-gate Xword symn, cnt;
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate * Set up to read the symbol table and its associated string table.
537c478bd9Sstevel@tonic-gate */
547c478bd9Sstevel@tonic-gate shdr = _cache->c_shdr;
557c478bd9Sstevel@tonic-gate syms = (Sym *)_cache->c_data->d_buf;
567c478bd9Sstevel@tonic-gate symn = shdr->sh_size / shdr->sh_entsize;
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate strs = (char *)cache[shdr->sh_link].c_data->d_buf;
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate * Loop through the symbol table looking for `_end' and `_edata'.
627c478bd9Sstevel@tonic-gate */
637c478bd9Sstevel@tonic-gate for (cnt = 0; cnt < symn; cnt++, syms++) {
647c478bd9Sstevel@tonic-gate char *name = strs + syms->st_name;
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate if (addr) {
677c478bd9Sstevel@tonic-gate if (syms->st_value)
687c478bd9Sstevel@tonic-gate syms->st_value += addr;
697c478bd9Sstevel@tonic-gate }
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate if ((name[0] != '_') || (name[1] != 'e'))
727c478bd9Sstevel@tonic-gate continue;
737c478bd9Sstevel@tonic-gate if (strcmp(name, MSG_ORIG(MSG_SYM_END)) &&
747c478bd9Sstevel@tonic-gate strcmp(name, MSG_ORIG(MSG_SYM_EDATA)))
757c478bd9Sstevel@tonic-gate continue;
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate syms->st_value = edata + addr;
787c478bd9Sstevel@tonic-gate if (endx)
797c478bd9Sstevel@tonic-gate syms->st_shndx = endx;
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate }
82*2926dd2eSrie
83*2926dd2eSrie int
syminfo(Cache * _cache,Alist ** nodirect)84*2926dd2eSrie syminfo(Cache *_cache, Alist **nodirect)
85*2926dd2eSrie {
86*2926dd2eSrie Syminfo *info;
87*2926dd2eSrie Shdr *shdr;
88*2926dd2eSrie Word num, ndx;
89*2926dd2eSrie
90*2926dd2eSrie shdr = _cache->c_shdr;
91*2926dd2eSrie info = (Syminfo *)_cache->c_data->d_buf;
92*2926dd2eSrie num = (Word)(shdr->sh_size / shdr->sh_entsize);
93*2926dd2eSrie
94*2926dd2eSrie /*
95*2926dd2eSrie * Traverse the syminfo section recording the index of all nodirect
96*2926dd2eSrie * symbols.
97*2926dd2eSrie */
98*2926dd2eSrie for (ndx = 1, info++; ndx < num; ndx++, info++) {
99*2926dd2eSrie if ((info->si_flags & SYMINFO_FLG_NOEXTDIRECT) == 0)
100*2926dd2eSrie continue;
101*2926dd2eSrie
102*2926dd2eSrie if (alist_append(nodirect, &ndx, sizeof (Word), 20) == 0)
103*2926dd2eSrie return (1);
104*2926dd2eSrie }
105*2926dd2eSrie return (0);
106*2926dd2eSrie }
107