ofmt: Introduce output format aliases

This allow us to keep compatibility layer without
needing the separated struct ofmt for this and
elf_init_hack routine.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov 2010-04-09 15:12:13 +04:00
parent f134cc63da
commit 6837749d85
4 changed files with 54 additions and 57 deletions

View File

@ -122,7 +122,6 @@ static uint8_t elf_osabi = 0; /* Default OSABI = 0 (System V or Linux) */
static uint8_t elf_abiver = 0; /* Current ABI version */
extern struct ofmt of_elf32;
extern struct ofmt of_elf;
static struct ELF_SECTDATA {
void *data;
@ -266,12 +265,6 @@ static void elf_init(void)
def_seg = seg_alloc();
}
static void elf_init_hack(void)
{
of_elf32.current_dfmt = of_elf.current_dfmt; /* Sync debugging format */
elf_init();
}
static void elf_cleanup(int debuginfo)
{
struct Reloc *r;
@ -1414,23 +1407,6 @@ struct ofmt of_elf32 = {
elf_cleanup
};
struct ofmt of_elf = {
"ELF (short name for ELF32) ",
"elf",
0,
elf32_debugs_arr,
&df_stabs,
elf_stdmac,
elf_init_hack,
elf_set_info,
elf_out,
elf_deflabel,
elf_section_names,
elf_segbase,
elf_directive,
elf_filename,
elf_cleanup
};
/* again, the stabs debugging stuff (code) */
static void stabs32_linenum(const char *filename, int32_t linenumber,

View File

@ -48,18 +48,28 @@
#include "output/outform.h"
struct ofmt *ofmt_find(char *name)
{ /* find driver */
{
struct ofmt **ofp, *of;
unsigned int i;
/* primary targets first */
for (ofp = drivers; (of = *ofp); ofp++) {
if (!nasm_stricmp(name, of->shortname))
return of;
}
/* lets walk thru aliases then */
for (i = 0; i < elements(ofmt_aliases); i++) {
if (ofmt_aliases[i].shortname &&
!nasm_stricmp(name, ofmt_aliases[i].shortname))
return ofmt_aliases[i].ofmt;
}
return NULL;
}
struct dfmt *dfmt_find(struct ofmt *ofmt, char *name)
{ /* find driver */
{
struct dfmt **dfp, *df;
for (dfp = ofmt->debug_formats; (df = *dfp); dfp++) {
@ -72,12 +82,23 @@ struct dfmt *dfmt_find(struct ofmt *ofmt, char *name)
void ofmt_list(struct ofmt *deffmt, FILE * fp)
{
struct ofmt **ofp, *of;
unsigned int i;
/* primary targets first */
for (ofp = drivers; (of = *ofp); ofp++) {
fprintf(fp, " %c %-10s%s\n",
of == deffmt ? '*' : ' ',
of->shortname, of->fullname);
}
/* lets walk through aliases then */
for (i = 0; i < elements(ofmt_aliases); i++) {
if (!ofmt_aliases[i].shortname)
continue;
fprintf(fp, " %-10s%s\n",
ofmt_aliases[i].shortname,
ofmt_aliases[i].fullname);
}
}
void dfmt_list(struct ofmt *ofmt, FILE *fp)

View File

@ -1,5 +1,5 @@
/* ----------------------------------------------------------------------- *
*
*
* Copyright 1996-2009 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
@ -14,7 +14,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@ -153,7 +153,7 @@
#define OF_BIN
#endif
#ifndef OF_COFF
#define OF_COFF /* COFF is used by DJGPP */
#define OF_COFF /* COFF is used by DJGPP */
#endif
#ifndef OF_WIN32
#define OF_WIN32
@ -260,7 +260,6 @@ extern struct ofmt of_aout;
extern struct ofmt of_aoutb;
extern struct ofmt of_coff;
extern struct ofmt of_elf32;
extern struct ofmt of_elf;
extern struct ofmt of_elf64;
extern struct ofmt of_as86;
extern struct ofmt of_obj;
@ -269,14 +268,15 @@ extern struct ofmt of_win64;
extern struct ofmt of_rdf2;
extern struct ofmt of_ieee;
extern struct ofmt of_macho32;
extern struct ofmt of_macho;
extern struct ofmt of_macho64;
extern struct ofmt of_dbg;
#ifdef BUILD_DRIVERS_ARRAY /* only if included from outform.c */
/* pull in the externs for the different formats, then make the *drivers
* array based on the above defines */
/*
* pull in the externs for the different formats, then make the
* drivers array based on the above defines
*/
static struct ofmt *drivers[] = {
#ifdef OF_BIN
@ -295,7 +295,6 @@ static struct ofmt *drivers[] = {
#endif
#ifdef OF_ELF32
&of_elf32,
&of_elf,
#endif
#ifdef OF_ELF64
&of_elf64,
@ -320,7 +319,6 @@ static struct ofmt *drivers[] = {
#endif
#ifdef OF_MACHO32
&of_macho32,
&of_macho,
#endif
#ifdef OF_MACHO64
&of_macho64,
@ -332,7 +330,29 @@ static struct ofmt *drivers[] = {
NULL
};
#endif /* BUILD_DRIVERS_ARRAY */
static struct ofmt_alias {
const char *shortname;
const char *fullname;
struct ofmt *ofmt;
} ofmt_aliases[] = {
#ifdef OF_ELF32
{
"elf",
"ELF (short name for ELF32)",
&of_elf32,
},
#endif
#ifdef OF_MACHO32
{
"macho",
"MACHO (short name for MACHO32)",
&of_macho32,
},
#endif
{ NULL, NULL, NULL }
};
#endif /* BUILD_DRIVERS_ARRAY */
struct ofmt *ofmt_find(char *);
struct dfmt *dfmt_find(struct ofmt *, char *);
@ -341,4 +361,4 @@ void dfmt_list(struct ofmt *ofmt, FILE * fp);
struct ofmt *ofmt_register(efunc error);
extern struct dfmt null_debug_form;
#endif /* NASM_OUTFORM_H */
#endif /* NASM_OUTFORM_H */

View File

@ -208,8 +208,6 @@ static struct RAA *extsyms;
static struct SAA *strs;
static uint32_t strslen;
extern struct ofmt of_macho;
/* Global file information. This should be cleaned up into either
a structure or as function arguments. */
uint32_t head_ncmds = 0;
@ -1325,24 +1323,6 @@ struct ofmt of_macho32 = {
macho_cleanup
};
struct ofmt of_macho = {
"MACHO (short name for MACHO32)",
"macho",
0,
null_debug_arr,
&null_debug_form,
macho_stdmac,
macho_init,
null_setinfo,
macho_output,
macho_symdef,
macho_section,
macho_segbase,
null_directive,
macho_filename,
macho_cleanup
};
#endif
/*