summaryrefslogtreecommitdiffhomepage
path: root/src/logic/slbt_exec_link.c
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-10-21 21:02:33 -0400
committermidipix <writeonce@midipix.org>2018-10-21 21:49:54 -0400
commit2480bde89a3c451902613e8ece89a9f233560512 (patch)
tree1bcea3af7e51362fb114de8e47b08fa8ce77bfb5 /src/logic/slbt_exec_link.c
parentdc48ad4836a2aaaa7c5058b008937a102945ed85 (diff)
downloadslibtool-2480bde89a3c451902613e8ece89a9f233560512.tar.bz2
slibtool-2480bde89a3c451902613e8ece89a9f233560512.tar.xz
slbt_exec_link_finalize_argument_vector(): remove redundant -l arguments.
Diffstat (limited to 'src/logic/slbt_exec_link.c')
-rw-r--r--src/logic/slbt_exec_link.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c
index f3c292f..c4a5023 100644
--- a/src/logic/slbt_exec_link.c
+++ b/src/logic/slbt_exec_link.c
@@ -577,6 +577,10 @@ static int slbt_exec_link_finalize_argument_vector(
char ** parg;
char ** aarg;
char ** oarg;
+ char ** larg;
+ char ** darg;
+ char ** earg;
+ char ** rarg;
char ** aargv;
char ** oargv;
char ** cap;
@@ -614,7 +618,8 @@ static int slbt_exec_link_finalize_argument_vector(
/* (program name) */
parg = &base[1];
- /* split object args from all other args, record output annotation */
+ /* split object args from all other args, record output */
+ /* annotation, and remove redundant -l arguments */
for (; *parg; ) {
if (ectx->lout[0] == parg) {
ectx->lout[0] = &aarg[0];
@@ -649,7 +654,45 @@ static int slbt_exec_link_finalize_argument_vector(
*oarg++ = *parg++;
} else {
- *aarg++ = *parg++;
+ /* not a -l argument? */
+ if ((parg[0][0] != '-') || (parg[0][1] != 'l')) {
+ *aarg++ = *parg++;
+
+ } else {
+ /* find the previus occurence of this -l argument */
+ for (rarg=0, larg=&aarg[-1]; !rarg && (larg>=aargv); larg--)
+ if (!strcmp(*larg,*parg))
+ rarg = larg;
+
+ /* first occurence of this specific -l argument? */
+ if (!rarg) {
+ *aarg++ = *parg++;
+
+ } else {
+ larg = rarg;
+
+ /* if all -l arguments following the previous */
+ /* occurence had already appeared before the */
+ /* previous argument, then the current */
+ /* occurence is redundant. */
+
+ for (darg=&larg[1]; rarg && darg<aarg; darg++) {
+ /* only test -l arguments */
+ if ((darg[0][0] == '-') && (darg[0][1] == 'l')) {
+ for (rarg=0, earg=aargv; !rarg && earg<larg; earg++)
+ if (!strcmp(*earg,*darg))
+ rarg = darg;
+ }
+ }
+
+ /* final verdict: repeated -l argument? */
+ if (rarg)
+ parg++;
+
+ else
+ *aarg++ = *parg++;
+ }
+ }
}
}
@@ -670,6 +713,9 @@ static int slbt_exec_link_finalize_argument_vector(
for (; src<cap; )
*dst++ = *src++;
+ /* properly null-terminate argv, accounting for redundant -l arguments */
+ *dst = 0;
+
/* output annotation */
if (ectx->lout[0]) {
ectx->lout[0] = &base[1] + (oarg - oargv) + (ectx->lout[0] - aargv);