summaryrefslogtreecommitdiffhomepage
path: root/src/internal
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2023-05-28 10:14:58 +0000
committermidipix <writeonce@midipix.org>2023-05-28 10:24:28 +0000
commita126a7f68ef374d65d014226195380eb7dceb634 (patch)
tree577360dd60b07dfa9d14a9ab9be88cf5f58fcb26 /src/internal
parent667d348ca9d54b31857fd20c08b97c642ae9f815 (diff)
downloadslibtool-a126a7f68ef374d65d014226195380eb7dceb634.tar.bz2
slibtool-a126a7f68ef374d65d014226195380eb7dceb634.tar.xz
driver: added -objectlist support.
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/slibtool_driver_impl.h11
-rw-r--r--src/internal/slibtool_objlist_impl.c82
-rw-r--r--src/internal/slibtool_objlist_impl.h10
3 files changed, 103 insertions, 0 deletions
diff --git a/src/internal/slibtool_driver_impl.h b/src/internal/slibtool_driver_impl.h
index 0971fd9..0293308 100644
--- a/src/internal/slibtool_driver_impl.h
+++ b/src/internal/slibtool_driver_impl.h
@@ -9,6 +9,7 @@
#include <stdint.h>
#include <stdio.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <slibtool/slibtool.h>
@@ -54,6 +55,7 @@ enum app_tags {
TAG_RPATH,
TAG_SYSROOT,
TAG_RELEASE,
+ TAG_OBJECTLIST,
TAG_DLOPEN,
TAG_DLPREOPEN,
TAG_EXPORT_DYNAMIC,
@@ -99,12 +101,21 @@ struct slbt_host_strs {
char * mdso;
};
+struct slbt_obj_list {
+ const char * name;
+ void * addr;
+ size_t size;
+ int objc;
+ char ** objv;
+};
+
struct slbt_driver_ctx_impl {
struct slbt_common_ctx cctx;
struct slbt_driver_ctx ctx;
struct slbt_host_strs host;
struct slbt_host_strs ahost;
struct slbt_fd_ctx fdctx;
+ struct slbt_obj_list * objlistv;
char * libname;
char * dargs;
char ** dargv;
diff --git a/src/internal/slibtool_objlist_impl.c b/src/internal/slibtool_objlist_impl.c
new file mode 100644
index 0000000..be3d994
--- /dev/null
+++ b/src/internal/slibtool_objlist_impl.c
@@ -0,0 +1,82 @@
+/*******************************************************************/
+/* slibtool: a skinny libtool implementation, written in C */
+/* Copyright (C) 2016--2023 SysDeer Technologies, LLC */
+/* Released under the Standard MIT License; see COPYING.SLIBTOOL. */
+/*******************************************************************/
+
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+
+#include "slibtool_driver_impl.h"
+#include "slibtool_errinfo_impl.h"
+#include "slibtool_mapfile_impl.h"
+#include "slibtool_objlist_impl.h"
+
+int slbt_objlist_read(
+ int fdcwd,
+ struct slbt_obj_list * objlist)
+{
+ struct slbt_map_info * mapinfo;
+ int objc;
+ char ** objv;
+ char * src;
+ char * dst;
+ char * mark;
+ int skip;
+
+ /* temporarily map the object list */
+ if (!(mapinfo = slbt_map_file(fdcwd,objlist->name,SLBT_MAP_INPUT)))
+ return -1;
+
+ /* object list, cautionary null termination, vector null termination */
+ objlist->size = mapinfo->size;
+ objlist->size++;
+ objlist->size++;
+
+ if (!(objlist->addr = calloc(1,objlist->size))) {
+ slbt_unmap_file(mapinfo);
+ return -1;
+ }
+
+ /* object list file to normalized object strings */
+ objc = 0;
+ skip = true;
+
+ for (src=mapinfo->addr,dst=objlist->addr; src<mapinfo->cap; src++) {
+ if (!*src || (*src==' ') || (*src=='\n') || (*src=='\r')) {
+ if (!skip)
+ *dst++ = 0;
+
+ skip = true;
+ } else {
+ *dst++ = *src;
+
+ objc += !!skip;
+ skip = false;
+ }
+ }
+
+ /* object vector */
+ objlist->objc = objc;
+
+ if (!(objlist->objv = calloc(++objc,sizeof(char *)))) {
+ free(objlist->addr);
+ slbt_unmap_file(mapinfo);
+ return -1;
+ }
+
+ for (objv=objlist->objv,mark=objlist->addr; *mark; objv++) {
+ *objv = mark;
+ mark += strlen(mark) + 1;
+ }
+
+ slbt_unmap_file(mapinfo);
+
+ return 0;
+}
diff --git a/src/internal/slibtool_objlist_impl.h b/src/internal/slibtool_objlist_impl.h
new file mode 100644
index 0000000..cb11d07
--- /dev/null
+++ b/src/internal/slibtool_objlist_impl.h
@@ -0,0 +1,10 @@
+#ifndef SLIBTOOL_OBJLIST_IMPL_H
+#define SLIBTOOL_OBJLIST_IMPL_H
+
+#include "slibtool_driver_impl.h"
+
+int slbt_objlist_read(
+ int fdcwd,
+ struct slbt_obj_list * objlist);
+
+#endif