summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-12-23 00:53:59 -0500
committermidipix <writeonce@midipix.org>2016-11-11 00:22:31 -0500
commitf455847564c7cb6a7a95c451351cd0ff2adb8a31 (patch)
tree01f6e5343f397bdd26580939a88f6867f7676db1
parent6848b7f8ed9521f9c4c36b62d4d204e693194cee (diff)
downloadmdso-f455847564c7cb6a7a95c451351cd0ff2adb8a31.tar.bz2
mdso-f455847564c7cb6a7a95c451351cd0ff2adb8a31.tar.xz
mdso_generate_dsometa(): initial implementation.
-rw-r--r--include/mdso/mdso.h1
-rw-r--r--project/common.mk1
-rw-r--r--src/logic/mdso_generate_dsometa.c67
3 files changed, 69 insertions, 0 deletions
diff --git a/include/mdso/mdso.h b/include/mdso/mdso.h
index 6f2796c..6a217a0 100644
--- a/include/mdso/mdso.h
+++ b/include/mdso/mdso.h
@@ -92,6 +92,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_dsometa (const struct mdso_common_ctx *, FILE * fout);
mdso_api int mdso_generate_symentry(const struct mdso_common_ctx *, const char * sym, FILE * fout);
mdso_api int mdso_generate_symfn (const char * sym, FILE * fout);
diff --git a/project/common.mk b/project/common.mk
index 9278e97..ae97c6e 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_dsometa.c \
src/logic/mdso_generate_symentry.c \
src/logic/mdso_generate_symfn.c \
src/logic/mdso_map_input.c \
diff --git a/src/logic/mdso_generate_dsometa.c b/src/logic/mdso_generate_dsometa.c
new file mode 100644
index 0000000..80a3b8c
--- /dev/null
+++ b/src/logic/mdso_generate_dsometa.c
@@ -0,0 +1,67 @@
+/****************************************************************/
+/* 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_hdr_lines[] = {
+ "\t.file \"__%s_dso_meta.s\"\n",
+
+ "\t.section " MDSO_META_SECTION ",\"r\"\n",
+ "\t.globl .__dsometa_%s\n",
+ 0
+};
+
+static const char * const asm_meta_lines[] = {
+ "\t.long\t0 # priority\n",
+ "\t.long\t0 # nsyms\n",
+ "\t.long\t0 # padding\n",
+ "\t%s\t0 # hashtbl\n",
+ "\t%s\t0 # symtbl\n",
+ "\t%s\t0 # fncarg\n",
+ "\t%s\t0 # fncargarr\n",
+ "\t%s\t0 # fnr1\n",
+ "\t%s\t0 # fnr2\n",
+ 0
+};
+
+int mdso_generate_dsometa(
+ const struct mdso_common_ctx * cctx,
+ 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_hdr_lines; *line; line++)
+ if ((fprintf(fout,*line,cctx->libname)) < 0)
+ return -1;
+
+ if ((fputs(alignstr,fout)) < 0)
+ return -1;
+
+ if ((fprintf(fout,"\t%s\t%d\t# base\n",ptrsize,0)) < 0)
+ return -1;
+
+ if ((fprintf(fout,"\t%s\t%d\t# flags\n",".long",cctx->dsoflags)) < 0)
+ return -1;
+
+ for (line=asm_meta_lines; *line; line++)
+ if ((fprintf(fout,*line,ptrsize)) < 0)
+ return -1;
+
+ return 0;
+}