2 * Copyright (c) 1995 by Sun Microsystems, Inc.
5 * This source code is a product of Sun Microsystems, Inc. and is provided
6 * for unrestricted use provided that this legend is included on all tape
7 * media and as a part of the software program in whole or part. Users
8 * may copy or modify this source code without charge, but are not authorized
9 * to license or distribute it to anyone else except as part of a product or
10 * program developed by the user.
12 * THIS PROGRAM CONTAINS SOURCE CODE COPYRIGHTED BY SUN MICROSYSTEMS, INC.
13 * SUN MICROSYSTEMS, INC., MAKES NO REPRESENTATIONS ABOUT THE SUITABLITY
14 * OF SUCH SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
15 * EXPRESS OR IMPLIED WARRANTY OF ANY KIND. SUN MICROSYSTEMS, INC. DISCLAIMS
16 * ALL WARRANTIES WITH REGARD TO SUCH SOURCE CODE, INCLUDING ALL IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN
18 * NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT,
19 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
20 * FROM USE OF SUCH SOURCE CODE, REGARDLESS OF THE THEORY OF LIABILITY.
22 * This source code is provided with no support and without any obligation on
23 * the part of Sun Microsystems, Inc. to assist in its use, correction,
24 * modification or enhancement.
26 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
27 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS
28 * SOURCE CODE OR ANY PART THEREOF.
30 * Sun Microsystems, Inc.
32 * Mountain View, California 94043
35 #pragma ident "@(#) $Id: _relocate.c,v 1.4 1995/06/26 20:12:41 georgn Exp $ - SMI"
42 #include "_dynodump.h"
45 update_reloc(Cache *ocache, Cache *_ocache,
46 Cache *icache, Cache *_icache,
52 Cache *orcache, *ircache;
55 * Set up to readh the output relocation table.
57 shdr = _ocache->c_shdr;
58 rels = (Rel *) _ocache->c_data->d_buf;
59 reln = shdr->sh_size / shdr->sh_entsize;
62 * Determine the section that is being relocated.
64 orcache = &ocache[shdr->sh_info];
65 shdr = _icache->c_shdr;
66 ircache = &icache[shdr->sh_info];
69 * Determine the section that is being relocated. Note that for this
70 * stupid architecture the .rel.plt actually contains offsets into the
73 if (strcmp(_ocache->c_name, ".rel.plt")) {
74 orcache = &ocache[shdr->sh_info];
75 shdr = _icache->c_shdr;
76 ircache = &icache[shdr->sh_info];
79 Cache * __ocache = ocache;
81 for (__ocache++, ndx = 1; ndx != shnum; ndx++, __ocache++) {
82 if (strcmp(__ocache->c_name, ".got") == 0) {
84 ircache = &icache[ndx];
91 * Loop through the relocation table.
93 for (cnt = 0; cnt < reln; cnt++, rels++) {
94 unsigned char *iaddr, *oaddr;
96 unsigned char type = ELF_R_TYPE(rels->r_info);
99 * Ignore some relocations as these can be safely carried out
100 * twice (they simply override any existing data). In fact,
101 * some relocations like __iob's copy relocation must be carried
102 * out each time the process restarts, otherwise stdio blows up.
104 if ((type == R_386_COPY) || (type == R_386_NONE))
108 * If we are required to restore the relocation location
109 * to its value prior to relocation, then read the
110 * location's original contents from the input image and
111 * copy it to the output image.
113 off = rels->r_offset - ircache->c_shdr->sh_addr;
114 iaddr = (unsigned char *) ircache->c_data->d_buf + off;
115 oaddr = (unsigned char *) orcache->c_data->d_buf + off;
116 *(unsigned long *) oaddr = *(unsigned long *) iaddr;