ldlibs.c revision 5aefb6555731130ca4fd295960123d71f2d21fe8
/*
* 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 (c) 1988 AT&T
* All Rights Reserved
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Library processing
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <debug.h>
#include "msg.h"
#include "_libld.h"
/*
* List of support libraries specified (-S option).
*/
static Listnode * insert_lib;
/*
* Function to handle -YL and -YU substitutions in LIBPATH. It's probably
* very unlikely that the link-editor will ever see this, as any use of these
* options is normally processed by the compiler driver first and the finished
* -YP string is sent to us. The fact that these two options are not even
* documented anymore makes it even more unlikely this processing will occur.
*/
static char *
{
if (Llibdir) {
/*
* User supplied "-YL,libdir", this is the pathname that
* corresponds for compatibility to -YL (as defined in
*/
return (Llibdir);
}
if (Ulibdir) {
/*
* User supplied "-YU,libdir", this is the pathname that
* corresponds for compatibility to -YU (as defined in
*/
return (Ulibdir);
}
}
return (path);
}
static char *
{
int i;
char *cp;
for (i = YLDIR; i; i++) {
if (*path == '\0') {
if (seenflg)
return ((char *)S_ERROR);
} else
return ((char *)S_ERROR);
return (cp);
}
if (*cp == ':') {
*cp = '\0';
return ((char *)S_ERROR);
} else {
return ((char *)S_ERROR);
}
continue;
}
/* case ";" */
return ((char *)S_ERROR);
} else {
if (seenflg)
return ((char *)S_ERROR);
}
return (cp);
}
/* NOTREACHED */
return (NULL); /* keep gcc happy */
}
/*
* adds the indicated path to those to be searched for libraries.
*/
{
if (insert_lib == NULL) {
return (S_ERROR);
} else
insert_lib)) == 0)
return (S_ERROR);
/*
* As -l and -L options can be interspersed, print the library
* search paths each time a new path is added.
*/
&ofl->ofl_dlibdirs));
return (1);
}
/*
* Process a required library. Combine the directory and filename, and then
* append either a `.so' or `.a' suffix and try opening the associated pathname.
*/
static Ifl_desc *
{
int fd;
/*
* Determine the size of the directory. The directory and filename are
* concatenated into the local buffer which is purposely larger than
* PATH_MAX. Should a pathname be created that exceeds the system
* limit, the open() will catch it, and a suitable rejection message is
* saved.
*/
dlen = 1;
}
dlen++;
/*
* If we are in dynamic mode try and open the associated shared object.
*/
FLG_IF_NEEDED, rej);
return (ifl);
/*
* If the open() failed for anything other than the
* file not existing, record the error condition.
*/
}
}
/*
* If we are not in dynamic mode, or a shared object could not be
* located, try and open the associated archive.
*/
return (ifl);
/*
* If the open() failed for anything other than the
* file not existing, record the error condition.
*/
}
return (0);
}
/*
* Take the abbreviated name of a library file (from -lfoo) and searches for the
* library. The search path rules are:
*
* o use any user supplied paths, i.e. LD_LIBRARY_PATH and -L, then
*
* o use the default directories, i.e. LIBPATH or -YP.
*
* If we are in dynamic mode and -Bstatic is not in effect, first look for a
* otherwise process the file appropriately depending on its type.
*/
{
char *path;
/*
* Search for this file in any user defined directories.
*/
continue;
}
}
/*
* Finally try the default library search directories.
*/
continue;
}
}
/*
* If we've got this far we haven't found a shared object or archive.
* If an object was found, but was rejected for some reason, print a
* diagnostic to that effect, otherwise generate a generic "not found"
* diagnostic.
*/
conv_reject_desc(&rej));
else
name);
return (0);
}
/*
* Inspect the LD_LIBRARY_PATH variable (if the -i options has not been
* specified), and set up the directory list from which to search for
* libraries. From the man page:
*
* LD_LIBRARY_PATH=dirlist1;dirlist2
* and
* ld ... -Lpath1 ... -Lpathn ...
*
* results in a search order of:
*
* dirlist1 path1 ... pathn dirlist2 LIBPATH
*
* If LD_LIBRARY_PATH has no `;' specified, the pathname(s) supplied are
* all taken as dirlist2.
*/
{
/*
* Determine whether an LD_LIBRARY_PATH setting is in effect.
*/
#if defined(_ELF64)
#else
#endif
}
return (S_ERROR);
/*
* Process the first path string (anything up to a null or
* a `;');
*/
/*
* If a `;' was seen then initialize the insert flag to the
* tail of this list. This is where any -L paths will be
* added (otherwise -L paths are prepended to this list).
* Continue to process the remaining path string.
*/
if (path) {
*path = '\0';
++path;
FALSE);
return (S_ERROR);
else if (cp)
}
}
/*
* Add the default LIBPATH or any -YP supplied path.
*/
return (S_ERROR);
else if (cp) {
return (S_ERROR);
}
&ofl->ofl_dlibdirs));
return (1);
}