summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-12-22 23:26:55 -0500
committermidipix <writeonce@midipix.org>2016-11-11 00:22:30 -0500
commitefc615e033a4e0e3ed23e62edb3053a80a43b437 (patch)
treeac71d2250aa814be9a718b45cf03e2d66a59bd15
parent67025de5a14bc568da8576b1a0cbded6ebedf7f2 (diff)
downloadmdso-efc615e033a4e0e3ed23e62edb3053a80a43b437.tar.bz2
mdso-efc615e033a4e0e3ed23e62edb3053a80a43b437.tar.xz
mdso_generate_symentry(): initial implementation.
-rw-r--r--include/mdso/mdso.h1
-rw-r--r--project/common.mk1
-rw-r--r--src/logic/mdso_generate_symentry.c60
3 files changed, 62 insertions, 0 deletions
diff --git a/include/mdso/mdso.h b/include/mdso/mdso.h
index f912fe8..2ac8dd4 100644
--- a/include/mdso/mdso.h
+++ b/include/mdso/mdso.h
@@ -91,6 +91,7 @@ mdso_api int mdso_output_export_symbols(const struct mdso_unit_ctx *, const str
mdso_api uint32_t mdso_crc32_mbstr (const unsigned char * str, size_t * symlen);
mdso_api uint64_t mdso_crc64_mbstr (const unsigned char * str, size_t * symlen);
mdso_api FILE * mdso_create_output (const struct mdso_driver_ctx *, const char * asmname);
+mdso_api int mdso_generate_symentry(const struct mdso_common_ctx *, const char * sym, FILE * fout);
#ifdef __cplusplus
}
diff --git a/project/common.mk b/project/common.mk
index 2d7fad1..2533550 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_generate_symentry.c \
src/logic/mdso_map_input.c \
src/output/mdso_create_output.c \
src/output/mdso_output_export_symbols.c \
diff --git a/src/logic/mdso_generate_symentry.c b/src/logic/mdso_generate_symentry.c
new file mode 100644
index 0000000..df55186
--- /dev/null
+++ b/src/logic/mdso_generate_symentry.c
@@ -0,0 +1,60 @@
+/****************************************************************/
+/* mdso: midipix dso scavenger */
+/* Copyright (C) 2015 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
+/****************************************************************/
+
+#include <stdint.h>
+#include <stdio.h>
+#include <mdso/mdso.h>
+#include <mdso/mdso_specs.h>
+
+static const char * const asm_lines[] = {
+ "\t.file \"__%s_sym_entry.s\"\n",
+
+ "\t.section " MDSO_STRS_SECTION ",\"r\"\n",
+ "\t.globl .__dsostr_%s\n",
+ "\t.balign 2\n\n",
+ ".__dsostr_%s:\n",
+ "\t.ascii\t\"%s\\0\"\n\n"
+
+ "\t.section " MDSO_SYMS_SECTION ",\"r\"\n",
+ "\t.globl __imp_%s\n",
+ 0
+};
+
+int mdso_generate_symentry(
+ const struct mdso_common_ctx * cctx,
+ const char * sym,
+ FILE * fout)
+{
+ const char * const * line;
+ const char * alignstr;
+ const char * ptrsize;
+
+ if (cctx->drvflags & MDSO_DRIVER_QUAD_PTR) {
+ alignstr = "\t.balign 16\n\n";
+ ptrsize = ".quad";
+ } else {
+ alignstr = "\t.balign 8\n\n";
+ ptrsize = ".long";
+ }
+
+ for (line=asm_lines; *line; line++)
+ if ((fprintf(fout,*line,sym)) < 0)
+ return -1;
+
+ if ((fputs(alignstr,fout)) < 0)
+ return -1;
+
+ if ((fprintf(fout,"__imp_%s:\n",sym)) < 0)
+ return -1;
+
+ if ((fprintf(fout,"\t%s\t.__dsostr_%s\n",ptrsize,sym)) < 0)
+ return -1;
+
+ if ((fprintf(fout,"\t%s\t.__dsometa_%s\n",ptrsize,cctx->libname)) < 0)
+ return -1;
+
+ return 0;
+}