summaryrefslogtreecommitdiffhomepage
path: root/src/logic/mdso_generate_symfn.c
blob: 7b3b2955d8e096c03a6122652e7440c4219f7b9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/****************************************************************/
/*  mdso: midipix dso scavenger                                 */
/*  Copyright (C) 2015--2016  Z. Gilboa                         */
/*  Released under GPLv2 and GPLv3; see COPYING.MDSO.           */
/****************************************************************/

#include <stdint.h>
#include <stdio.h>

#include <mdso/mdso.h>
#include "mdso_errinfo_impl.h"

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 struct mdso_driver_ctx *	dctx,
	const char *			sym,
	FILE *				fout)
{
	const char * const * line;

	for (line=asm_lines; *line; line++)
		if ((fprintf(fout,*line,sym)) < 0)
			return MDSO_FILE_ERROR(dctx);

	return 0;
}