From 6691d883d212073b429b940edc8756b0179b4218 Mon Sep 17 00:00:00 2001 From: midipix Date: Tue, 22 Dec 2015 23:32:20 -0500 Subject: mdso_generate_symfn(): initial implementation. --- include/mdso/mdso.h | 1 + project/common.mk | 1 + src/logic/mdso_generate_symfn.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/logic/mdso_generate_symfn.c diff --git a/include/mdso/mdso.h b/include/mdso/mdso.h index 2ac8dd4..88159fc 100644 --- a/include/mdso/mdso.h +++ b/include/mdso/mdso.h @@ -92,6 +92,7 @@ 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); +mdso_api int mdso_generate_symfn (const char * sym, FILE * fout); #ifdef __cplusplus } diff --git a/project/common.mk b/project/common.mk index 2533550..9278e97 100644 --- a/project/common.mk +++ b/project/common.mk @@ -4,6 +4,7 @@ COMMON_SRCS = \ src/driver/mdso_driver_ctx.c \ src/driver/mdso_unit_ctx.c \ src/logic/mdso_generate_symentry.c \ + src/logic/mdso_generate_symfn.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_symfn.c b/src/logic/mdso_generate_symfn.c new file mode 100644 index 0000000..4e8de54 --- /dev/null +++ b/src/logic/mdso_generate_symfn.c @@ -0,0 +1,31 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include +#include +#include + +static const char * const asm_lines[] = { + "\t.file \"__%s_sym_fn.s\"\n", + "\t.section .text\n", + "\t.globl %s\n", + "\t.def %s; .scl 2; .type 32; .endef\n\n", + + "%s:\n", + "\tjmp *__imp_%s\n\n", + 0 +}; + +int mdso_generate_symfn(const char * sym, FILE * fout) +{ + const char * const * line; + + for (line=asm_lines; *line; line++) + if ((fprintf(fout,*line,sym)) < 0) + return -1; + + return 0; +} -- cgit v1.2.3