Skip to content

Commit 6ec4a10

Browse files
committed
Process linker directives beginning with a colon
eg. -l :crti.o, with the same meaning as for other linkers (search library paths for an exact match) Also clean up some copy/pasting
1 parent 1747b45 commit 6ec4a10

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

libtcc.c

+26-15
Original file line numberDiff line numberDiff line change
@@ -1212,26 +1212,37 @@ ST_FUNC int tcc_add_crt(TCCState *s1, const char *filename)
12121212
/* the library name is the same as the argument of the '-l' option */
12131213
LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
12141214
{
1215+
static const char * const libs[] = {
12151216
#if defined TCC_TARGET_PE
1216-
static const char * const libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL };
1217-
const char * const *pp = s->static_link ? libs + 4 : libs;
1217+
"%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll",
12181218
#elif defined TCC_TARGET_MACHO
1219-
static const char * const libs[] = { "%s/lib%s.dylib", "%s/lib%s.tbd", "%s/lib%s.a", NULL };
1220-
const char * const *pp = s->static_link ? libs + 2 : libs;
1219+
"%s/lib%s.dylib", "%s/lib%s.tbd",
12211220
#elif defined TARGETOS_OpenBSD
1222-
static const char * const libs[] = { "%s/lib%s.so.*", "%s/lib%s.a", NULL };
1223-
const char * const *pp = s->static_link ? libs + 1 : libs;
1221+
"%s/lib%s.so.*",
12241222
#else
1225-
static const char * const libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL };
1226-
const char * const *pp = s->static_link ? libs + 1 : libs;
1223+
"%s/lib%s.so",
12271224
#endif
1228-
int flags = s->filetype & AFF_WHOLE_ARCHIVE;
1229-
while (*pp) {
1230-
int ret = tcc_add_library_internal(s, *pp,
1231-
libraryname, flags, s->library_paths, s->nb_library_paths);
1232-
if (ret != FILE_NOT_FOUND)
1233-
return ret;
1234-
++pp;
1225+
"%s/lib%s.a",
1226+
NULL
1227+
};
1228+
1229+
const char * const *pp = s->static_link
1230+
? libs + sizeof(libs) / sizeof(*libs) - 2
1231+
: libs;
1232+
1233+
/* if libraryname begins with a colon, it means search lib paths for
1234+
exactly the following file, without lib prefix or anything */
1235+
if (*libraryname == ':')
1236+
libraryname++;
1237+
else {
1238+
int flags = s->filetype & AFF_WHOLE_ARCHIVE;
1239+
while (*pp) {
1240+
int ret = tcc_add_library_internal(s, *pp,
1241+
libraryname, flags, s->library_paths, s->nb_library_paths);
1242+
if (ret != FILE_NOT_FOUND)
1243+
return ret;
1244+
++pp;
1245+
}
12351246
}
12361247
return tcc_add_dll(s, libraryname, AFF_PRINT_ERROR);
12371248
}

0 commit comments

Comments
 (0)