ofmt: Alias shortname must be used for __OUTPUT_FORMAT__ macro

__OUTPUT_FORMAT__ must consist of shortname of output format
or its alias, otherwise userspace ABI gets broken.

For example source code still can refer to __OUTPUT_FORMAT__=elf,
instead of __OUTPUT_FORMAT__=elf32.

BR3246990

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov 2011-04-06 18:32:15 +04:00
parent f2536e10a0
commit c1936da942
4 changed files with 29 additions and 14 deletions

12
nasm.c
View File

@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2010 The NASM Authors - All Rights Reserved
* Copyright 1996-2011 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@ -98,6 +98,7 @@ static char errname[FILENAME_MAX];
static int globallineno; /* for forward-reference tracking */
/* static int pass = 0; */
struct ofmt *ofmt = &OF_DEFAULT;
struct ofmt_alias *ofmt_alias = NULL;
const struct dfmt *dfmt;
static FILE *error_file; /* Where to write error messages */
@ -268,8 +269,13 @@ static void define_macros_late(void)
{
char temp[128];
/*
* In case if output format is defined by alias
* we have to put shortname of the alias itself here
* otherwise ABI backward compatibility gets broken.
*/
snprintf(temp, sizeof(temp), "__OUTPUT_FORMAT__=%s",
ofmt->shortname);
ofmt_alias ? ofmt_alias->shortname : ofmt->shortname);
pp_pre_define(temp);
}
@ -652,7 +658,7 @@ static bool process_arg(char *p, char *q)
break;
case 'f': /* output format */
ofmt = ofmt_find(param);
ofmt = ofmt_find(param, &ofmt_alias);
if (!ofmt) {
nasm_error(ERR_FATAL | ERR_NOFILE | ERR_USAGE,
"unrecognised output format `%s' - "

11
nasm.h
View File

@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2009 The NASM Authors - All Rights Reserved
* Copyright 1996-2011 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@ -754,6 +754,15 @@ struct ofmt {
void (*cleanup) (int debuginfo);
};
/*
* Output format driver alias
*/
struct ofmt_alias {
const char *shortname;
const char *fullname;
struct ofmt *ofmt;
};
extern struct ofmt *ofmt;
extern FILE *ofile;

View File

@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2009 The NASM Authors - All Rights Reserved
* Copyright 1996-2011 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@ -47,11 +47,13 @@
#define BUILD_DRIVERS_ARRAY
#include "output/outform.h"
struct ofmt *ofmt_find(char *name)
struct ofmt *ofmt_find(char *name, struct ofmt_alias **ofmt_alias)
{
struct ofmt **ofp, *of;
unsigned int i;
*ofmt_alias = NULL;
/* primary targets first */
for (ofp = drivers; (of = *ofp); ofp++) {
if (!nasm_stricmp(name, of->shortname))
@ -61,8 +63,10 @@ struct ofmt *ofmt_find(char *name)
/* lets walk thru aliases then */
for (i = 0; i < ARRAY_SIZE(ofmt_aliases); i++) {
if (ofmt_aliases[i].shortname &&
!nasm_stricmp(name, ofmt_aliases[i].shortname))
!nasm_stricmp(name, ofmt_aliases[i].shortname)) {
*ofmt_alias = &ofmt_aliases[i];
return ofmt_aliases[i].ofmt;
}
}
return NULL;

View File

@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2009 The NASM Authors - All Rights Reserved
* Copyright 1996-2011 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@ -330,11 +330,7 @@ static struct ofmt *drivers[] = {
NULL
};
static struct ofmt_alias {
const char *shortname;
const char *fullname;
struct ofmt *ofmt;
} ofmt_aliases[] = {
static struct ofmt_alias ofmt_aliases[] = {
#ifdef OF_ELF32
{
"elf",
@ -361,7 +357,7 @@ static struct ofmt_alias {
#endif /* BUILD_DRIVERS_ARRAY */
struct ofmt *ofmt_find(char *);
struct ofmt *ofmt_find(char *name, struct ofmt_alias **ofmt_alias);
struct dfmt *dfmt_find(struct ofmt *, char *);
void ofmt_list(struct ofmt *, FILE *);
void dfmt_list(struct ofmt *ofmt, FILE * fp);