ldlibs.c revision 98c080d502548e68bb9815459ea56e6ae282c430
/*
* 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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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"
/*
* Define a list index for "-L" processing. By default, "-L" search paths are
* inserted at the beginning of the associated search list. However, should a
* ";" be discovered in a LD_LIBRARY_PATH listing, then any new "-L" search
* paths are inserted following the ";".
*/
/*
* 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)
AL_CNT_OFL_LIBDIRS) == NULL)
return ((char *)S_ERROR);
AL_CNT_OFL_LIBDIRS) == NULL) {
return ((char *)S_ERROR);
}
return (cp);
}
if (*cp == ':') {
*cp = '\0';
AL_CNT_OFL_LIBDIRS) == NULL)
return ((char *)S_ERROR);
AL_CNT_OFL_LIBDIRS) == NULL) {
return ((char *)S_ERROR);
}
continue;
}
/* case ";" */
AL_CNT_OFL_LIBDIRS) == NULL)
return ((char *)S_ERROR);
} else {
if (seenflg)
AL_CNT_OFL_LIBDIRS) == NULL)
return ((char *)S_ERROR);
}
return (cp);
}
/* NOTREACHED */
return (NULL); /* keep gcc happy */
}
/*
* adds the indicated path to those to be searched for libraries.
*/
{
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);
if (fd != -1)
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.
*/
FLG_IF_NEEDED, rej);
if (fd != -1)
return (ifl);
/*
* If the open() failed for anything other than the
* file not existing, record the error condition.
*/
}
return (NULL);
}
/*
* 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.
*/
} 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 `;');
*/
/*
* By default, -L paths are prepended to the library search
* path list, because Lidx == 0. If a ';' is seen within an
* LD_LIBRARY_PATH string, change the insert index so that -L
* paths are added following the ';'.
*/
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);
}