summaryrefslogtreecommitdiffhomepage
path: root/src/util
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2017-02-08 01:08:41 -0500
committermidipix <writeonce@midipix.org>2017-02-08 01:19:09 -0500
commit00a88c01dc20c33da1936600d46974d460a23cc4 (patch)
tree2b0de22c0b68520e9504b566fce23d67ab16b05b /src/util
parenta75141e458ef5b5016961afcb789ee8d2cee2584 (diff)
downloadmdso-00a88c01dc20c33da1936600d46974d460a23cc4.tar.bz2
mdso-00a88c01dc20c33da1936600d46974d460a23cc4.tar.xz
project: source tree: tidy up.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/mdso_create_implib_objects.c79
-rw-r--r--src/util/mdso_create_implib_sources.c85
2 files changed, 164 insertions, 0 deletions
diff --git a/src/util/mdso_create_implib_objects.c b/src/util/mdso_create_implib_objects.c
new file mode 100644
index 0000000..dd681e0
--- /dev/null
+++ b/src/util/mdso_create_implib_objects.c
@@ -0,0 +1,79 @@
+/****************************************************************/
+/* mdso: midipix dso scavenger */
+/* Copyright (C) 2015--2017 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
+/****************************************************************/
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <mdso/mdso.h>
+#include "mdso_errinfo_impl.h"
+
+static void mdso_init_objname(char * buf, const char * fmt, const char * str)
+{
+ char hexstr[24];
+ long long unsigned int crc64;
+
+ if (strlen(str) + strlen(fmt) > (PATH_MAX - 1)) {
+ crc64 = mdso_crc64_mbstr((const unsigned char *)str,0);
+ sprintf(hexstr,"%llx",crc64);
+ sprintf(buf,fmt,hexstr);
+ } else
+ sprintf(buf,fmt,str);
+}
+
+mdso_api int mdso_create_implib_objects(const struct mdso_driver_ctx * dctx)
+{
+ struct mdso_unit_ctx * uctx;
+ const char ** unit;
+ FILE * fout;
+ char objname[PATH_MAX];
+ const char * const * sym;
+ int ret;
+
+ mdso_init_objname(objname,".dsometa_%s.o",dctx->cctx->libname);
+
+ if (!(fout = mdso_create_object(dctx,objname)))
+ return MDSO_NESTED_ERROR(dctx);
+
+ ret = mdso_objgen_dsometa(dctx,fout,0);
+ fclose(fout);
+
+ if (ret < 0)
+ return MDSO_NESTED_ERROR(dctx);
+
+ for (unit=dctx->units; *unit; unit++) {
+ if (mdso_get_unit_ctx(dctx,*unit,&uctx))
+ return MDSO_NESTED_ERROR(dctx);
+
+ for (sym=uctx->syms; *sym; sym++) {
+ mdso_init_objname(objname,".%s_symentry.o",*sym);
+
+ if (!(fout = mdso_create_object(dctx,objname)))
+ return MDSO_NESTED_ERROR(dctx);
+
+ ret = mdso_objgen_symentry(dctx,*sym,fout,0);
+ fclose(fout);
+
+ if (ret < 0)
+ return MDSO_NESTED_ERROR(dctx);
+
+ mdso_init_objname(objname,".%s_symfn.o",*sym);
+
+ if (!(fout = mdso_create_object(dctx,objname)))
+ return MDSO_NESTED_ERROR(dctx);
+
+ ret = mdso_objgen_symfn(dctx,*sym,fout,0);
+ fclose(fout);
+
+ if (ret < 0)
+ return MDSO_NESTED_ERROR(dctx);
+ }
+
+ mdso_free_unit_ctx(uctx);
+ }
+
+ return 0;
+}
diff --git a/src/util/mdso_create_implib_sources.c b/src/util/mdso_create_implib_sources.c
new file mode 100644
index 0000000..1031920
--- /dev/null
+++ b/src/util/mdso_create_implib_sources.c
@@ -0,0 +1,85 @@
+/****************************************************************/
+/* mdso: midipix dso scavenger */
+/* Copyright (C) 2015--2017 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
+/****************************************************************/
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <mdso/mdso.h>
+#include "mdso_errinfo_impl.h"
+
+static void mdso_init_asmname(char * buf, const char * fmt, const char * str)
+{
+ char hexstr[24];
+ long long unsigned int crc64;
+
+ if (strlen(str) + strlen(fmt) > (PATH_MAX - 1)) {
+ crc64 = mdso_crc64_mbstr((const unsigned char *)str,0);
+ sprintf(hexstr,"%llx",crc64);
+ sprintf(buf,fmt,hexstr);
+ } else
+ sprintf(buf,fmt,str);
+}
+
+mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx)
+{
+ struct mdso_unit_ctx * uctx;
+ const char ** unit;
+ FILE * fout;
+ char asmname[PATH_MAX];
+ const char * const * sym;
+ int ret;
+
+ mdso_init_asmname(asmname,".dsometa_%s.s",dctx->cctx->libname);
+
+ if (!(fout = mdso_create_asm_source(dctx,asmname)))
+ return MDSO_NESTED_ERROR(dctx);
+
+ ret = mdso_asmgen_dsometa(dctx,fout);
+
+ if (fout != stdout)
+ fclose(fout);
+
+ if (ret < 0)
+ return MDSO_NESTED_ERROR(dctx);
+
+ for (unit=dctx->units; *unit; unit++) {
+ if (mdso_get_unit_ctx(dctx,*unit,&uctx))
+ return MDSO_NESTED_ERROR(dctx);
+
+ for (sym=uctx->syms; *sym; sym++) {
+ mdso_init_asmname(asmname,".%s_symentry.s",*sym);
+
+ if (!(fout = mdso_create_asm_source(dctx,asmname)))
+ return MDSO_NESTED_ERROR(dctx);
+
+ ret = mdso_asmgen_symentry(dctx,*sym,fout);
+
+ if (fout != stdout)
+ fclose(fout);
+
+ if (ret < 0)
+ return MDSO_NESTED_ERROR(dctx);
+
+ mdso_init_asmname(asmname,".%s_symfn.s",*sym);
+
+ if (!(fout = mdso_create_asm_source(dctx,asmname)))
+ return MDSO_NESTED_ERROR(dctx);
+
+ ret = mdso_asmgen_symfn(dctx,*sym,fout);
+
+ if (fout != stdout)
+ fclose(fout);
+
+ if (ret < 0)
+ return MDSO_NESTED_ERROR(dctx);
+ }
+
+ mdso_free_unit_ctx(uctx);
+ }
+
+ return 0;
+}