usr/src/cmd/sgs/rtld/sparc/sparc_a.out.c
author Rod Evans <Rod.Evans@Sun.COM>
Wed, 19 May 2010 22:33:49 -0700
changeset 12449 a87750d92895
parent 11827 d7ef53deac3f
permissions -rw-r--r--
6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW PSARC/2010/175 Deferred symbol references 6943432 dlsym(RTLD_PROBE) should only bind to symbol definitions 6668759 an external method for determining whether an ELF dependency is optional
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     1
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     2
 * CDDL HEADER START
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     3
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
     5
 * Common Development and Distribution License (the "License").
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
     6
 * You may not use this file except in compliance with the License.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     7
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    11
 * and limitations under the License.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    12
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    18
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    19
 * CDDL HEADER END
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    20
 */
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
    21
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    22
/*
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
    23
 *	Copyright (c) 1988 AT&T
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
    24
 *	All Rights Reserved
12449
a87750d92895 6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents: 11827
diff changeset
    25
 *
a87750d92895 6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents: 11827
diff changeset
    26
 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    27
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    28
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    29
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    30
 * SPARC machine dependent and a.out format file class dependent functions.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    31
 * Contains routines for performing function binding and symbol relocations.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    32
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    33
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    34
#include	<stdio.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    35
#include	<sys/types.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    36
#include	<sys/mman.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    37
#include	<synch.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    38
#include	<dlfcn.h>
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
    39
#include	<debug.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    40
#include	"_a.out.h"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    41
#include	"_rtld.h"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    42
#include	"_audit.h"
12449
a87750d92895 6943772 Testing for a symbols existence with RTLD_PROBE is compromised by RTLD_BIND_NOW
Rod Evans <Rod.Evans@Sun.COM>
parents: 11827
diff changeset
    43
#include	"_inline_gen.h"
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    44
#include	"msg.h"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    45
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    46
extern void	iflush_range(caddr_t, size_t);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    47
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    48
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    49
 * Function binding routine - invoked on the first call to a function through
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    50
 * the procedure linkage table;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    51
 * passes first through an assembly language interface.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    52
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    53
 * Takes the address of the PLT entry where the call originated,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    54
 * the offset into the relocation table of the associated
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    55
 * relocation entry and the address of the link map (rt_private_map struct)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    56
 * for the entry.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    57
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    58
 * Returns the address of the function referenced after re-writing the PLT
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    59
 * entry to invoke the function directly.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    60
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    61
 * On error, causes process to terminate with a signal.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    62
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    63
ulong_t
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    64
aout_bndr(caddr_t pc)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    65
{
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
    66
	Rt_map		*lmp, *nlmp, *llmp;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    67
	struct relocation_info *rp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    68
	struct nlist	*sp;
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
    69
	Sym		*sym;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    70
	char		*name;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    71
	int 		rndx, entry;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    72
	ulong_t		symval;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    73
	Slookup		sl;
11827
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
    74
	Sresult		sr;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    75
	uint_t		binfo;
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
    76
	Lm_list		*lml;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    77
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    78
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    79
	 * For compatibility with libthread (TI_VERSION 1) we track the entry
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    80
	 * value.  A zero value indicates we have recursed into ld.so.1 to
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    81
	 * further process a locking request (see comments in completion()).
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    82
	 * Under this recursion we disable tsort and cleanup activities.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    83
	 */
6515
10dab2b883e0 6678310 using LD_AUDIT, ld.so.1 calls shared library's .init before library is fully relocated
raf
parents: 6387
diff changeset
    84
	entry = enter(0);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    85
