From 2c190da52dbfe58d46c8e4d4dcc924fb444e0334 Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 4 Feb 2017 11:50:08 -0500 Subject: logic: replaced interface: prefix mdso_generate --> mdso_asmgen. --- include/mdso/mdso.h | 6 +-- project/common.mk | 6 +-- src/logic/mdso_asmgen_dsometa.c | 84 ++++++++++++++++++++++++++++++++++ src/logic/mdso_asmgen_symentry.c | 65 ++++++++++++++++++++++++++ src/logic/mdso_asmgen_symfn.c | 42 +++++++++++++++++ src/logic/mdso_create_implib_sources.c | 6 +-- src/logic/mdso_generate_dsometa.c | 84 ---------------------------------- src/logic/mdso_generate_symentry.c | 65 -------------------------- src/logic/mdso_generate_symfn.c | 42 ----------------- 9 files changed, 200 insertions(+), 200 deletions(-) create mode 100644 src/logic/mdso_asmgen_dsometa.c create mode 100644 src/logic/mdso_asmgen_symentry.c create mode 100644 src/logic/mdso_asmgen_symfn.c delete mode 100644 src/logic/mdso_generate_dsometa.c delete mode 100644 src/logic/mdso_generate_symentry.c delete mode 100644 src/logic/mdso_generate_symfn.c diff --git a/include/mdso/mdso.h b/include/mdso/mdso.h index d8c5057..c60979a 100644 --- a/include/mdso/mdso.h +++ b/include/mdso/mdso.h @@ -133,9 +133,9 @@ mdso_api int mdso_output_error_vector (const struct mdso_driver_ctx *); /* low-level api */ 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 int mdso_generate_dsometa (const struct mdso_driver_ctx *, FILE * fout); -mdso_api int mdso_generate_symentry(const struct mdso_driver_ctx *, const char * sym, FILE * fout); -mdso_api int mdso_generate_symfn (const struct mdso_driver_ctx *, const char * sym, FILE * fout); +mdso_api int mdso_asmgen_dsometa (const struct mdso_driver_ctx *, FILE * fout); +mdso_api int mdso_asmgen_symentry (const struct mdso_driver_ctx *, const char * sym, FILE * fout); +mdso_api int mdso_asmgen_symfn (const struct mdso_driver_ctx *, const char * sym, FILE * fout); #ifdef __cplusplus } diff --git a/project/common.mk b/project/common.mk index 70c7778..26c2c7a 100644 --- a/project/common.mk +++ b/project/common.mk @@ -6,9 +6,9 @@ API_SRCS = \ src/driver/mdso_unit_ctx.c \ src/helper/mdso_create_asm_source.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 \ + src/logic/mdso_asmgen_dsometa.c \ + src/logic/mdso_asmgen_symentry.c \ + src/logic/mdso_asmgen_symfn.c \ src/logic/mdso_map_input.c \ src/output/mdso_output_error.c \ src/output/mdso_output_export_symbols.c \ 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 +#include + +#include +#include +#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; +} diff --git a/src/logic/mdso_asmgen_symentry.c b/src/logic/mdso_asmgen_symentry.c new file mode 100644 index 0000000..7db988a --- /dev/null +++ b/src/logic/mdso_asmgen_symentry.c @@ -0,0 +1,65 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015--2017 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include +#include + +#include +#include +#include "mdso_errinfo_impl.h" + +static const char * const asm_lines[] = { + "\t.section " MDSO_STRS_SECTION ",\"r0\"\n\n", + ".__dsostr_%s:\n", + "\t.ascii\t\"%s\\0\"\n\n" + "\t.section " MDSO_SYMS_SECTION ",\"r\"\n", + 0 +}; + +int mdso_asmgen_symentry( + const struct mdso_driver_ctx * dctx, + const char * sym, + FILE * fout) +{ + const char * const * line; + const char * alignstr; + const char * ptrsize; + const char * uscore; + + if (fprintf(fout,"\t.file \"__%s_sym_entry.s\"\n",sym) < 0) + return MDSO_FILE_ERROR(dctx); + + if (dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR) { + alignstr = "\t.balign 16\n\n"; + ptrsize = ".quad"; + uscore = ""; + } else { + alignstr = "\t.balign 8\n\n"; + ptrsize = ".long"; + uscore = "_"; + } + + for (line=asm_lines; *line; line++) + if ((fprintf(fout,*line,sym)) < 0) + return MDSO_FILE_ERROR(dctx); + + if (fprintf(fout,"\t.globl __imp_%s%s\n",uscore,sym) < 0) + return MDSO_FILE_ERROR(dctx); + + if ((fputs(alignstr,fout)) < 0) + return MDSO_FILE_ERROR(dctx); + + if ((fprintf(fout,"__imp_%s%s:\n",uscore,sym)) < 0) + return MDSO_FILE_ERROR(dctx); + + if ((fprintf(fout,"\t%s\t.__dsostr_%s\n",ptrsize,sym)) < 0) + return MDSO_FILE_ERROR(dctx); + + if ((fprintf(fout,"\t%s\t.__dsometa_%s\n",ptrsize,dctx->cctx->libname)) < 0) + return MDSO_FILE_ERROR(dctx); + + return 0; +} diff --git a/src/logic/mdso_asmgen_symfn.c b/src/logic/mdso_asmgen_symfn.c new file mode 100644 index 0000000..a3960b3 --- /dev/null +++ b/src/logic/mdso_asmgen_symfn.c @@ -0,0 +1,42 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015--2017 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include +#include + +#include +#include "mdso_errinfo_impl.h" + +static const char * const asm_lines[] = { + "\t.section .text\n", + "\t.globl %s%s\n", + "\t.def %s%s; .scl 2; .type 32; .endef\n\n", + + "%s%s:\n", + "\tjmp *__imp_%s%s\n\n", + 0 +}; + +int mdso_asmgen_symfn( + const struct mdso_driver_ctx * dctx, + const char * sym, + FILE * fout) +{ + const char * const * line; + const char * uscore; + + if (fprintf(fout,"\t.file \"__%s_sym_fn.s\"\n",sym) < 0) + return MDSO_FILE_ERROR(dctx); + + uscore = (dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR) + ? "" : "_"; + + for (line=asm_lines; *line; line++) + if (fprintf(fout,*line,uscore,sym) < 0) + return MDSO_FILE_ERROR(dctx); + + return 0; +} diff --git a/src/logic/mdso_create_implib_sources.c b/src/logic/mdso_create_implib_sources.c index e0ba209..864d2f5 100644 --- a/src/logic/mdso_create_implib_sources.c +++ b/src/logic/mdso_create_implib_sources.c @@ -38,7 +38,7 @@ mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx) if (!(fout = mdso_create_asm_source(dctx,asmname))) return MDSO_NESTED_ERROR(dctx); - ret = mdso_generate_dsometa(dctx,fout); + ret = mdso_asmgen_dsometa(dctx,fout); if (fout != stdout) fclose(fout); @@ -56,7 +56,7 @@ mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx) if (!(fout = mdso_create_asm_source(dctx,asmname))) return MDSO_NESTED_ERROR(dctx); - ret = mdso_generate_symentry(dctx,*sym,fout); + ret = mdso_asmgen_symentry(dctx,*sym,fout); if (fout != stdout) fclose(fout); @@ -69,7 +69,7 @@ mdso_api int mdso_create_implib_sources(const struct mdso_driver_ctx * dctx) if (!(fout = mdso_create_asm_source(dctx,asmname))) return MDSO_NESTED_ERROR(dctx); - ret = mdso_generate_symfn(dctx,*sym,fout); + ret = mdso_asmgen_symfn(dctx,*sym,fout); if (fout != stdout) fclose(fout); diff --git a/src/logic/mdso_generate_dsometa.c b/src/logic/mdso_generate_dsometa.c deleted file mode 100644 index 50e9eb0..0000000 --- a/src/logic/mdso_generate_dsometa.c +++ /dev/null @@ -1,84 +0,0 @@ -/****************************************************************/ -/* mdso: midipix dso scavenger */ -/* Copyright (C) 2015--2017 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ -/****************************************************************/ - -#include -#include - -#include -#include -#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_generate_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; -} diff --git a/src/logic/mdso_generate_symentry.c b/src/logic/mdso_generate_symentry.c deleted file mode 100644 index 8aa48c7..0000000 --- a/src/logic/mdso_generate_symentry.c +++ /dev/null @@ -1,65 +0,0 @@ -/****************************************************************/ -/* mdso: midipix dso scavenger */ -/* Copyright (C) 2015--2017 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ -/****************************************************************/ - -#include -#include - -#include -#include -#include "mdso_errinfo_impl.h" - -static const char * const asm_lines[] = { - "\t.section " MDSO_STRS_SECTION ",\"r0\"\n\n", - ".__dsostr_%s:\n", - "\t.ascii\t\"%s\\0\"\n\n" - "\t.section " MDSO_SYMS_SECTION ",\"r\"\n", - 0 -}; - -int mdso_generate_symentry( - const struct mdso_driver_ctx * dctx, - const char * sym, - FILE * fout) -{ - const char * const * line; - const char * alignstr; - const char * ptrsize; - const char * uscore; - - if (fprintf(fout,"\t.file \"__%s_sym_entry.s\"\n",sym) < 0) - return MDSO_FILE_ERROR(dctx); - - if (dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR) { - alignstr = "\t.balign 16\n\n"; - ptrsize = ".quad"; - uscore = ""; - } else { - alignstr = "\t.balign 8\n\n"; - ptrsize = ".long"; - uscore = "_"; - } - - for (line=asm_lines; *line; line++) - if ((fprintf(fout,*line,sym)) < 0) - return MDSO_FILE_ERROR(dctx); - - if (fprintf(fout,"\t.globl __imp_%s%s\n",uscore,sym) < 0) - return MDSO_FILE_ERROR(dctx); - - if ((fputs(alignstr,fout)) < 0) - return MDSO_FILE_ERROR(dctx); - - if ((fprintf(fout,"__imp_%s%s:\n",uscore,sym)) < 0) - return MDSO_FILE_ERROR(dctx); - - if ((fprintf(fout,"\t%s\t.__dsostr_%s\n",ptrsize,sym)) < 0) - return MDSO_FILE_ERROR(dctx); - - if ((fprintf(fout,"\t%s\t.__dsometa_%s\n",ptrsize,dctx->cctx->libname)) < 0) - return MDSO_FILE_ERROR(dctx); - - return 0; -} diff --git a/src/logic/mdso_generate_symfn.c b/src/logic/mdso_generate_symfn.c deleted file mode 100644 index 2e937d1..0000000 --- a/src/logic/mdso_generate_symfn.c +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************/ -/* mdso: midipix dso scavenger */ -/* Copyright (C) 2015--2017 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ -/****************************************************************/ - -#include -#include - -#include -#include "mdso_errinfo_impl.h" - -static const char * const asm_lines[] = { - "\t.section .text\n", - "\t.globl %s%s\n", - "\t.def %s%s; .scl 2; .type 32; .endef\n\n", - - "%s%s:\n", - "\tjmp *__imp_%s%s\n\n", - 0 -}; - -int mdso_generate_symfn( - const struct mdso_driver_ctx * dctx, - const char * sym, - FILE * fout) -{ - const char * const * line; - const char * uscore; - - if (fprintf(fout,"\t.file \"__%s_sym_fn.s\"\n",sym) < 0) - return MDSO_FILE_ERROR(dctx); - - uscore = (dctx->cctx->drvflags & MDSO_DRIVER_QUAD_PTR) - ? "" : "_"; - - for (line=asm_lines; *line; line++) - if (fprintf(fout,*line,uscore,sym) < 0) - return MDSO_FILE_ERROR(dctx); - - return 0; -} -- cgit v1.2.3