/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Binary compatibility ld.so. Intercepts the reference of a pre-SVR4
* SunOS executable to the dynamic linker, and then redirects to the
* "real" post-SVR4 SunOS ld.so.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Import data structures (N.B.: from 5.x).
*/
#include <sys/sysconfig.h>
#include <sys/archsystm.h>
#include <elf.h>
#include <link.h>
/*
* Relocation manifest constants and macros.
*/
~((int)(a) - 1))
void aout_reloc_write();
/*
* 4.x SunOS Dynamic Link Editor public definitions (much derived from
* SunOS 4.x <link.h>.)
*/
/*
* Dynamic linking information. With the exception of
* ld_loaded (determined at execution time) and ld_stab_hash (a special
* case of relocation handled at execution time), the values in this
* structure reflect offsets from the containing link_dynamic structure.
*/
struct link_dynamic_1 {
};
struct link_dynamic_2 {
};
/*
* Debugger interface structure.
*/
struct ld_debug {
};
/*
* Structure associated with each object which may be or which requires
* execution-time link editing. Used by the run-time linkage editor to
* identify needed objects and symbol definitions and references.
*/
struct link_dynamic {
int ld_version;
union {
} ld_un;
};
struct old_link_dynamic {
union {
} ld_un;
int in_debugging;
int sym_loaded;
char *bp_addr;
int bp_inst;
/* allocated common symbols. */
};
/*
* SunOS 4.x SPARC relocation types and relocation record. Note that
* these, among other things, make this program not portable to things
* other than SPARC.
*/
enum reloc_type {
/* Disp's (pc-rel) */
/* PIC GOT references */
/* ld.so relocation types */
};
struct relocation_info {
int : 2; /* <unused> */
};
/*
* Size of relocations.
*/
#define GETRELSZ(x) \
(x->ld_version < 2 ? \
/*
* Interface between crt0 & ld.so.
*/
struct crt_i1 {
};
/*
* Structure we provide to ELF ld.so upon entry.
*/
/*
* Global data.
*/
/*
* 4.0 ld.so main entry point.
*/
int version; /* interface version */
{
int i, p; /* working */
int r; /* working (# of *our* relocations */
/*
* ld.so must itself be relocated, take care of this now.
* We can not refer to global data before this step is
* complete. Perform the relocation by stepping over all
* entries in the relocation table and turn them into
* absolute addresses. Note that, in order to avoid invoking
* as yet unrelocated items, we perform the relocation count
* by counting rather than risk invoking subroutine calls
* to intrinsic .div or .mul routines. Note also that we
* assume that there are no symbolic relocations to be
* performed here.
*/
r = 0;
while (i != 0) {
i -= RELOC_SIZE;
r++;
}
/*
* Determine the location of the routine that will write the relocation.
* This hasn't yet been relocated so determine the real address using
* our base address.
*/
/*
* Relocate ourselves - we only need RELOC_RELATIVE and RELOC_32.
* Note, if panic() was called its probable that it will barf as the
* corresponding plt wouldn't have been relocated yet.
*/
for (i = 0; i < r; i++) {
long value;
case RELOC_RELATIVE:
where++;
break;
case RELOC_32:
break;
default:
break;
}
rp++;
}
/*
* We're relocated, we can now initialize things referencing
* static storage.
*/
/*
* Close off the file descriptor used to get us here -- let it
* be available for the next (probable) use below.
*/
/*
* Discover things about our environment: auxiliary vector (if
* any), arguments, program name, and the like.
*/
program_name = (char *)(argp + sizeof (int));
if (version != 1)
panic("bad startup interface version of %d",
version);
;
addr += sizeof (char *);
/*
* The kernel sends us an abbreviated aux vector with some
* potentially handy stuff that saves us on syscalls.
*
* Notes on 1226113
*
* The f77 compiler shipped as part of SC1.0 on 4.x creates binaries
* that use the _fix_libc_ feature of acc. This makes the resulting
* executable object dependent on the undocumented behaviour of
* libc's .rem and .div routines e.g. that .div returns the
* remainder in %o3 (and similarly .rem returns the division in %o3).
*
* The only simple solution is to disable hardware divide for
* all 4.x applications so that the old software routines that have
* this "support" in them are used instead. And we do that by
* clearing the divide-in-hardware flag from the aux vector before
* libc's .init routine gets to see it. Awful isn't it.
*/
/*
* If we didn't get a page size from looking in the auxiliary
* vector, we need to get one now.
*/
if (page_size == 0) {
}
/*
* Map in the ELF-based ld.so. Note that we're mapping it as
* an ELF database, not as a program -- we just want to walk it's
* data structures. Further mappings will actually establish the
* program in the address space.
*/
MAP_SHARED, fd, 0);
/*
* Validate the file we're looking at, ensure it has the correct
* ELF structures, such as: ELF magic numbers, coded for SPARC,
* is a ".so", etc.
*/
panic("%s is not a valid SPARC object: e_machine: %x",
/*
* Point at program headers and start figuring out what to load.
*/
if (fph == 0) {
"%s invalid program header - segments out of order", ldso);
}
/*
* We'd better have at least one loadable segment.
*/
if (fph == 0)
/*
* Map enough address space to hold the program (as opposed to the
* file) represented by ld.so. The amount to be assigned is the
* range between the end of the last loadable segment and the
* beginning of the first PLUS the alignment of the first segment.
* mmap() can assign us any page-aligned address, but the relocations
* assume the alignments included in the program header. As an
* optimization, however, let's assume that mmap() will actually
* give us an aligned address -- since if it does, we can save
* an munmap() later on. If it doesn't -- then go try it again.
*/
MAP_SHARED, fd, 0);
/*
* Check to see whether alignment skew was really needed.
*/
MAP_SHARED, fd, 0);
}
/*
* We have the address space reserved, so map each loadable segment.
*/
/*
* Skip non-loadable segments or segments that don't occupy
* any memory.
*/
continue;
/*
* Determine the file offset to which the mapping will
* directed (must be aligned) and how much to map (might
* be more than the file in the case of .bss.)
*/
/*
* Set address of this segment relative to our base.
*/
/*
* Unmap anything form the last mapping address to this
* one.
*/
}
/*
* Determine the mapping protection from the section
* attributes.
*/
i = 0;
i |= PROT_READ;
i |= PROT_WRITE;
i |= PROT_EXEC;
/*
* If the memory occupancy of the segment overflows the
* definition in the file, we need to "zero out" the
* end of the mapping we've established, and if necessary,
*/
if (r > 0)
0) == (caddr_t)-1)
ldso);
}
/*
* Update the mapping claim pointer.
*/
}
/*
* Unmap any final reservation.
*/
if (mlen > 0)
/*
* Clean up file descriptor space we've consumed. Pass along
*/
/*
* The call itself. Note that we start 1 instruction word in.
* The ELF ld.so contains an "entry vector" of branch instructions,
* which, for our interest are:
* +0: ba, a <normal startup>
* +4: ba, a <compatibility startup>
* By starting at the compatibility startup, the ELF ld.so knows
* that a pointer to "eb" is available to it and further knows
* how to calculate the offset to the program's arguments and
* other structures.
*/
return (0);
}