8394
cfddc4c3786c 6782597 32-bit ld.so.1 needs to accept objects with large inode number
Ali Bahrami <Ali.Bahrami@Sun.COM>
parents: 6812
diff changeset
    86
	for (lmp = lml_main.lm_head; lmp; lmp = NEXT_RT_MAP(lmp)) {
8598
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
    87
		if (THIS_IS_AOUT(lmp)) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    88
			if (pc > (caddr_t)(LM2LP(lmp)->lp_plt) &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    89
			    pc < (caddr_t)((int)LM2LP(lmp)->lp_plt +
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    90
			    AOUTDYN(lmp)->v2->ld_plt_sz))  {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    91
				break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    92
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    93
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    94
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    95
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    96
#define	LAST22BITS	0x3fffff
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    97
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    98
	/* LINTED */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    99
	rndx = *(int *)(pc + (sizeof (ulong_t *) * 2)) & LAST22BITS;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   100
	rp = &LM2LP(lmp)->lp_rp[rndx];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   101
	sp = &LM2LP(lmp)->lp_symtab[rp->r_symbolnum];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   102
	name = &LM2LP(lmp)->lp_symstr[sp->n_un.n_strx];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   103
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   104
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   105
	 * Determine the last link-map of this list, this'll be the starting
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   106
	 * point for any tsort() processing.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   107
	 */
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   108
	lml = LIST(lmp);
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   109
	llmp = lml->lm_tail;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   110
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   111
	/*
5950
a449a24f9be0 6654381 lazy loading fall-back needs optimizing
rie
parents: 5892
diff changeset
   112
	 * Find definition for symbol.  Initialize the symbol lookup data
a449a24f9be0 6654381 lazy loading fall-back needs optimizing
rie
parents: 5892
diff changeset
   113
	 * structure.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   114
	 */
5950
a449a24f9be0 6654381 lazy loading fall-back needs optimizing
rie
parents: 5892
diff changeset
   115
	SLOOKUP_INIT(sl, name, lmp, lml->lm_head, ld_entry_cnt, 0, 0, 0, 0,
a449a24f9be0 6654381 lazy loading fall-back needs optimizing
rie
parents: 5892
diff changeset
   116
	    LKUP_DEFT);
11827
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   117
	SRESULT_INIT(sr, name);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   118
11827
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   119
	if (aout_lookup_sym(&sl, &sr, &binfo, NULL) == 0) {
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   120
		eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_NOSYM), NAME(lmp),
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   121
		    demangle(name));
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   122
		rtldexit(lml, 1);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   123
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   124
11827
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   125
	name = (char *)sr.sr_name;
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   126
	nlmp = sr.sr_dmap;
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   127
	sym = sr.sr_sym;
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   128
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   129
	symval = sym->st_value;
11827
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   130
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   131
	if (!(FLAGS(nlmp) & FLG_RT_FIXED) &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   132
	    (sym->st_shndx != SHN_ABS))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   133
		symval += (int)(ADDR(nlmp));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   134
	if ((lmp != nlmp) && ((FLAGS1(nlmp) & FL1_RT_NOINIFIN) == 0)) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   135
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   136
		 * Record that this new link map is now bound to the caller.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   137
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   138
		if (bind_one(lmp, nlmp, BND_REFER) == 0)
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   139
			rtldexit(lml, 1);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   140
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   141
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   142
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   143
	 * Print binding information and rebuild PLT entry.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   144
	 */
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   145
	DBG_CALL(Dbg_bind_global(lmp, (Addr)(ADDR(lmp) + rp->r_address),
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   146
	    (Off)rp->r_address, (Xword)(-1), PLT_T_NONE, nlmp,
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   147
	    (Addr)symval, sym->st_value, name, binfo));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   148
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   149
	if (!(rtld_flags & RT_FL_NOBIND))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   150
		aout_plt_write((caddr_t)(ADDR(lmp) + rp->r_address), symval);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   151
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   152
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   153
	 * Complete any processing for newly loaded objects.  Note we don't
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   154
	 * know exactly where any new objects are loaded (we know the object
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   155
	 * that supplied the symbol, but others may have been loaded lazily as
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   156
	 * we searched for the symbol), so sorting starts from the last
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   157
	 * link-map know on entry to this routine.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   158
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   159
	if (entry)
4679
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   160
		load_completion(llmp);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   161
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   162
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   163
	 * Make sure the object to which we've bound has had it's .init fired.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   164
	 * Cleanup before return to user code.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   165
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   166
	if (entry) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   167
		is_dep_init(nlmp, lmp);
6515
10dab2b883e0 6678310 using LD_AUDIT, ld.so.1 calls shared library's .init before library is fully relocated
raf
parents: 6387
diff changeset
   168
		leave(lml, 0);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   169
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   170
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   171
	return (symval);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   172
}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   173
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   174
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   175
#define	IS_PC_RELATIVE(X) (pc_rel_type[(X)] == 1)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   176
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   177
static const uchar_t pc_rel_type[] = {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   178
	0,				/* RELOC_8 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   179
	0,				/* RELOC_16 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   180
	0,				/* RELOC_32 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   181
	1,				/* RELOC_DISP8 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   182
	1,				/* RELOC_DISP16 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   183
	1,				/* RELOC_DISP32 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   184
	1,				/* RELOC_WDISP30 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   185
	1,				/* RELOC_WDISP22 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   186
	0,				/* RELOC_HI22 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   187
	0,				/* RELOC_22 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   188
	0,				/* RELOC_13 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   189
	0,				/* RELOC_LO10 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   190
	0,				/* RELOC_SFA_BASE */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   191
	0,				/* RELOC_SFA_OFF13 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   192
	0,				/* RELOC_BASE10 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   193
	0,				/* RELOC_BASE13 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   194
	0,				/* RELOC_BASE22 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   195
	0,				/* RELOC_PC10 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   196
	0,				/* RELOC_PC22 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   197
	0,				/* RELOC_JMP_TBL */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   198
	0,				/* RELOC_SEGOFF16 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   199
	0,				/* RELOC_GLOB_DAT */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   200
	0,				/* RELOC_JMP_SLOT */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   201
	0				/* RELOC_RELATIVE */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   202
};
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   203
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   204
int
8598
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
   205
