elfrd.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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 (c) 1996-1997, by Sun Microsystems, Inc.
* All Rights Reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <locale.h>
#include <stdio.h>
#include <fcntl.h>
#include <link.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <search.h>
#include "libelf.h"
#include "elfrd.h"
extern int verbose;
extern char *mstrdup(const char *);
/*
* Given the name of an executable and a function call the function for
* all shared objects needed to link the executable. The function will only
* be called once. A list of filenames for which the function has been called
* is maintained, this is used to exclude filenames.
*/
void
{
#ifdef DEBUG
#endif /* debug */
#ifdef DEBUG
#endif /* debug */
if (verbose) {
if ((int)sop < 0) {
"cachefspack: unable to get shared objects - %s\n"),
pathname);
}
}
if ((int)sop > 0) {
#ifdef DEBUG
printf("process_executable: sop->so_name = %s\n",
#endif /* DEBUG */
}
}
}
/*
* Given the name of an executable, a list of directories to use in the
* library search and a list of library names to exclude, return all
* shared object needed by the executable.
*
* RETURNS: A pointer to a list of shared objects
*/
struct sobj *
{
static int name_cnt = 0;
static int depth = 0;
int found_file = 0;
int error;
int fd;
char *name;
void * get_scndata();
struct sobj *alloc_sobj();
char pathtmp[MAXPATHLEN];
int fileopn;
int elfbgn = 0;
int buf;
/*
* Open a file and perform necessary operations to find the sections
* in an elf format file. If the specified file is not elf format
* return an error.
*/
depth++;
if (depth == 1) {
/*
* Find the ending exclude shared object element.
*/
#ifdef DEBUG
#endif /* DEBUG */
}
fileopn = 0;
error = ERR_NOERROR;
if (fd < 0) {
error = ERR_NOFILE;
goto out;
}
fileopn = 1;
/* work around */
/*
* elf_begin() core dumps when passed a file descriptor for a file
* which does not have read permission, but was opened RDONLY because the
* user doing the open was root. To avoid this problem, make sure we can
* read the first byte of the file. If we can't, skip the file. This is a
* temporary workaround until elf_begin() is fixed.
*/
#ifdef DEBUG
printf("read failed\n");
#endif /* DEBUG */
error = ERR_NOFILE;
goto out;
}
/* work around end */
goto out;
}
elfbgn = 0;
goto out;
}
elfbgn = 1;
#ifdef DEBUG
#endif /* DEBUG */
goto out;
}
goto out;
}
#ifdef DEBUG
#endif /* DEBUG */
/*
* Scan all sections of the elf file to locate the dynamic section
*/
scn = 0;
goto out;
}
continue;
}
/*
* The first pass of the dynamic section locates all
* directories specified by "ld -R..". A stack is created
* for the search, this allows shared libraries, dependant
* on other shared libraries, built with "ld -R" to work
* properly.
*
*/
goto out;
}
#ifdef DEBUG
#endif /* DEBUG */
}
dyn++;
}
/*
* Find all needed shared objects. Do this recursively
* so libraries dependant on other libraries are found.
* Also, try a list of libraries to exclude. Since
* this routine is used by cachefspack, it is only neccessary
* to pack a library once. For example, libc is used by lots
* of commands, we need not return its name to cachefspack
* except the first time we find it.
*/
goto out;
}
if (name != 0) {
#ifdef DEBUG
#endif /* DEBUG */
pathtmp);
#ifdef DEBUG
printf("dbg: 1 found_file = %d\n",
#endif /* DEBUG */
if (!found_file) {
}
#ifdef DEBUG
printf("dbg: 2 found_file = %d\n",
#endif /* DEBUG */
if (!found_file) {
continue;
}
if (name_cnt == 0) {
so = alloc_sobj();
}
/*
* See if file already in list
*/
#ifdef DEBUG
printf("found so: %s\n",
pathtmp);
printf("hitemp.key = %s\n",
#endif /* DEBUG */
continue;
}
#ifdef DEBUG
#endif /* DEBUG */
name_cnt++;
if (flag & GSO_ADDEXCLD) {
#ifdef DEBUG
printf("adding so: %s\n",
pathtmp);
#endif /* DEBUG */
NULL) {
goto out;
}
}
} else {
if (name_cnt > 0) {
goto out;
} else {
goto out;
}
}
}
}
}
out:
#ifdef DEBUG
#endif /* DEBUG */
depth--;
#ifdef DEBUG
#endif /* DEBUG */
if (fileopn) {
if (elfbgn) {
}
}
}
if (name_cnt == 0) {
return ((struct sobj *)ERR_NOERROR);
}
#ifdef DEBUG
#endif /* DEBUG */
}
if (depth == 0) {
name_cnt = 0;
}
if (error == ERR_NOERROR) {
return (hd_so);
} else {
}
}
/*
* Get the section descriptor and set the size of the
* data returned. Data is byte-order converted.
*/
void *
{
p_data = 0;
{
return (NULL);
}
}
/*
* Allocate a shared object structure
*
* RETURNS: A pointer to the allocated structure
*/
struct sobj *
{
return (so);
}
/*
* Add an object to a shared object list
*
* RETURNS: The tail of the shared object list
*/
struct sobj *
{
so = alloc_sobj();
}
return (so);
}
/*
* Determine if name concatenated with a library directory path yields
* a file name that exists.
*
* RETURNS: True(1) or False(0)
* if true - fullpath arg contains a pointer to the full path name
* of the file
*/
int
{
#ifdef DEBUG
#endif /* DEBUG */
return (0);
}
#ifdef DEBUG
#endif /* DEBUG */
#ifdef DEBUG
#endif /* DEBUG */
/*
* stat - if file break
*/
== 0) {
#ifdef DEBUG
#endif /* DEBUG */
return (1);
}
}
#ifdef DEBUG
#endif /* DEBUG */
return (0);
}
/*
* Add path to the libpath list(add at the tail of the list).
*
* RETURNS: The new tail of the list
*/
struct libpath *
{
char *s;
if (s != (char *)0) {
}
return (lp);
}
/*
* Add directory/directories in name to libpath stack(as head of the stack)
* at the level specified.
*
* RETURNS: the new head of the stack
*/
struct libpath *
{
char *s, *t;
char *tok;
char *freeit;
#ifdef DEBUG
#endif /* DEBUG */
freeit = s;
while (1) {
break;
s = (char *)0;
}
#ifdef DEBUG
#endif /* DEBUG */
return (lp);
}
/*
* Free up a libpath stack entry.
*
* RETURNS: the new head of the stack
*/
struct libpath *
{
return (lp);
}
/*
* Crack the LD_LIBRARY_PATH environment variable. Make a list of libraries
* to search.
*/
void
{
char *s;
char *tok = (char *) 1;
s = getenv("LD_LIBRARY_PATH");
if (s != (char *)NULL) {
while (1) {
break;
s = (char *) 0;
}
}
}
#ifdef DEBUG
{
if ((int)sop < 0) {
exit(1);
}
if ((int)sop > 0) {
}
}
}
#endif /* DEBUG */