1 /* Storage management for the chain of loaded shared objects.
2 Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
24 #include <elf/ldsodefs.h>
29 /* Allocate a `struct link_map' for a new object being loaded,
30 and enter it into the _dl_loaded list. */
34 _dl_new_object (char *realname
, const char *libname
, int type
,
35 struct link_map
*loader
)
39 size_t libname_len
= strlen (libname
) + 1;
40 struct link_map
*new = calloc (sizeof *new, 1);
41 struct libname_list
*newname
= malloc (sizeof *newname
+ libname_len
);
42 if (! new || ! newname
)
45 new->l_name
= realname
;
46 newname
->name
= memcpy (newname
+ 1, libname
, libname_len
);
48 new->l_libname
= newname
;
50 new->l_loader
= loader
;
51 /* new->l_global = 0; We use calloc therefore not necessary. */
53 /* Counter for the scopes we have to handle. */
56 if (_dl_loaded
!= NULL
)
62 /* new->l_next = NULL; Would be necesary but we use calloc. */
65 /* Add the global scope. */
66 new->l_scope
[idx
++] = &_dl_loaded
->l_searchlist
;
70 /* This is our local scope. */
73 while (loader
->l_loader
!= NULL
)
74 loader
= loader
->l_loader
;
75 new->l_scope
[idx
] = &loader
->l_searchlist
;
78 new->l_scope
[idx
] = &new->l_searchlist
;
80 new->l_local_scope
[0] = &new->l_searchlist
;
82 /* Don't try to find the origin for the main map which has the name "". */
83 if (realname
[0] != '\0')
87 if (realname
[0] == '/')
89 /* It an absolute path. Use it. But we have to make a copy since
90 we strip out the trailing slash. */
91 size_t len
= strlen (realname
) + 1;
92 origin
= malloc (len
);
96 memcpy (origin
, realname
, len
);
100 size_t realname_len
= strlen (realname
) + 1;
101 size_t len
= 128 + realname_len
;
104 /* Get the current directory name. */
105 origin
= malloc (len
);
107 while (origin
!= NULL
108 && (result
= __getcwd (origin
, len
- realname_len
)) == NULL
112 origin
= (char *) realloc (origin
, len
);
117 /* We were not able to determine the current directory. */
120 origin
= (char *) -1;
124 /* Now append the filename. */
125 char *cp
= strchr (origin
, '\0');
130 memcpy (cp
, realname
, realname_len
);
134 if (origin
!= (char *) -1)
136 /* Now remove the filename and the slash. Do this even if the
137 string is something like "/foo" which leaves an empty string. */
138 char *last
= strrchr (origin
, '/');
146 new->l_origin
= origin
;