aout_reloc(Rt_map *lmp, uint_t plt, int *in_nfavl, APlist **textrel)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   206
{
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   207
	int		k;		/* loop temporary */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   208
	int		nr;		/* number of relocations */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   209
	char		*name;		/* symbol being searched for */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   210
	long		value;		/* relocation temporary */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   211
	long		*ra;		/* cached relocation address */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   212
	struct relocation_info *rp;	/* current relocation */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   213
	struct nlist	*sp;		/* symbol table of "symbol" */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   214
	Rt_map *	_lmp;		/* lm which holds symbol definition */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   215
	Sym *		sym;		/* symbol definition */
8598
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
   216
	int		ret = 1;
5892
b863dde33f1b 6492726 Merge SHF_MERGE|SHF_STRINGS input sections
ab196087
parents: 5220
diff changeset
   217
	APlist		*bound = NULL;
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   218
	Lm_list		*lml = LIST(lmp);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   219
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   220
	DBG_CALL(Dbg_reloc_run(lmp, SHT_RELA, plt, DBG_REL_START));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   221
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   222
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   223
	 * If we've been called upon to promote an RTLD_LAZY object to an
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   224
	 * RTLD_NOW don't bother to do anything - a.out's are bound as if
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   225
	 * RTLD_NOW regardless.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   226
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   227
	if (plt)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   228
		return (1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   229
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   230
	rp = LM2LP(lmp)->lp_rp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   231
	nr = GETRELSZ(AOUTDYN(lmp)) / sizeof (struct relocation_info);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   232
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   233
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   234
	 * Initialize _PLT_, if any.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   235
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   236
	if (AOUTDYN(lmp)->v2->ld_plt_sz)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   237
		aout_plt_write((caddr_t)LM2LP(lmp)->lp_plt->jb_inst,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   238
		    (ulong_t)aout_rtbndr);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   239
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   240
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   241
	 * Loop through relocations.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   242
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   243
	for (k = 0; k < nr; k++, rp++) {
8598
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
   244
		mmapobj_result_t	*mpp;
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
   245
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   246
		/* LINTED */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   247
		ra = (long *)&((char *)ADDR(lmp))[rp->r_address];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   248
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   249
		/*
8598
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
   250
		 * Make sure the segment is writable.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   251
		 */
8598
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
   252
		if (((mpp = find_segment((caddr_t)ra, lmp)) != NULL) &&
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
   253
		    ((mpp->mr_prot & PROT_WRITE) == 0)) {
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
   254
			if ((set_prot(lmp, mpp, 1) == 0) ||
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
   255
			    (aplist_append(textrel, mpp,
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
   256
			    AL_CNT_TEXTREL) == NULL)) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   257
				ret = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   258
				break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   259
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   260
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   261
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   262
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   263
		 * Perform the relocation.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   264
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   265
		if (rp->r_extern == 0) {
11827
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   266
			name = NULL;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   267
			value = ADDR(lmp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   268
		} else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   269
			Slookup		sl;
11827
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   270
			Sresult		sr;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   271
			uint_t		binfo;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   272
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   273
			if (rp->r_type == RELOC_JMP_SLOT)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   274
				continue;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   275
			sp = &LM2LP(lmp)->lp_symtab[rp->r_symbolnum];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   276
			name = &LM2LP(lmp)->lp_symstr[sp->n_un.n_strx];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   277
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   278
			/*
5950
a449a24f9be0 6654381 lazy loading fall-back needs optimizing
rie
parents: 5892
diff changeset
   279
			 * Locate symbol.  Initialize the symbol lookup data
a449a24f9be0 6654381 lazy loading fall-back needs optimizing
rie
parents: 5892
diff changeset
   280
			 * structure.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   281
			 */
8598
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
   282
			SLOOKUP_INIT(sl, name, lmp, 0, ld_entry_cnt,
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
   283
			    0, 0, 0, 0, LKUP_STDRELOC);
11827
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   284
			SRESULT_INIT(sr, name);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   285
11827
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   286
			if (aout_lookup_sym(&sl, &sr, &binfo, in_nfavl) == 0) {
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   287
				if (lml->lm_flags & LML_FLG_TRC_WARN) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   288
					(void)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   289
					    printf(MSG_INTL(MSG_LDD_SYM_NFOUND),
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   290
					    demangle(name), NAME(lmp));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   291
					continue;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   292
				} else {
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   293
					eprintf(lml, ERR_FATAL,
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   294
					    MSG_INTL(MSG_REL_NOSYM), NAME(lmp),
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   295
					    demangle(name));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   296
					ret = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   297
					break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   298
				}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   299
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   300
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   301
			/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   302
			 * If symbol was found in an object other than the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   303
			 * referencing object then record the binding.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   304
			 */
11827
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   305
			name = (char *)sr.sr_name;
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   306
			_lmp = sr.sr_dmap;
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   307
			sym = sr.sr_sym;
d7ef53deac3f 6918143 symbol capabilities
Rod Evans <Rod.Evans@Sun.COM>
parents: 8598
diff changeset
   308
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   309
			if ((lmp != _lmp) &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   310
			    ((FLAGS1(_lmp) & FL1_RT_NOINIFIN) == 0)) {
5892
b863dde33f1b 6492726 Merge SHF_MERGE|SHF_STRINGS input sections
ab196087
parents: 5220
diff changeset
   311
				if (aplist_test(&bound, _lmp,
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   312
				    AL_CNT_RELBIND) == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   313
					ret = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   314
					break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   315
				}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   316
			}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   317
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   318
			value = sym->st_value + rp->r_addend;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   319
			if (!(FLAGS(_lmp) & FLG_RT_FIXED) &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   320
			    (sym->st_shndx != SHN_COMMON) &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   321
			    (sym->st_shndx != SHN_ABS))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   322
				value += ADDR(_lmp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   323
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   324
			if (IS_PC_RELATIVE(rp->r_type))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   325
				value -= (long)ADDR(lmp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   326
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   327
			DBG_CALL(Dbg_bind_global(lmp, (Addr)ra,
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   328
			    (Off)(ra - ADDR(lmp)), (Xword)(-1), PLT_T_NONE,
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   329
			    _lmp, (Addr)value, sym->st_value, name, binfo));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   330
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   331
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   332
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   333
		 * Perform a specific relocation operation.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   334
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   335
		switch (rp->r_type) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   336
		case RELOC_RELATIVE:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   337
			value += *ra << (32-22);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   338
			*(long *)ra = (*(long *)ra & ~S_MASK(22)) |
4679
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   339
			    ((value >> (32 - 22)) & S_MASK(22));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   340
			ra++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   341
			value += (*ra & S_MASK(10));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   342
			*(long *)ra = (*(long *)ra & ~S_MASK(10)) |
4679
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   343
			    (value & S_MASK(10));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   344
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   345
		case RELOC_8:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   346
		case RELOC_DISP8:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   347
			value += *ra & S_MASK(8);
4679
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   348
			if (!S_INRANGE(value, 8)) {
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   349
				eprintf(lml, ERR_FATAL,
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   350
				    MSG_INTL(MSG_REL_OVERFLOW), NAME(lmp),
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   351
				    (name ? demangle(name) :
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   352
				    MSG_INTL(MSG_STR_UNKNOWN)), (int)value, 8,
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   353
				    (uint_t)ra);
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   354
			}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   355
			*ra = value;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   356
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   357
		case RELOC_LO10:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   358
		case RELOC_BASE10:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   359
			value += *ra & S_MASK(10);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   360
			*(long *)ra = (*(long *)ra & ~S_MASK(10)) |
4679
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   361
			    (value & S_MASK(10));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   362
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   363
		case RELOC_BASE13:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   364
		case RELOC_13:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   365
			value += *ra & S_MASK(13);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   366
			*(long *)ra = (*(long *)ra & ~S_MASK(13)) |
4679
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   367
			    (value & S_MASK(13));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   368
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   369
		case RELOC_16:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   370
		case RELOC_DISP16:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   371
			value += *ra & S_MASK(16);
4679
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   372
			if (!S_INRANGE(value, 16)) {
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   373
				eprintf(lml, ERR_FATAL,
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   374
				    MSG_INTL(MSG_REL_OVERFLOW), NAME(lmp),
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   375
				    (name ? demangle(name) :
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   376
				    MSG_INTL(MSG_STR_UNKNOWN)), (int)value, 16,
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   377
				    (uint_t)ra);
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   378
			}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   379
			*(short *)ra = value;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   380
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   381
		case RELOC_22:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   382
		case RELOC_BASE22:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   383
			value += *ra & S_MASK(22);
4679
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   384
			if (!S_INRANGE(value, 22)) {
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   385
				eprintf(lml, ERR_FATAL,
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   386
				    MSG_INTL(MSG_REL_OVERFLOW), NAME(lmp),
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   387
				    (name ? demangle(name) :
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   388
				    MSG_INTL(MSG_STR_UNKNOWN)), (int)value, 22,
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   389
				    (uint_t)ra);
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   390
			}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   391
			*(long *)ra = (*(long *)ra & ~S_MASK(22)) |
4679
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   392
			    (value & S_MASK(22));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   393
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   394
		case RELOC_HI22:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   395
			value += (*ra & S_MASK(22)) << (32 - 22);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   396
			*(long *)ra = (*(long *)ra & ~S_MASK(22)) |
4679
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   397
			    ((value >> (32 - 22)) & S_MASK(22));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   398
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   399
		case RELOC_WDISP22:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   400
			value += *ra & S_MASK(22);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   401
			value >>= 2;
4679
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   402
			if (!S_INRANGE(value, 22)) {
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   403
				eprintf(lml, ERR_FATAL,
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   404
				    MSG_INTL(MSG_REL_OVERFLOW), NAME(lmp),
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   405
				    (name ? demangle(name) :
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   406
				    MSG_INTL(MSG_STR_UNKNOWN)), (int)value, 22,
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   407
				    (uint_t)ra);
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   408
			}
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   409
			*(long *)ra = (*(long *)ra & ~S_MASK(22)) |
4679
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   410
			    (value & S_MASK(22));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   411
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   412
		case RELOC_WDISP30:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   413
			value += *ra & S_MASK(30);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   414
			value >>= 2;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   415
			*(long *)ra = (*(long *)ra & ~S_MASK(30)) |
4679
3d9b5e6569cc PSARC/2007/413 Add -zglobalaudit option to ld
rie
parents: 1618
diff changeset
   416
			    (value & S_MASK(30));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   417
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   418
		case RELOC_32:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   419
		case RELOC_GLOB_DAT:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   420
		case RELOC_DISP32:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   421
			value += *ra;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   422
			*(long *)ra = value;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   423
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   424
		default:
1618
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   425
			eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_UNIMPL),
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   426
			    NAME(lmp), (name ? demangle(name) :
8c9a4f31d225 6316708 LD_DEBUG should provide a means of identifying/isolating individual
rie
parents: 0
diff changeset
   427
			    MSG_INTL(MSG_STR_UNKNOWN)), rp->r_type);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   428
			ret = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   429
			break;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   430
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   431
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   432
		/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   433
		 * If this relocation is against a text segment we must make
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   434
		 * sure that the instruction cache is flushed.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   435
		 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   436
		if (textrel) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   437
			if (rp->r_type == RELOC_RELATIVE)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   438
				iflush_range((caddr_t)(ra - 1), 0x8);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   439
			else
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   440
				iflush_range((caddr_t)ra, 0x4);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   441
		}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   442
	}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   443
8598
0867fc633d66 6686372 ld.so.1 should use mmapobj(2)
Rod Evans <Rod.Evans@Sun.COM>
parents: 8394
diff changeset
   444
	return (relocate_finish(lmp, bound, ret));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   445
}