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>
6e477a
f45584
#include <mdso/mdso.h>
f45584
#include <mdso/mdso_specs.h>
6e477a
#include "mdso_errinfo_impl.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(
6e477a
	const struct mdso_driver_ctx *	dctx,
f45584
	FILE *				fout)
f45584
{
f45584
	const char * const *	line;
f45584
	const char *		alignstr;
f45584
	const char *		ptrsize;
f45584
6e477a
	if (dctx->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++)
6e477a
		if ((fprintf(fout,*line,dctx->cctx->libname)) < 0)
6e477a
			return MDSO_FILE_ERROR(dctx);
f45584
f45584
	if ((fputs(alignstr,fout)) < 0)
6e477a
		return MDSO_FILE_ERROR(dctx);
f45584
643252
	if ((fprintf(fout,".__dsometa_%s:\n",dctx->cctx->libname)) < 0)
643252
		return MDSO_FILE_ERROR(dctx);
643252
f45584
	if ((fprintf(fout,"\t%s\t%d\t# base\n",ptrsize,0)) < 0)
6e477a
		return MDSO_FILE_ERROR(dctx);
f45584
6e477a
	if ((fprintf(fout,"\t%s\t%u\t# flags\n",".long",dctx->cctx->dsoflags)) < 0)
6e477a
		return MDSO_FILE_ERROR(dctx);
f45584
f45584
	for (line=asm_meta_lines; *line; line++)
f45584
		if ((fprintf(fout,*line,ptrsize)) < 0)
6e477a
			return MDSO_FILE_ERROR(dctx);
f45584
f45584
	return 0;
f45584
}