Skip to content

Commit 3992788

Browse files
authored
[mono] Remove .la fallback code in mono_dl_open_full (#107907)
We don't use libtool files anymore. Contributes to #107883
1 parent fc66a78 commit 3992788

File tree

1 file changed

+5
-160
lines changed

1 file changed

+5
-160
lines changed

src/mono/mono/utils/mono-dl.c

Lines changed: 5 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -41,118 +41,6 @@ struct MonoDlFallbackHandler {
4141

4242
static GSList *fallback_handlers;
4343

44-
#if defined (_AIX)
45-
#include <ar.h>
46-
#include <fcntl.h>
47-
48-
/**
49-
* On AIX/PASE, a shared library can be contained inside of an ar format
50-
* archive. Determine if the file is an ar archive or not.
51-
*/
52-
static gboolean
53-
is_library_ar_archive (char *path)
54-
{
55-
int lfd, readret;
56-
char magic [SAIAMAG];
57-
lfd = open (path, O_RDONLY);
58-
59-
/* don't assume it's an archive on error */
60-
if (lfd == -1)
61-
return FALSE;
62-
63-
readret = read (lfd, magic, SAIAMAG);
64-
close (lfd);
65-
/* check for equality with either version of header */
66-
return readret == SAIAMAG &&
67-
(memcmp (magic, AIAMAG, SAIAMAG) == 0 ||
68-
memcmp (magic, AIAMAGBIG, SAIAMAG) == 0);
69-
}
70-
#endif
71-
72-
/*
73-
* read a value string from line with any of the following formats:
74-
* \s*=\s*'string'
75-
* \s*=\s*"string"
76-
* \s*=\s*non_white_space_string
77-
*/
78-
static char*
79-
read_string (char *p, FILE *file)
80-
{
81-
char *endp;
82-
char *startp;
83-
while (*p && isspace (*p))
84-
++p;
85-
if (*p == 0)
86-
return NULL;
87-
if (*p == '=')
88-
p++;
89-
while (*p && isspace (*p))
90-
++p;
91-
if (*p == '\'' || *p == '"') {
92-
char t = *p;
93-
p++;
94-
startp = p;
95-
endp = strchr (p, t);
96-
/* FIXME: may need to read more from file... */
97-
if (!endp)
98-
return NULL;
99-
*endp = 0;
100-
return (char *) g_memdup (startp, GPTRDIFF_TO_UINT ((endp - startp) + 1));
101-
}
102-
if (*p == 0)
103-
return NULL;
104-
startp = p;
105-
while (*p && !isspace (*p))
106-
++p;
107-
*p = 0;
108-
return (char *) g_memdup (startp, GPTRDIFF_TO_UINT ((p - startp) + 1));
109-
}
110-
111-
/*
112-
* parse a libtool .la file and return the path of the file to dlopen ()
113-
* handling both the installed and uninstalled cases
114-
*/
115-
static char*
116-
get_dl_name_from_libtool (const char *libtool_file)
117-
{
118-
FILE* file;
119-
char buf [512];
120-
char *line, *dlname = NULL, *libdir = NULL, *installed = NULL;
121-
if (!(file = fopen (libtool_file, "r")))
122-
return NULL;
123-
while ((line = fgets (buf, 512, file))) {
124-
while (*line && isspace (*line))
125-
++line;
126-
if (*line == '#' || *line == 0)
127-
continue;
128-
if (strncmp ("dlname", line, 6) == 0) {
129-
g_free (dlname);
130-
dlname = read_string (line + 6, file);
131-
} else if (strncmp ("libdir", line, 6) == 0) {
132-
g_free (libdir);
133-
libdir = read_string (line + 6, file);
134-
} else if (strncmp ("installed", line, 9) == 0) {
135-
g_free (installed);
136-
installed = read_string (line + 9, file);
137-
}
138-
}
139-
fclose (file);
140-
line = NULL;
141-
if (installed && strcmp (installed, "no") == 0) {
142-
char *dir = g_path_get_dirname (libtool_file);
143-
if (dlname)
144-
line = g_strconcat (dir, G_DIR_SEPARATOR_S ".libs" G_DIR_SEPARATOR_S, dlname, (const char*)NULL);
145-
g_free (dir);
146-
} else {
147-
if (libdir && dlname)
148-
line = g_strconcat (libdir, G_DIR_SEPARATOR_S, dlname, (const char*)NULL);
149-
}
150-
g_free (dlname);
151-
g_free (libdir);
152-
g_free (installed);
153-
return line;
154-
}
155-
15644
static const char *
15745
fix_libc_name (const char *name)
15846
{
@@ -278,61 +166,18 @@ mono_dl_open_full (const char *name, int mono_flags, int native_flags, MonoError
278166
}
279167
}
280168
if (!lib && !dl_fallback) {
281-
char *lname;
282-
char *llname;
283-
const char *suff;
284-
const char *ext;
285169
/* This platform does not support dlopen */
286170
if (name == NULL) {
287171
g_free (module);
288172
mono_error_set_not_supported (error, NULL);
289173
return NULL;
290174
}
291175

292-
suff = ".la";
293-
ext = strrchr (name, '.');
294-
if (ext && strcmp (ext, ".la") == 0)
295-
suff = "";
296-
lname = g_strconcat (name, suff, (const char*)NULL);
297-
llname = get_dl_name_from_libtool (lname);
298-
g_free (lname);
299-
if (llname) {
300-
error_init_reuse (load_error);
301-
lib = mono_dl_open_file (llname, lflags, load_error);
302-
mono_error_cleanup (load_error);
303-
304-
if (lib)
305-
found_name = g_strdup (llname);
306-
#if defined (_AIX)
307-
/*
308-
* HACK: deal with AIX archive members because libtool
309-
* underspecifies when using --with-aix-soname=svr4 -
310-
* without this check, Mono can't find System.Native
311-
* at build time.
312-
* XXX: Does this also need to be in other places?
313-
*/
314-
if (!lib && is_library_ar_archive (llname)) {
315-
/* try common suffix */
316-
char *llaixname;
317-
llaixname = g_strconcat (llname, "(shr_64.o)", (const char*)NULL);
318-
error_init_reuse (load_error);
319-
lib = mono_dl_open_file (llaixname, lflags, load_error);
320-
mono_error_cleanup (load_error);
321-
if (lib)
322-
found_name = g_strdup (llaixname);
323-
/* XXX: try another suffix like (shr.o)? */
324-
g_free (llaixname);
325-
}
326-
#endif
327-
g_free (llname);
328-
}
329-
if (!lib) {
330-
char *error_msg = mono_dl_current_error_string ();
331-
mono_error_set_error (error, MONO_ERROR_FILE_NOT_FOUND, "%s", error_msg);
332-
g_free (error_msg);
333-
g_free (module);
334-
return NULL;
335-
}
176+
char *error_msg = mono_dl_current_error_string ();
177+
mono_error_set_error (error, MONO_ERROR_FILE_NOT_FOUND, "%s", error_msg);
178+
g_free (error_msg);
179+
g_free (module);
180+
return NULL;
336181
}
337182
mono_refcount_init (module, NULL);
338183
module->handle = lib;

0 commit comments

Comments
 (0)