Blame src/logic/mdso_generate_dsometa.c

f45584
/****************************************************************/
f45584
/*  mdso: midipix dso scavenger                                 */
3e816c
/*  Copyright (C) 2015--2016  Z. Gilboa                         */
f45584
/*  Released under GPLv2 and GPLv3; see COPYING.MDSO.           */
f45584
/****************************************************************/
f45584
f45584
#include <stdint.h>
f45584
#include <stdio.h>
f45584
#include <mdso/mdso.h>
f45584
#include <mdso/mdso_specs.h>
f45584
f45584
static const char * const asm_hdr_lines[] = {
f45584
	"\t.file     \"__%s_dso_meta.s\"\n",
f45584
f45584
	"\t.section  " MDSO_META_SECTION ",\"r\"\n",
f45584
	"\t.globl    .__dsometa_%s\n",
f45584
	0
f45584
};
f45584
f45584
static const char * const asm_meta_lines[] = {
f45584
	"\t.long\t0	# priority\n",
f45584
	"\t.long\t0	# nsyms\n",
f45584
	"\t.long\t0	# padding\n",
f45584
	"\t%s\t0	# hashtbl\n",
f45584
	"\t%s\t0	# symtbl\n",
f45584
	"\t%s\t0	# fncarg\n",
f45584
	"\t%s\t0	# fncargarr\n",
f45584
	"\t%s\t0	# fnr1\n",
f45584
	"\t%s\t0	# fnr2\n",
f45584
	0
f45584
};
f45584
f45584
int mdso_generate_dsometa(
f45584
	const struct mdso_common_ctx *	cctx,
f45584
	FILE *				fout)
f45584
{
f45584
	const char * const *	line;
f45584
	const char *		alignstr;
f45584
	const char *		ptrsize;
f45584
f45584
	if (cctx->drvflags & MDSO_DRIVER_QUAD_PTR) {
f45584
		alignstr = "\t.balign   16\n\n";
f45584
		ptrsize  = ".quad";
f45584
	} else {
f45584
		alignstr = "\t.balign   8\n\n";
f45584
		ptrsize  = ".long";
f45584
	}
f45584
f45584
	for (line=asm_hdr_lines; *line; line++)
f45584
		if ((fprintf(fout,*line,cctx->libname)) < 0)
f45584
			return -1;
f45584
f45584
	if ((fputs(alignstr,fout)) < 0)
f45584
		return -1;
f45584
f45584
	if ((fprintf(fout,"\t%s\t%d\t# base\n",ptrsize,0)) < 0)
f45584
		return -1;
f45584
ce8ba9
	if ((fprintf(fout,"\t%s\t%u\t# flags\n",".long",cctx->dsoflags)) < 0)
f45584
		return -1;
f45584
f45584
	for (line=asm_meta_lines; *line; line++)
f45584
		if ((fprintf(fout,*line,ptrsize)) < 0)
f45584
			return -1;
f45584
f45584
	return 0;
f45584
}