summaryrefslogtreecommitdiff
path: root/src/logic/mdso_generate_dsometa.c
blob: 80a3b8cab796ebd3c9f645c16e56c6778a1aa20f (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;
}