a.out.c revision 56deab0745753336570f5c63c3b5fa565eaab8f1
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Object file dependent support for a.out format objects.
*/
#include <a.out.h> /* Explicitly override M_SEGSIZE */
#include <machdep.h> /* used in M_SROUND */
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <limits.h>
#include <stdio.h>
#include <dlfcn.h>
#include <errno.h>
#include <debug.h>
#include "_a.out.h"
#include "cache_a.out.h"
#include "msg.h"
#include "_rtld.h"
/*
* Default and secure dependency search paths.
*/
static Spath_defn _aout_def_dirs[] = {
{ 0, 0 }
};
static Spath_defn _aout_sec_dirs[] = {
{ 0, 0 }
};
/*
* Defines for local functions.
*/
int *l);
static Addr aout_entry_point(void);
static Alist **aout_get_def_dirs(void);
static Alist **aout_get_sec_dirs(void);
/*
* Functions and data accessed through indirect pointers.
*/
};
/*
* Default and secure dependency search paths.
*/
static Alist **
{
if (aout_def_dirs == NULL)
return (&aout_def_dirs);
}
static Alist **
{
if (aout_sec_dirs == NULL)
return (&aout_sec_dirs);
}
/*
* In 4.x, a needed file or a dlopened file that was a simple file name implied
* that the file be found in the present working directory. To simulate this
* lookup within the ELF rules it is necessary to add a preceding `./' to the
* filename.
*/
/* ARGSUSED4 */
static int
{
const char *nname;
/*
* Check for slash in name, if none, prepend "./", otherwise just
* return name given.
*/
return (0);
} else {
return (0);
}
return (0);
return (1);
}
/*
* Determine if we have been given an A_OUT file. Returns 1 if true.
*/
Fct *
/* ARGSUSED1 */
{
/* LINTED */
return (NULL);
}
return (&aout_fct);
}
/*
* Return the entry point of the A_OUT executable. Although the entry point
* within an ELF file is flexible, the entry point of an A_OUT executable is
* always zero.
*/
static Addr
{
return (0);
}
/*
* Search through the dynamic section for DT_NEEDED entries and perform one
* of two functions. If only the first argument is specified then load the
* defined shared object, otherwise add the link map representing the
* defined link map the the dlopen list.
*/
static int
{
void *need;
char *name;
/*
* If lo_library field is not NULL then this needed
* library was linked in using the "-l" option.
* Thus we need to rebuild the library name before
* trying to load it.
*/
char *file;
/*
* Allocate name length plus 20 for full library name.
* lib.so.. = 7 + (2 * short) + NULL = 7 + 12 + 1 = 20
*/
return (0);
/*
* We need to determine what filename will match the
* the filename specified (ie, a libc.so.1.2 may match
* to a libc.so.1.3). It's the real pathname that is
* recorded in the link maps. If we are presently
* being traced, skip this pathname generation so
* that we fall through into load_so() to print the
* appropriate diagnostics. I don't like this at all.
*/
else {
continue;
file, 0, 0))
break;
}
return (0);
}
}
AL_CNT_NEEDED, 0, 0) == 0)
return (0);
} else {
/*
* If the library is specified as a pathname, see if
* it must be fixed to specify the current working
*/
AL_CNT_NEEDED, 0) == 0)
return (0);
}
in_nfavl);
return (0);
}
return (1);
}
static Sym *
{
break;
case N_COMM:
break;
break;
default:
break;
}
return (&sym);
}
/*
* Process a.out format commons.
*/
static struct nlist *
{
const char *sl;
char *cp;
/*
* See if common is already allocated.
*/
while (trs) {
if (*sl++ == '\0')
}
/*
* If we got here, common is not already allocated so allocate it.
*/
return (NULL);
return (NULL);
return (NULL);
return (NULL);
}
/*
* Find a.out format symbol in the specified link map. Unlike the sister
* elf routine we re-calculate the symbols hash value for each link map
* we're looking at.
*/
static struct nlist *
{
char *cp;
struct fshash *p;
int i;
#define HASHMASK 0x7fffffff
#define RTHS 126
/*
* The name passed to us is in ELF format, thus it is necessary to
* map this back to the A_OUT format to compute the hash value (see
* mapping rules in aout_lookup_sym()). Basically the symbols are
* mapped according to whether a leading `.' exists.
*
* elf symbol a.out symbol
* i. .bar -> .bar (LKUP_LDOT)
* ii. .nuts -> nuts
* iii. foo -> _foo
*/
if (*name == '.') {
name++;
} else
hval = '_';
while (*name)
if (p->fssymbno != -1) {
do {
if (*name == '.') {
name++;
} else {
cp++;
}
if (*name++ == '\0')
return (sp); /* found */
}
if (p->next == 0)
return (NULL); /* not found */
else
continue;
}
return (NULL);
}
/*
* The symbol name we have been asked to look up is in A_OUT format, this
* symbol is mapped to the appropriate ELF format which is the standard by
* which symbols are passed around ld.so.1. The symbols are mapped
* according to whether a leading `_' or `.' exists.
*
* a.out symbol elf symbol
* i. _foo -> foo
* ii. .bar -> .bar (LKUP_LDOT)
* iii. nuts -> .nuts
*/
Sym *
{
else {
name[0] = '.';
}
/*
* Call the generic lookup routine to cycle through the specified
* link maps.
*/
}
/*
* Symbol lookup for an a.out format module.
*/
/* ARGSUSED3 */
static Sym *
{
/*
* is it a common?
*/
return (NULL);
}
*binfo |= DBG_BINFO_FOUND;
return (aout_symconvert(sp));
}
}
return (NULL);
}
/*
* Create a new Rt_map structure for an a.out format object and
* initializes all values.
*/
/* ARGSUSED6 */
Rt_map *
{
/*
* Allocate space for the link-map and private a.out information. Once
* these are allocated and initialized, we can use remove_so(0, lmp) to
* tear down the link-map should any failures occur.
*/
return (NULL);
/*
* All fields not filled in were set to 0 by calloc.
*/
/*
* Specific settings for a.out format.
*/
} else
/*
* Fill in all AOUT information. Applications provide the Link_dynamic
* offset via the boot block, but if this is a shared object that
* ld.so.1 has mapped, then determine the Link_dynamic offset from the
* mapped image.
*/
/* LINTED */
/* LINTED */
/* LINTED */
}
/* LINTED */
/* LINTED */
/* LINTED */
/* LINTED */
/*
* Add the mapped object to the end of the link map list.
*/
return (lmp);
}
/*
* Build full pathname of shared object from the given directory name and
* filename.
*/
static char *
/* ARGSUSED2 */
{
}
return (path);
}
/*
* Determine the symbol location of an address within a link-map. Look for
* the nearest symbol (whoes value is less than or equal to the required
* address). This is the object specific part of dladdr().
*/
static void
int flags)
{
sizeof (struct nlist);
base = 0;
else
continue;
continue;
continue;
break;
}
if (_sym) {
/*
* The only way we can create a symbol entry is to use
* aout_symconvert(), however this results in us pointing to
* static data that could be overridden. In addition the AOUT
* symbol format doesn't give us everything an ELF symbol does.
* So, unless we get convinced otherwise, don't bother returning
* a symbol entry for AOUT's.
*/
if (_flags == RTLD_DL_SYMENT)
*info = 0;
else if (_flags == RTLD_DL_LINKMAP)
}
}
/*
* Continue processing a dlsym request. Lookup the required symbol in each
* link-map specified by the handle. Note, that because this lookup is against
* individual link-maps we don't need to supply a starting link-map to the
* lookup routine (see lookup_sym():analyze.c).
*/
static Sym *
int *in_nfavl)
{
buffer[0] = '_';
return (sym);
/*
* Symbol not found as supplied. However, most of our symbols will
* be in the "C" name space, where the implementation prepends a "_"
* to the symbol as it emits it. Therefore, attempt to find the
* symbol with the "_" prepend.
*/
}
/*
* The initial mapping of the a.out occurs through exec(2), and presently this
* implementation doesn't provide a mmapobj_result_t array to ld.so.1. Thus,
* aout_get_mmap() is called to create the mapping information. Unlike ELF,
* the information that can be gathered from a mapped AOUT file, can be limited.
* In some cases the AOUT header isn't available in the mapped image, and thus
* this can't be inspected to determine the files size (the kernel always
* returns a pointer to the AOUT dynamic structure, but this is only sufficient
* to determine the size of the text segment).
*
* Therefore, the only generic mechanism of determining the AOUT's mapping is
* to use /proc. Only two mappings are required, the text (to determine any
* read-only region), and the data. The two mapping validate the range in
* which any relocations will occur. Should there be an additional bss segment,
* we don't care, as this can't be relocated, and we're never going to try
* unmapping the a.out.
*/
int
{
char proc[16];
return (1);
}
return (1);
}
return (1);
return (1);
}
maps--;
return (0);
}