summaryrefslogtreecommitdiffhomepage
path: root/src/logic/mdso_asmgen_dsometa.c
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2017-02-04 11:50:08 -0500
committermidipix <writeonce@midipix.org>2017-02-04 11:50:08 -0500
commit2c190da52dbfe58d46c8e4d4dcc924fb444e0334 (patch)
tree38e7880037f2ec5ab89137647f9cf0128f833318 /src/logic/mdso_asmgen_dsometa.c
parent78ab3c85dada5e34f6697e782a793e42c70e8d1a (diff)
downloadmdso-2c190da52dbfe58d46c8e4d4dcc924fb444e0334.tar.bz2
mdso-2c190da52dbfe58d46c8e4d4dcc924fb444e0334.tar.xz
logic: replaced interface: prefix mdso_generate --> mdso_asmgen.
Diffstat (limited to 'src/logic/mdso_asmgen_dsometa.c')
-rw-r--r--src/logic/mdso_asmgen_dsometa.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/logic/mdso_asmgen_dsometa.c b/src/logic/mdso_asmgen_dsometa.c
new file mode 100644
index 0000000..6cf9186
--- /dev/null
+++ b/src/logic/mdso_asmgen_dsometa.c
@@ -0,0 +1,84 @@
+/****************************************************************/
+/* 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 <mdso/mdso.h>
+#include <mdso/mdso_specs.h>
+#include "mdso_errinfo_impl.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
+};
+
+static const char * const asm_libname_fmt =
+ "\n\n"
+ "\t.section " MDSO_STRS_SECTION ",\"r0\"\n\n"
+ "._name:\n"
+ "\t.ascii\t\"%s\\0\"\n\n";
+
+int mdso_asmgen_dsometa(
+ const struct mdso_driver_ctx * dctx,
+ FILE * fout)
+{
+ const char * const * line;
+ const char * alignstr;
+ const char * ptrsize;
+
+ if (dctx->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,dctx->cctx->libname)) < 0)
+ return MDSO_FILE_ERROR(dctx);
+
+ if ((fputs(alignstr,fout)) < 0)
+ return MDSO_FILE_ERROR(dctx);
+
+ if ((fprintf(fout,".__dsometa_%s:\n",dctx->cctx->libname)) < 0)
+ return MDSO_FILE_ERROR(dctx);
+
+ if ((fprintf(fout,"\t%s\t%d\t# base\n",ptrsize,0)) < 0)
+ return MDSO_FILE_ERROR(dctx);
+
+ if ((fprintf(fout,"\t%s\t%s\t# name\n",ptrsize,"._name")) < 0)
+ return MDSO_FILE_ERROR(dctx);
+
+ if ((fprintf(fout,"\t%s\t%u\t# flags\n",".long",dctx->cctx->dsoflags)) < 0)
+ return MDSO_FILE_ERROR(dctx);
+
+ for (line=asm_meta_lines; *line; line++)
+ if ((fprintf(fout,*line,ptrsize)) < 0)
+ return MDSO_FILE_ERROR(dctx);
+
+ if (fprintf(fout,asm_libname_fmt,dctx->cctx->libname) < 0)
+ return MDSO_FILE_ERROR(dctx);
+
+ return 0;
+}