a.out.c revision 2020b2b6df0384feda1732f65486c4604fbf5bea
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 2N/A * Object file dependent support for a.out format objects. 2N/A#
include <
a.out.h>
/* Explicitly override M_SEGSIZE */ 2N/A * Default and secure dependency search paths. 2N/A * Defines for local functions. 2N/A * Functions and data accessed through indirect pointers. * Default and secure dependency search paths. * 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 * Check for slash in name, if none, prepend "./", otherwise just * Determine if we have been given an A_OUT file. Returns 1 if true. * 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 * 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. * 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 * Allocate name length plus 20 for full library name. * lib.so.. = 7 + (2 * short) + NULL = 7 + 12 + 1 = 20 * 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. * If the library is specified as a pathname, see if * it must be fixed to specify the current working * Process a.out format commons. * See if common is already allocated. * If we got here, common is not already allocated so allocate it. * 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 * 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) return (
NULL);
/* not found */ * 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 * ii. .bar -> .bar (LKUP_LDOT) * Call the generic lookup routine to cycle through the specified * Symbol lookup for an a.out format module. * Create a new Rt_map structure for an a.out format object and * initializes all values. * 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. * All fields not filled in were set to 0 by calloc. * Specific settings for a.out format. * 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 * Add the mapped object to the end of the link map list. * Build full pathname of shared object from the given directory name and * 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(). * 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. * 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). * 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