Skip to content

Commit

Permalink
Process linker directives beginning with a colon
Browse files Browse the repository at this point in the history
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
  • Loading branch information
el-remph committed Feb 16, 2025
1 parent 1747b45 commit 6ec4a10
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions libtcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1212,26 +1212,37 @@ ST_FUNC int tcc_add_crt(TCCState *s1, const char *filename)
/* the library name is the same as the argument of the '-l' option */
LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
{
static const char * const libs[] = {
#if defined TCC_TARGET_PE
static const char * const libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL };
const char * const *pp = s->static_link ? libs + 4 : libs;
"%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll",
#elif defined TCC_TARGET_MACHO
static const char * const libs[] = { "%s/lib%s.dylib", "%s/lib%s.tbd", "%s/lib%s.a", NULL };
const char * const *pp = s->static_link ? libs + 2 : libs;
"%s/lib%s.dylib", "%s/lib%s.tbd",
#elif defined TARGETOS_OpenBSD
static const char * const libs[] = { "%s/lib%s.so.*", "%s/lib%s.a", NULL };
const char * const *pp = s->static_link ? libs + 1 : libs;
"%s/lib%s.so.*",
#else
static const char * const libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL };
const char * const *pp = s->static_link ? libs + 1 : libs;
"%s/lib%s.so",
#endif
int flags = s->filetype & AFF_WHOLE_ARCHIVE;
while (*pp) {
int ret = tcc_add_library_internal(s, *pp,
libraryname, flags, s->library_paths, s->nb_library_paths);
if (ret != FILE_NOT_FOUND)
return ret;
++pp;
"%s/lib%s.a",
NULL
};

const char * const *pp = s->static_link
? libs + sizeof(libs) / sizeof(*libs) - 2
: libs;

/* if libraryname begins with a colon, it means search lib paths for
exactly the following file, without lib prefix or anything */
if (*libraryname == ':')
libraryname++;
else {
int flags = s->filetype & AFF_WHOLE_ARCHIVE;
while (*pp) {
int ret = tcc_add_library_internal(s, *pp,
libraryname, flags, s->library_paths, s->nb_library_paths);
if (ret != FILE_NOT_FOUND)
return ret;
++pp;
}
}
return tcc_add_dll(s, libraryname, AFF_PRINT_ERROR);
}
Expand Down

0 comments on commit 6ec4a10

Please sign in to comment.