From 39f31e5c1db03fdd506e40ee02b76539ad5493c1 Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 3 Dec 2016 02:37:16 -0500 Subject: link mode: properly determine whether -L and -ldeplib are needed. --- src/logic/slbt_exec_link.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c index 553780f..3aa9d2f 100644 --- a/src/logic/slbt_exec_link.c +++ b/src/logic/slbt_exec_link.c @@ -524,6 +524,7 @@ static int slbt_exec_link_create_dep_file( char depfile[PATH_MAX]; struct stat st; int ldepth; + int fdyndep; (void)dctx; @@ -579,8 +580,23 @@ static int slbt_exec_link_create_dep_file( reladir[1] = 0; } + + /* dynamic library dependency? */ + strcpy(depfile,*parg); + mark = depfile + (base - *parg); + size = sizeof(depfile) - (base - *parg); + + if ((size_t)snprintf(mark,size,".libs/%s",base) + >= size) + return SLBT_BUFFER_ERROR(dctx); + + mark = strrchr(mark,'.'); + strcpy(mark,dctx->cctx->settings.dsoprefix); + + fdyndep = !stat(depfile,&st); + /* [-L... as needed] */ - if (!farchive && (base > *parg) && (ectx->ldirdepth >= 0)) { + if (fdyndep && (base > *parg) && (ectx->ldirdepth >= 0)) { if (fputs("-L",ectx->fdeps) < 0) { fclose(fdeps); return SLBT_SYSTEM_ERROR(dctx); @@ -599,7 +615,7 @@ static int slbt_exec_link_create_dep_file( } /* -ldeplib */ - if (!farchive) { + if (fdyndep) { *popt = 0; mark = base; mark += strlen(dctx->cctx->settings.dsoprefix); -- cgit v1.2.3