summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/mdso/mdso.h1
-rw-r--r--project/common.mk1
-rw-r--r--src/logic/mdso_create_implib_sources.c83
-rw-r--r--src/mdso.c4
4 files changed, 89 insertions, 0 deletions
diff --git a/include/mdso/mdso.h b/include/mdso/mdso.h
index 6a217a0..dc599b2 100644
--- a/include/mdso/mdso.h
+++ b/include/mdso/mdso.h
@@ -87,6 +87,7 @@ mdso_api int mdso_unmap_input (struct mdso_input *);
/* utility api */
mdso_api int mdso_output_export_symbols(const struct mdso_unit_ctx *, const struct mdso_common_ctx *, FILE *);
+mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx *);
/* low-level api */
mdso_api uint32_t mdso_crc32_mbstr (const unsigned char * str, size_t * symlen);
diff --git a/project/common.mk b/project/common.mk
index ae97c6e..a768e42 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -3,6 +3,7 @@ COMMON_SRCS = \
src/crc/mdso_crc32.c \
src/driver/mdso_driver_ctx.c \
src/driver/mdso_unit_ctx.c \
+ src/logic/mdso_create_implib_sources.c \
src/logic/mdso_generate_dsometa.c \
src/logic/mdso_generate_symentry.c \
src/logic/mdso_generate_symfn.c \
diff --git a/src/logic/mdso_create_implib_sources.c b/src/logic/mdso_create_implib_sources.c
new file mode 100644
index 0000000..7579c51
--- /dev/null
+++ b/src/logic/mdso_create_implib_sources.c
@@ -0,0 +1,83 @@
+/****************************************************************/
+/* mdso: midipix dso scavenger */
+/* Copyright (C) 2015 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
+/****************************************************************/
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <mdso/mdso.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,"__%s_dso_meta.s",dctx->cctx->libname);
+
+ if (!(fout = mdso_create_output(dctx,asmname)))
+ return -1;
+
+ ret = mdso_generate_dsometa(dctx->cctx,fout);
+
+ if (fout != stdout)
+ fclose(fout);
+
+ if (ret < 0)
+ return -1;
+
+ for (unit=dctx->units; *unit; unit++) {
+ if (mdso_get_unit_ctx(dctx,*unit,&uctx))
+ return -1;
+
+ for (sym=uctx->syms; *sym; sym++) {
+ mdso_init_asmname(asmname,"__%s_sym_entry.s",*sym);
+
+ if (!(fout = mdso_create_output(dctx,asmname)))
+ return -1;
+
+ ret = mdso_generate_symentry(dctx->cctx,*sym,fout);
+
+ if (fout != stdout)
+ fclose(fout);
+
+ if (ret < 0)
+ return -1;
+
+ mdso_init_asmname(asmname,"__%s_sym_fn.s",*sym);
+
+ if (!(fout = mdso_create_output(dctx,asmname)))
+ return -1;
+
+ ret = mdso_generate_symfn(*sym,fout);
+
+ if (fout != stdout)
+ fclose(fout);
+
+ if (ret < 0)
+ return -1;
+ }
+
+ mdso_free_unit_ctx(uctx);
+ }
+
+ return 0;
+}
diff --git a/src/mdso.c b/src/mdso.c
index 1480325..4c0b667 100644
--- a/src/mdso.c
+++ b/src/mdso.c
@@ -60,6 +60,10 @@ int mdso_main(int argc, const char ** argv, const char ** envp)
}
}
+ dctx->status = mdso_create_implib_sources(dctx);
+ dctx->nerrors += !!dctx->status;
+ ret += dctx->nerrors;
+
return mdso_exit(dctx,ret);
}