OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [linux/] [dl/] [dl-object.c] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* Storage management for the chain of loaded shared objects.
2
   Copyright (C) 1995,96,97,98,99,2000,2001 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
4
 
5
   The GNU C Library is free software; you can redistribute it and/or
6
   modify it under the terms of the GNU Lesser General Public
7
   License as published by the Free Software Foundation; either
8
   version 2.1 of the License, or (at your option) any later version.
9
 
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
   Lesser General Public License for more details.
14
 
15
   You should have received a copy of the GNU Lesser General Public
16
   License along with the GNU C Library; if not, write to the Free
17
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18
   02111-1307 USA.  */
19
 
20
#include <errno.h>
21
#include <string.h>
22
#include <stdlib.h>
23
#include <unistd.h>
24
#include <ldsodefs.h>
25
 
26
#include <assert.h>
27
 
28
 
29
/* Allocate a `struct link_map' for a new object being loaded,
30
   and enter it into the _dl_loaded list.  */
31
 
32
struct link_map *
33
internal_function
34
_dl_new_object (char *realname, const char *libname, int type,
35
                struct link_map *loader)
36
{
37
  struct link_map *l;
38
  int idx;
39
  size_t libname_len = strlen (libname) + 1;
40
  struct link_map *new;
41
  struct libname_list *newname;
42
 
43
  new = (struct link_map *) calloc (sizeof (*new) + sizeof (*newname)
44
                                    + libname_len, 1);
45
  if (new == NULL)
46
    return NULL;
47
 
48
  new->l_libname = newname = (struct libname_list *) (new + 1);
49
  newname->name = (char *) memcpy (newname + 1, libname, libname_len);
50
  /* newname->next = NULL;      We use calloc therefore not necessary.  */
51
  newname->dont_free = 1;
52
 
53
  new->l_name = realname;
54
  new->l_type = type;
55
  new->l_loader = loader;
56
  /* new->l_global = 0; We use calloc therefore not necessary.  */
57
 
58
  /* Use the 'l_scope_mem' array by default for the the 'l_scope'
59
     information.  If we need more entries we will allocate a large
60
     array dynamically.  */
61
  new->l_scope = new->l_scope_mem;
62
  new->l_scope_max = sizeof (new->l_scope_mem) / sizeof (new->l_scope_mem[0]);
63
 
64
  /* Counter for the scopes we have to handle.  */
65
  idx = 0;
66
 
67
  if (_dl_loaded != NULL)
68
    {
69
      l = _dl_loaded;
70
      while (l->l_next != NULL)
71
        l = l->l_next;
72
      new->l_prev = l;
73
      /* new->l_next = NULL;    Would be necessary but we use calloc.  */
74
      l->l_next = new;
75
 
76
      /* Add the global scope.  */
77
      new->l_scope[idx++] = &_dl_loaded->l_searchlist;
78
    }
79
  else
80
    _dl_loaded = new;
81
  ++_dl_nloaded;
82
 
83
  /* If we have no loader the new object acts as it.  */
84
  if (loader == NULL)
85
    loader = new;
86
  else
87
    /* Determine the local scope.  */
88
    while (loader->l_loader != NULL)
89
      loader = loader->l_loader;
90
 
91
  /* Insert the scope if it isn't the global scope we already added.  */
92
  if (idx == 0 || &loader->l_searchlist != new->l_scope[0])
93
    new->l_scope[idx] = &loader->l_searchlist;
94
 
95
  new->l_local_scope[0] = &new->l_searchlist;
96
 
97
  /* Don't try to find the origin for the main map which has the name "".  */
98
  if (realname[0] != '\0')
99
    {
100
      size_t realname_len = strlen (realname) + 1;
101
      char *origin;
102
      char *cp;
103
 
104
      if (realname[0] == '/')
105
        {
106
          /* It is an absolute path.  Use it.  But we have to make a
107
             copy since we strip out the trailing slash.  */
108
          cp = origin = (char *) malloc (realname_len);
109
          if (origin == NULL)
110
            {
111
              origin = (char *) -1;
112
              goto out;
113
            }
114
        }
115
      else
116
        {
117
          size_t len = realname_len;
118
          char *result = NULL;
119
 
120
          /* Get the current directory name.  */
121
          origin = NULL;
122
          do
123
            {
124
              len += 128;
125
              origin = (char *) realloc (origin, len);
126
            }
127
          while (origin != NULL
128
                 && (result = getcwd (origin, len - realname_len)) == NULL
129
                 && errno == ERANGE);
130
 
131
          if (result == NULL)
132
            {
133
              /* We were not able to determine the current directory.
134
                 Note that free(origin) is OK if origin == NULL.  */
135
              free (origin);
136
              origin = (char *) -1;
137
              goto out;
138
            }
139
 
140
          /* Find the end of the path and see whether we have to add
141
             a slash.  */
142
          cp = memchr (origin, '\0', strlen(origin));
143
          if (cp[-1] != '/')
144
            *cp++ = '/';
145
        }
146
 
147
      /* Add the real file name.  */
148
      memcpy (cp, realname, realname_len);
149
 
150
      /* Now remove the filename and the slash.  Leave the slash if it
151
         the name is something like "/foo".  */
152
      cp = strrchr (origin, '/');
153
      if (cp == origin)
154
        origin[1] = '\0';
155
      else
156
        *cp = '\0';
157
 
158
    out:
159
      new->l_origin = origin;
160
    }
161
 
162
  return new;
163
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.