From 4af256bee433fadfacf2cb1e22dbe35c9e0a8fbf Mon Sep 17 00:00:00 2001
From: midipix <writeonce@midipix.org>
Date: Sun, 3 Mar 2024 05:35:33 +0000
Subject: slbt_exec_link_create_library(): allow ar(1) driven invocations.

---
 src/internal/slibtool_linkcmd_impl.h    | 4 +++-
 src/logic/linkcmd/slbt_linkcmd_dsolib.c | 8 +++++++-
 src/logic/slbt_exec_ctx.c               | 9 +++++++++
 src/logic/slbt_exec_link.c              | 6 ++++--
 4 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/internal/slibtool_linkcmd_impl.h b/src/internal/slibtool_linkcmd_impl.h
index 85d1e13..8451810 100644
--- a/src/internal/slibtool_linkcmd_impl.h
+++ b/src/internal/slibtool_linkcmd_impl.h
@@ -74,7 +74,9 @@ int slbt_exec_link_create_library(
 	struct slbt_exec_ctx *		ectx,
 	const char *			dsobasename,
 	const char *			dsofilename,
-	const char *			relfilename);
+	const char *			relfilename,
+	bool				fardlopen);
+
 
 int slbt_exec_link_create_executable(
 	const struct slbt_driver_ctx *	dctx,
diff --git a/src/logic/linkcmd/slbt_linkcmd_dsolib.c b/src/logic/linkcmd/slbt_linkcmd_dsolib.c
index 4d611a0..dd5bf64 100644
--- a/src/logic/linkcmd/slbt_linkcmd_dsolib.c
+++ b/src/logic/linkcmd/slbt_linkcmd_dsolib.c
@@ -60,7 +60,8 @@ slbt_hidden int slbt_exec_link_create_library(
 	struct slbt_exec_ctx *		ectx,
 	const char *			dsobasename,
 	const char *			dsofilename,
-	const char *			relfilename)
+	const char *			relfilename,
+	bool                            fardlopen)
 {
 	int                     fdcwd;
 	char **                 parg;
@@ -273,6 +274,7 @@ slbt_hidden int slbt_exec_link_create_library(
 			return SLBT_BUFFER_ERROR(dctx);
 	}
 
+	/* output marks */
 	*ectx->lout[0] = "-o";
 	*ectx->lout[1] = output;
 
@@ -307,6 +309,10 @@ slbt_hidden int slbt_exec_link_create_library(
 	if (slbt_exec_link_finalize_argument_vector(dctx,ectx))
 		return SLBT_NESTED_ERROR(dctx);
 
+	/* all done? */
+	if (fardlopen)
+		return 0;
+
 	/* step output */
 	if (!(dctx->cctx->drvflags & SLBT_DRIVER_SILENT))
 		if (slbt_output_link(ectx))
diff --git a/src/logic/slbt_exec_ctx.c b/src/logic/slbt_exec_ctx.c
index 583001d..7c5bd87 100644
--- a/src/logic/slbt_exec_ctx.c
+++ b/src/logic/slbt_exec_ctx.c
@@ -705,6 +705,15 @@ void slbt_ectx_reset_argvector(struct slbt_exec_ctx * ectx)
 
 slbt_hidden void slbt_reset_placeholders(struct slbt_exec_ctx * ectx)
 {
+	struct slbt_exec_ctx_impl * ictx;
+
+	ictx = slbt_get_exec_ictx(ectx);
+
+	if (ictx->lout[0]) {
+		ectx->lout[0] = ictx->lout[0];
+		ectx->lout[1] = ictx->lout[1];
+	}
+
 	*ectx->dpic = "-USLIBTOOL_PLACEHOLDER_DPIC";
 	*ectx->fpic = "-USLIBTOOL_PLACEHOLDER_FPIC";
 	*ectx->cass = "-USLIBTOOL_PLACEHOLDER_COMPILE_ASSEMBLE";
diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c
index 428c13a..423a20e 100644
--- a/src/logic/slbt_exec_link.c
+++ b/src/logic/slbt_exec_link.c
@@ -298,7 +298,8 @@ int slbt_exec_link(const struct slbt_driver_ctx * dctx)
 						dctx,ectx,
 						ectx->dsobasename,
 						ectx->dsofilename,
-						ectx->relfilename)) {
+						ectx->relfilename,
+						false)) {
 					slbt_ectx_free_exec_ctx(ectx);
 					return SLBT_NESTED_ERROR(dctx);
 				}
@@ -364,7 +365,8 @@ int slbt_exec_link(const struct slbt_driver_ctx * dctx)
 				dctx,ectx,
 				ectx->dsobasename,
 				ectx->dsofilename,
-				ectx->relfilename)) {
+				ectx->relfilename,
+				false)) {
 			slbt_ectx_free_exec_ctx(ectx);
 			return SLBT_NESTED_ERROR(dctx);
 		}
-- 
cgit v1.2.3