1999-05-03 15:29:11 +08:00
|
|
|
%{ /* deffilep.y - parser for .def files */
|
|
|
|
|
2009-09-02 15:25:43 +08:00
|
|
|
/* Copyright 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006,
|
|
|
|
2007, 2009 Free Software Foundation, Inc.
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2003-01-28 19:39:43 +08:00
|
|
|
This file is part of GNU Binutils.
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2003-01-28 19:39:43 +08:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-06 22:09:45 +08:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
2003-01-28 19:39:43 +08:00
|
|
|
(at your option) any later version.
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2003-01-28 19:39:43 +08:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2003-01-28 19:39:43 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2007-07-06 22:09:45 +08:00
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2007-04-26 22:47:00 +08:00
|
|
|
#include "sysdep.h"
|
1999-05-03 15:29:11 +08:00
|
|
|
#include "libiberty.h"
|
2001-09-19 13:33:36 +08:00
|
|
|
#include "safe-ctype.h"
|
1999-05-03 15:29:11 +08:00
|
|
|
#include "bfd.h"
|
|
|
|
#include "ld.h"
|
|
|
|
#include "ldmisc.h"
|
|
|
|
#include "deffile.h"
|
|
|
|
|
|
|
|
#define TRACE 0
|
|
|
|
|
|
|
|
#define ROUND_UP(a, b) (((a)+((b)-1))&~((b)-1))
|
|
|
|
|
|
|
|
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
|
|
|
|
as well as gratuitiously global symbol names, so we can have multiple
|
|
|
|
yacc generated parsers in ld. Note that these are only the variables
|
|
|
|
produced by yacc. If other parser generators (bison, byacc, etc) produce
|
|
|
|
additional global names that conflict at link time, then those parser
|
2003-01-28 19:39:43 +08:00
|
|
|
generators need to be fixed instead of adding those names to this list. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
#define yymaxdepth def_maxdepth
|
|
|
|
#define yyparse def_parse
|
|
|
|
#define yylex def_lex
|
|
|
|
#define yyerror def_error
|
|
|
|
#define yylval def_lval
|
|
|
|
#define yychar def_char
|
|
|
|
#define yydebug def_debug
|
|
|
|
#define yypact def_pact
|
|
|
|
#define yyr1 def_r1
|
|
|
|
#define yyr2 def_r2
|
|
|
|
#define yydef def_def
|
|
|
|
#define yychk def_chk
|
|
|
|
#define yypgo def_pgo
|
|
|
|
#define yyact def_act
|
|
|
|
#define yyexca def_exca
|
|
|
|
#define yyerrflag def_errflag
|
|
|
|
#define yynerrs def_nerrs
|
|
|
|
#define yyps def_ps
|
|
|
|
#define yypv def_pv
|
|
|
|
#define yys def_s
|
|
|
|
#define yy_yys def_yys
|
|
|
|
#define yystate def_state
|
|
|
|
#define yytmp def_tmp
|
|
|
|
#define yyv def_v
|
|
|
|
#define yy_yyv def_yyv
|
|
|
|
#define yyval def_val
|
|
|
|
#define yylloc def_lloc
|
2003-01-28 19:39:43 +08:00
|
|
|
#define yyreds def_reds /* With YYDEBUG defined. */
|
|
|
|
#define yytoks def_toks /* With YYDEBUG defined. */
|
1999-05-03 15:29:11 +08:00
|
|
|
#define yylhs def_yylhs
|
|
|
|
#define yylen def_yylen
|
|
|
|
#define yydefred def_yydefred
|
|
|
|
#define yydgoto def_yydgoto
|
|
|
|
#define yysindex def_yysindex
|
|
|
|
#define yyrindex def_yyrindex
|
|
|
|
#define yygindex def_yygindex
|
|
|
|
#define yytable def_yytable
|
|
|
|
#define yycheck def_yycheck
|
|
|
|
|
2003-06-28 13:28:54 +08:00
|
|
|
static void def_description (const char *);
|
2009-10-23 19:40:17 +08:00
|
|
|
static void def_exports (const char *, const char *, int, int, const char *);
|
2003-06-28 13:28:54 +08:00
|
|
|
static void def_heapsize (int, int);
|
|
|
|
static void def_import (const char *, const char *, const char *, const char *,
|
2009-10-23 19:40:17 +08:00
|
|
|
int, const char *);
|
2005-01-16 17:18:35 +08:00
|
|
|
static void def_image_name (const char *, int, int);
|
2003-06-28 13:28:54 +08:00
|
|
|
static void def_section (const char *, int);
|
|
|
|
static void def_section_alt (const char *, const char *);
|
|
|
|
static void def_stacksize (int, int);
|
|
|
|
static void def_version (int, int);
|
|
|
|
static void def_directive (char *);
|
2009-05-20 00:08:08 +08:00
|
|
|
static void def_aligncomm (char *str, int align);
|
2003-06-28 13:28:54 +08:00
|
|
|
static int def_parse (void);
|
|
|
|
static int def_error (const char *);
|
|
|
|
static int def_lex (void);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
static int lex_forced_token = 0;
|
|
|
|
static const char *lex_parse_string = 0;
|
|
|
|
static const char *lex_parse_string_end = 0;
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
%union {
|
|
|
|
char *id;
|
|
|
|
int number;
|
2009-05-28 02:40:56 +08:00
|
|
|
char *digits;
|
1999-05-03 15:29:11 +08:00
|
|
|
};
|
|
|
|
|
2009-04-29 09:17:54 +08:00
|
|
|
%token NAME LIBRARY DESCRIPTION STACKSIZE_K HEAPSIZE CODE DATAU DATAL
|
2003-10-19 23:21:31 +08:00
|
|
|
%token SECTIONS EXPORTS IMPORTS VERSIONK BASE CONSTANTU CONSTANTL
|
2009-05-20 00:08:08 +08:00
|
|
|
%token PRIVATEU PRIVATEL ALIGNCOMM
|
2009-10-23 19:40:17 +08:00
|
|
|
%token READ WRITE EXECUTE SHARED NONAMEU NONAMEL DIRECTIVE EQUAL
|
1999-05-03 15:29:11 +08:00
|
|
|
%token <id> ID
|
2009-05-28 02:40:56 +08:00
|
|
|
%token <digits> DIGITS
|
|
|
|
%type <number> NUMBER
|
|
|
|
%type <digits> opt_digits
|
1999-05-03 15:29:11 +08:00
|
|
|
%type <number> opt_base opt_ordinal
|
|
|
|
%type <number> attr attr_list opt_number exp_opt_list exp_opt
|
2009-05-28 02:40:56 +08:00
|
|
|
%type <id> opt_name opt_equal_name dot_name anylang_id opt_id
|
2009-10-23 19:40:17 +08:00
|
|
|
%type <id> opt_equalequal_name
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
start: start command
|
|
|
|
| command
|
|
|
|
;
|
|
|
|
|
|
|
|
command:
|
2005-01-16 17:18:35 +08:00
|
|
|
NAME opt_name opt_base { def_image_name ($2, $3, 0); }
|
|
|
|
| LIBRARY opt_name opt_base { def_image_name ($2, $3, 1); }
|
1999-05-03 15:29:11 +08:00
|
|
|
| DESCRIPTION ID { def_description ($2);}
|
2009-04-29 09:17:54 +08:00
|
|
|
| STACKSIZE_K NUMBER opt_number { def_stacksize ($2, $3);}
|
1999-05-03 15:29:11 +08:00
|
|
|
| HEAPSIZE NUMBER opt_number { def_heapsize ($2, $3);}
|
|
|
|
| CODE attr_list { def_section ("CODE", $2);}
|
1999-09-29 04:22:55 +08:00
|
|
|
| DATAU attr_list { def_section ("DATA", $2);}
|
1999-05-03 15:29:11 +08:00
|
|
|
| SECTIONS seclist
|
|
|
|
| EXPORTS explist
|
|
|
|
| IMPORTS implist
|
|
|
|
| VERSIONK NUMBER { def_version ($2, 0);}
|
|
|
|
| VERSIONK NUMBER '.' NUMBER { def_version ($2, $4);}
|
|
|
|
| DIRECTIVE ID { def_directive ($2);}
|
2009-05-28 02:40:56 +08:00
|
|
|
| ALIGNCOMM anylang_id ',' NUMBER { def_aligncomm ($2, $4);}
|
1999-05-03 15:29:11 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
explist:
|
|
|
|
/* EMPTY */
|
|
|
|
| expline
|
|
|
|
| explist expline
|
|
|
|
;
|
|
|
|
|
|
|
|
expline:
|
1999-09-29 04:22:55 +08:00
|
|
|
/* The opt_comma is necessary to support both the usual
|
|
|
|
DEF file syntax as well as .drectve syntax which
|
|
|
|
mandates <expsym>,<expoptlist>. */
|
2009-10-23 19:40:17 +08:00
|
|
|
dot_name opt_equal_name opt_ordinal opt_comma exp_opt_list opt_comma opt_equalequal_name
|
|
|
|
{ def_exports ($1, $2, $3, $5, $7); }
|
1999-05-03 15:29:11 +08:00
|
|
|
;
|
|
|
|
exp_opt_list:
|
1999-09-29 04:22:55 +08:00
|
|
|
/* The opt_comma is necessary to support both the usual
|
|
|
|
DEF file syntax as well as .drectve syntax which
|
|
|
|
allows for comma separated opt list. */
|
|
|
|
exp_opt opt_comma exp_opt_list { $$ = $1 | $3; }
|
1999-05-03 15:29:11 +08:00
|
|
|
| { $$ = 0; }
|
|
|
|
;
|
|
|
|
exp_opt:
|
1999-09-29 04:22:55 +08:00
|
|
|
NONAMEU { $$ = 1; }
|
|
|
|
| NONAMEL { $$ = 1; }
|
|
|
|
| CONSTANTU { $$ = 2; }
|
|
|
|
| CONSTANTL { $$ = 2; }
|
|
|
|
| DATAU { $$ = 4; }
|
|
|
|
| DATAL { $$ = 4; }
|
|
|
|
| PRIVATEU { $$ = 8; }
|
|
|
|
| PRIVATEL { $$ = 8; }
|
1999-05-03 15:29:11 +08:00
|
|
|
;
|
|
|
|
implist:
|
|
|
|
implist impline
|
|
|
|
| impline
|
|
|
|
;
|
|
|
|
|
|
|
|
impline:
|
2009-10-23 19:40:17 +08:00
|
|
|
ID '=' ID '.' ID '.' ID opt_equalequal_name
|
|
|
|
{ def_import ($1, $3, $5, $7, -1, $8); }
|
|
|
|
| ID '=' ID '.' ID '.' NUMBER opt_equalequal_name
|
|
|
|
{ def_import ($1, $3, $5, 0, $7, $8); }
|
|
|
|
| ID '=' ID '.' ID opt_equalequal_name
|
|
|
|
{ def_import ($1, $3, 0, $5, -1, $6); }
|
|
|
|
| ID '=' ID '.' NUMBER opt_equalequal_name
|
|
|
|
{ def_import ($1, $3, 0, 0, $5, $6); }
|
|
|
|
| ID '.' ID '.' ID opt_equalequal_name
|
|
|
|
{ def_import( 0, $1, $3, $5, -1, $6); }
|
|
|
|
| ID '.' ID opt_equalequal_name
|
|
|
|
{ def_import ( 0, $1, 0, $3, -1, $4); }
|
1999-05-03 15:29:11 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
seclist:
|
|
|
|
seclist secline
|
|
|
|
| secline
|
|
|
|
;
|
|
|
|
|
|
|
|
secline:
|
|
|
|
ID attr_list { def_section ($1, $2);}
|
|
|
|
| ID ID { def_section_alt ($1, $2);}
|
|
|
|
;
|
|
|
|
|
|
|
|
attr_list:
|
|
|
|
attr_list opt_comma attr { $$ = $1 | $3; }
|
|
|
|
| attr { $$ = $1; }
|
|
|
|
;
|
|
|
|
|
|
|
|
opt_comma:
|
|
|
|
','
|
|
|
|
|
|
|
|
|
;
|
|
|
|
opt_number: ',' NUMBER { $$=$2;}
|
|
|
|
| { $$=-1;}
|
|
|
|
;
|
|
|
|
|
|
|
|
attr:
|
|
|
|
READ { $$ = 1;}
|
|
|
|
| WRITE { $$ = 2;}
|
|
|
|
| EXECUTE { $$=4;}
|
|
|
|
| SHARED { $$=8;}
|
|
|
|
;
|
|
|
|
|
|
|
|
opt_name: ID { $$ = $1; }
|
2010-05-25 18:05:16 +08:00
|
|
|
| '.' ID
|
|
|
|
{
|
|
|
|
char *name = xmalloc (strlen ($2) + 2);
|
|
|
|
sprintf (name, ".%s", $2);
|
|
|
|
$$ = name;
|
|
|
|
}
|
2000-01-05 07:30:51 +08:00
|
|
|
| ID '.' ID
|
|
|
|
{
|
2003-06-28 13:28:54 +08:00
|
|
|
char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
|
2000-01-05 07:30:51 +08:00
|
|
|
sprintf (name, "%s.%s", $1, $3);
|
|
|
|
$$ = name;
|
|
|
|
}
|
|
|
|
| { $$ = ""; }
|
1999-05-03 15:29:11 +08:00
|
|
|
;
|
|
|
|
|
2009-10-23 19:40:17 +08:00
|
|
|
opt_equalequal_name: EQUAL ID { $$ = $2; }
|
|
|
|
| { $$ = 0; }
|
|
|
|
;
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
opt_ordinal:
|
|
|
|
'@' NUMBER { $$ = $2;}
|
|
|
|
| { $$ = -1;}
|
|
|
|
;
|
|
|
|
|
|
|
|
opt_equal_name:
|
2003-03-13 17:39:09 +08:00
|
|
|
'=' dot_name { $$ = $2; }
|
1999-05-03 15:29:11 +08:00
|
|
|
| { $$ = 0; }
|
|
|
|
;
|
|
|
|
|
|
|
|
opt_base: BASE '=' NUMBER { $$ = $3;}
|
2003-03-19 05:33:43 +08:00
|
|
|
| { $$ = -1;}
|
1999-05-03 15:29:11 +08:00
|
|
|
;
|
|
|
|
|
2003-03-13 17:39:09 +08:00
|
|
|
dot_name: ID { $$ = $1; }
|
2010-05-25 18:05:16 +08:00
|
|
|
| '.' ID
|
|
|
|
{
|
|
|
|
char *name = xmalloc (strlen ($2) + 2);
|
|
|
|
sprintf (name, ".%s", $2);
|
|
|
|
$$ = name;
|
|
|
|
}
|
2003-03-13 17:39:09 +08:00
|
|
|
| dot_name '.' ID
|
|
|
|
{
|
2003-06-28 13:28:54 +08:00
|
|
|
char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
|
2003-03-13 17:39:09 +08:00
|
|
|
sprintf (name, "%s.%s", $1, $3);
|
|
|
|
$$ = name;
|
|
|
|
}
|
|
|
|
;
|
2009-05-28 02:40:56 +08:00
|
|
|
|
|
|
|
anylang_id: ID { $$ = $1; }
|
2010-05-25 18:05:16 +08:00
|
|
|
| '.' ID
|
|
|
|
{
|
|
|
|
char *id = xmalloc (strlen ($2) + 2);
|
|
|
|
sprintf (id, ".%s", $2);
|
|
|
|
$$ = id;
|
|
|
|
}
|
2009-05-28 02:40:56 +08:00
|
|
|
| anylang_id '.' opt_digits opt_id
|
|
|
|
{
|
|
|
|
char *id = xmalloc (strlen ($1) + 1 + strlen ($3) + strlen ($4) + 1);
|
|
|
|
sprintf (id, "%s.%s%s", $1, $3, $4);
|
|
|
|
$$ = id;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
opt_digits: DIGITS { $$ = $1; }
|
|
|
|
| { $$ = ""; }
|
|
|
|
;
|
|
|
|
|
|
|
|
opt_id: ID { $$ = $1; }
|
|
|
|
| { $$ = ""; }
|
|
|
|
;
|
|
|
|
|
|
|
|
NUMBER: DIGITS { $$ = strtoul ($1, 0, 0); }
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
API
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
static FILE *the_file;
|
|
|
|
static const char *def_filename;
|
|
|
|
static int linenumber;
|
|
|
|
static def_file *def;
|
|
|
|
static int saw_newline;
|
|
|
|
|
|
|
|
struct directive
|
|
|
|
{
|
|
|
|
struct directive *next;
|
|
|
|
char *name;
|
|
|
|
int len;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct directive *directives = 0;
|
|
|
|
|
|
|
|
def_file *
|
2003-06-28 13:28:54 +08:00
|
|
|
def_file_empty (void)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2003-06-28 13:28:54 +08:00
|
|
|
def_file *rv = xmalloc (sizeof (def_file));
|
1999-05-03 15:29:11 +08:00
|
|
|
memset (rv, 0, sizeof (def_file));
|
|
|
|
rv->is_dll = -1;
|
2003-06-28 13:28:54 +08:00
|
|
|
rv->base_address = (bfd_vma) -1;
|
1999-05-03 15:29:11 +08:00
|
|
|
rv->stack_reserve = rv->stack_commit = -1;
|
|
|
|
rv->heap_reserve = rv->heap_commit = -1;
|
|
|
|
rv->version_major = rv->version_minor = -1;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
def_file *
|
2003-06-28 13:28:54 +08:00
|
|
|
def_file_parse (const char *filename, def_file *add_to)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
struct directive *d;
|
|
|
|
|
|
|
|
the_file = fopen (filename, "r");
|
|
|
|
def_filename = filename;
|
|
|
|
linenumber = 1;
|
|
|
|
if (!the_file)
|
|
|
|
{
|
|
|
|
perror (filename);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (add_to)
|
|
|
|
{
|
|
|
|
def = add_to;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
def = def_file_empty ();
|
|
|
|
}
|
|
|
|
|
|
|
|
saw_newline = 1;
|
|
|
|
if (def_parse ())
|
|
|
|
{
|
|
|
|
def_file_free (def);
|
|
|
|
fclose (the_file);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose (the_file);
|
|
|
|
|
|
|
|
for (d = directives; d; d = d->next)
|
|
|
|
{
|
|
|
|
#if TRACE
|
|
|
|
printf ("Adding directive %08x `%s'\n", d->name, d->name);
|
|
|
|
#endif
|
|
|
|
def_file_add_directive (def, d->name, d->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-11 21:42:17 +08:00
|
|
|
def_file_free (def_file *fdef)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
int i;
|
2003-01-28 19:39:43 +08:00
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
if (!fdef)
|
1999-05-03 15:29:11 +08:00
|
|
|
return;
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->name)
|
|
|
|
free (fdef->name);
|
|
|
|
if (fdef->description)
|
|
|
|
free (fdef->description);
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->section_defs)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2009-12-11 21:42:17 +08:00
|
|
|
for (i = 0; i < fdef->num_section_defs; i++)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->section_defs[i].name)
|
|
|
|
free (fdef->section_defs[i].name);
|
|
|
|
if (fdef->section_defs[i].class)
|
|
|
|
free (fdef->section_defs[i].class);
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
2009-12-11 21:42:17 +08:00
|
|
|
free (fdef->section_defs);
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->exports)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2009-12-18 03:33:59 +08:00
|
|
|
for (i = 0; i < fdef->num_exports; i++)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->exports[i].internal_name
|
|
|
|
&& fdef->exports[i].internal_name != fdef->exports[i].name)
|
|
|
|
free (fdef->exports[i].internal_name);
|
|
|
|
if (fdef->exports[i].name)
|
|
|
|
free (fdef->exports[i].name);
|
|
|
|
if (fdef->exports[i].its_name)
|
|
|
|
free (fdef->exports[i].its_name);
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
2009-12-11 21:42:17 +08:00
|
|
|
free (fdef->exports);
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->imports)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2009-12-11 21:42:17 +08:00
|
|
|
for (i = 0; i < fdef->num_imports; i++)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->imports[i].internal_name
|
|
|
|
&& fdef->imports[i].internal_name != fdef->imports[i].name)
|
|
|
|
free (fdef->imports[i].internal_name);
|
|
|
|
if (fdef->imports[i].name)
|
|
|
|
free (fdef->imports[i].name);
|
|
|
|
if (fdef->imports[i].its_name)
|
|
|
|
free (fdef->imports[i].its_name);
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
2009-12-11 21:42:17 +08:00
|
|
|
free (fdef->imports);
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
while (fdef->modules)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2009-12-11 21:42:17 +08:00
|
|
|
def_file_module *m = fdef->modules;
|
|
|
|
|
|
|
|
fdef->modules = fdef->modules->next;
|
1999-05-03 15:29:11 +08:00
|
|
|
free (m);
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
while (fdef->aligncomms)
|
2009-05-20 00:08:08 +08:00
|
|
|
{
|
2009-12-11 21:42:17 +08:00
|
|
|
def_file_aligncomm *c = fdef->aligncomms;
|
|
|
|
|
|
|
|
fdef->aligncomms = fdef->aligncomms->next;
|
2009-05-20 00:08:08 +08:00
|
|
|
free (c->symbol_name);
|
|
|
|
free (c);
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
free (fdef);
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEF_FILE_PRINT
|
|
|
|
void
|
2009-12-11 21:42:17 +08:00
|
|
|
def_file_print (FILE *file, def_file *fdef)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
int i;
|
2003-01-28 19:39:43 +08:00
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
fprintf (file, ">>>> def_file at 0x%08x\n", fdef);
|
|
|
|
if (fdef->name)
|
|
|
|
fprintf (file, " name: %s\n", fdef->name ? fdef->name : "(unspecified)");
|
|
|
|
if (fdef->is_dll != -1)
|
|
|
|
fprintf (file, " is dll: %s\n", fdef->is_dll ? "yes" : "no");
|
|
|
|
if (fdef->base_address != (bfd_vma) -1)
|
|
|
|
fprintf (file, " base address: 0x%08x\n", fdef->base_address);
|
|
|
|
if (fdef->description)
|
|
|
|
fprintf (file, " description: `%s'\n", fdef->description);
|
|
|
|
if (fdef->stack_reserve != -1)
|
|
|
|
fprintf (file, " stack reserve: 0x%08x\n", fdef->stack_reserve);
|
|
|
|
if (fdef->stack_commit != -1)
|
|
|
|
fprintf (file, " stack commit: 0x%08x\n", fdef->stack_commit);
|
|
|
|
if (fdef->heap_reserve != -1)
|
|
|
|
fprintf (file, " heap reserve: 0x%08x\n", fdef->heap_reserve);
|
|
|
|
if (fdef->heap_commit != -1)
|
|
|
|
fprintf (file, " heap commit: 0x%08x\n", fdef->heap_commit);
|
|
|
|
|
|
|
|
if (fdef->num_section_defs > 0)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
fprintf (file, " section defs:\n");
|
2003-01-28 19:39:43 +08:00
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
for (i = 0; i < fdef->num_section_defs; i++)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
fprintf (file, " name: `%s', class: `%s', flags:",
|
2009-12-11 21:42:17 +08:00
|
|
|
fdef->section_defs[i].name, fdef->section_defs[i].class);
|
|
|
|
if (fdef->section_defs[i].flag_read)
|
1999-05-03 15:29:11 +08:00
|
|
|
fprintf (file, " R");
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->section_defs[i].flag_write)
|
1999-05-03 15:29:11 +08:00
|
|
|
fprintf (file, " W");
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->section_defs[i].flag_execute)
|
1999-05-03 15:29:11 +08:00
|
|
|
fprintf (file, " X");
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->section_defs[i].flag_shared)
|
1999-05-03 15:29:11 +08:00
|
|
|
fprintf (file, " S");
|
|
|
|
fprintf (file, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->num_exports > 0)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
fprintf (file, " exports:\n");
|
2003-01-28 19:39:43 +08:00
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
for (i = 0; i < fdef->num_exports; i++)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
fprintf (file, " name: `%s', int: `%s', ordinal: %d, flags:",
|
2009-12-11 21:42:17 +08:00
|
|
|
fdef->exports[i].name, fdef->exports[i].internal_name,
|
|
|
|
fdef->exports[i].ordinal);
|
|
|
|
if (fdef->exports[i].flag_private)
|
1999-05-03 15:29:11 +08:00
|
|
|
fprintf (file, " P");
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->exports[i].flag_constant)
|
1999-05-03 15:29:11 +08:00
|
|
|
fprintf (file, " C");
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->exports[i].flag_noname)
|
1999-05-03 15:29:11 +08:00
|
|
|
fprintf (file, " N");
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->exports[i].flag_data)
|
1999-05-03 15:29:11 +08:00
|
|
|
fprintf (file, " D");
|
|
|
|
fprintf (file, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->num_imports > 0)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
fprintf (file, " imports:\n");
|
2003-01-28 19:39:43 +08:00
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
for (i = 0; i < fdef->num_imports; i++)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
fprintf (file, " int: %s, from: `%s', name: `%s', ordinal: %d\n",
|
2009-12-11 21:42:17 +08:00
|
|
|
fdef->imports[i].internal_name,
|
|
|
|
fdef->imports[i].module,
|
|
|
|
fdef->imports[i].name,
|
|
|
|
fdef->imports[i].ordinal);
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
}
|
2003-01-28 19:39:43 +08:00
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->version_major != -1)
|
|
|
|
fprintf (file, " version: %d.%d\n", fdef->version_major, fdef->version_minor);
|
2003-01-28 19:39:43 +08:00
|
|
|
|
2009-12-18 03:33:59 +08:00
|
|
|
fprintf (file, "<<<< def_file at 0x%08x\n", fdef);
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
def_file_export *
|
2009-12-11 21:42:17 +08:00
|
|
|
def_file_add_export (def_file *fdef,
|
2003-06-28 13:28:54 +08:00
|
|
|
const char *external_name,
|
|
|
|
const char *internal_name,
|
2009-10-23 19:40:17 +08:00
|
|
|
int ordinal,
|
|
|
|
const char *its_name)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
def_file_export *e;
|
2009-12-11 21:42:17 +08:00
|
|
|
int max_exports = ROUND_UP(fdef->num_exports, 32);
|
2003-01-28 19:39:43 +08:00
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->num_exports >= max_exports)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2009-12-11 21:42:17 +08:00
|
|
|
max_exports = ROUND_UP(fdef->num_exports + 1, 32);
|
|
|
|
if (fdef->exports)
|
|
|
|
fdef->exports = xrealloc (fdef->exports,
|
2003-06-28 13:28:54 +08:00
|
|
|
max_exports * sizeof (def_file_export));
|
1999-05-03 15:29:11 +08:00
|
|
|
else
|
2009-12-11 21:42:17 +08:00
|
|
|
fdef->exports = xmalloc (max_exports * sizeof (def_file_export));
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
2009-12-11 21:42:17 +08:00
|
|
|
e = fdef->exports + fdef->num_exports;
|
1999-05-03 15:29:11 +08:00
|
|
|
memset (e, 0, sizeof (def_file_export));
|
|
|
|
if (internal_name && !external_name)
|
|
|
|
external_name = internal_name;
|
|
|
|
if (external_name && !internal_name)
|
|
|
|
internal_name = external_name;
|
|
|
|
e->name = xstrdup (external_name);
|
|
|
|
e->internal_name = xstrdup (internal_name);
|
2009-10-23 19:40:17 +08:00
|
|
|
e->its_name = (its_name ? xstrdup (its_name) : NULL);
|
1999-05-03 15:29:11 +08:00
|
|
|
e->ordinal = ordinal;
|
2009-12-11 21:42:17 +08:00
|
|
|
fdef->num_exports++;
|
1999-05-03 15:29:11 +08:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2003-01-28 19:39:43 +08:00
|
|
|
def_file_module *
|
2009-12-11 21:42:17 +08:00
|
|
|
def_get_module (def_file *fdef, const char *name)
|
2003-01-28 19:39:43 +08:00
|
|
|
{
|
|
|
|
def_file_module *s;
|
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
for (s = fdef->modules; s; s = s->next)
|
2003-01-28 19:39:43 +08:00
|
|
|
if (strcmp (s->name, name) == 0)
|
|
|
|
return s;
|
|
|
|
|
2003-06-28 13:28:54 +08:00
|
|
|
return NULL;
|
2003-01-28 19:39:43 +08:00
|
|
|
}
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
static def_file_module *
|
2009-12-11 21:42:17 +08:00
|
|
|
def_stash_module (def_file *fdef, const char *name)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
def_file_module *s;
|
2003-01-28 19:39:43 +08:00
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
if ((s = def_get_module (fdef, name)) != NULL)
|
1999-05-03 15:29:11 +08:00
|
|
|
return s;
|
2003-06-28 13:28:54 +08:00
|
|
|
s = xmalloc (sizeof (def_file_module) + strlen (name));
|
2009-12-18 03:33:59 +08:00
|
|
|
s->next = fdef->modules;
|
2009-12-11 21:42:17 +08:00
|
|
|
fdef->modules = s;
|
1999-05-03 15:29:11 +08:00
|
|
|
s->user_data = 0;
|
|
|
|
strcpy (s->name, name);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
def_file_import *
|
2009-12-11 21:42:17 +08:00
|
|
|
def_file_add_import (def_file *fdef,
|
2003-06-28 13:28:54 +08:00
|
|
|
const char *name,
|
|
|
|
const char *module,
|
|
|
|
int ordinal,
|
2009-10-23 19:40:17 +08:00
|
|
|
const char *internal_name,
|
|
|
|
const char *its_name)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
def_file_import *i;
|
2009-12-11 21:42:17 +08:00
|
|
|
int max_imports = ROUND_UP (fdef->num_imports, 16);
|
2003-01-28 19:39:43 +08:00
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->num_imports >= max_imports)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2009-12-11 21:42:17 +08:00
|
|
|
max_imports = ROUND_UP (fdef->num_imports+1, 16);
|
2003-01-28 19:39:43 +08:00
|
|
|
|
2009-12-11 21:42:17 +08:00
|
|
|
if (fdef->imports)
|
|
|
|
fdef->imports = xrealloc (fdef->imports,
|
2003-06-28 13:28:54 +08:00
|
|
|
max_imports * sizeof (def_file_import));
|
1999-05-03 15:29:11 +08:00
|
|
|
else
|
2009-12-11 21:42:17 +08:00
|
|
|
fdef->imports = xmalloc (max_imports * sizeof (def_file_import));
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
2009-12-11 21:42:17 +08:00
|
|
|
i = fdef->imports + fdef->num_imports;
|
1999-05-03 15:29:11 +08:00
|
|
|
memset (i, 0, sizeof (def_file_import));
|
|
|
|
if (name)
|
|
|
|
i->name = xstrdup (name);
|
|
|
|
if (module)
|
2009-12-18 03:33:59 +08:00
|
|
|
i->module = def_stash_module (fdef, module);
|
1999-05-03 15:29:11 +08:00
|
|
|
i->ordinal = ordinal;
|
|
|
|
if (internal_name)
|
|
|
|
i->internal_name = xstrdup (internal_name);
|
|
|
|
else
|
|
|
|
i->internal_name = i->name;
|
2009-10-23 19:40:17 +08:00
|
|
|
i->its_name = (its_name ? xstrdup (its_name) : NULL);
|
2009-12-11 21:42:17 +08:00
|
|
|
fdef->num_imports++;
|
2003-01-28 19:39:43 +08:00
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
char *param;
|
|
|
|
int token;
|
|
|
|
}
|
|
|
|
diropts[] =
|
|
|
|
{
|
|
|
|
{ "-heap", HEAPSIZE },
|
2009-04-29 09:17:54 +08:00
|
|
|
{ "-stack", STACKSIZE_K },
|
1999-05-03 15:29:11 +08:00
|
|
|
{ "-attr", SECTIONS },
|
|
|
|
{ "-export", EXPORTS },
|
2009-05-20 00:08:08 +08:00
|
|
|
{ "-aligncomm", ALIGNCOMM },
|
1999-05-03 15:29:11 +08:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2003-06-28 13:28:54 +08:00
|
|
|
def_file_add_directive (def_file *my_def, const char *param, int len)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
def_file *save_def = def;
|
|
|
|
const char *pend = param + len;
|
2003-06-27 16:10:57 +08:00
|
|
|
char * tend = (char *) param;
|
1999-05-03 15:29:11 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
def = my_def;
|
|
|
|
|
|
|
|
while (param < pend)
|
|
|
|
{
|
2003-06-28 13:28:54 +08:00
|
|
|
while (param < pend
|
|
|
|
&& (ISSPACE (*param) || *param == '\n' || *param == 0))
|
1999-05-03 15:29:11 +08:00
|
|
|
param++;
|
2003-01-28 19:39:43 +08:00
|
|
|
|
2003-06-27 16:10:57 +08:00
|
|
|
if (param == pend)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Scan forward until we encounter any of:
|
|
|
|
- the end of the buffer
|
|
|
|
- the start of a new option
|
|
|
|
- a newline seperating options
|
|
|
|
- a NUL seperating options. */
|
|
|
|
for (tend = (char *) (param + 1);
|
2003-06-28 13:28:54 +08:00
|
|
|
(tend < pend
|
|
|
|
&& !(ISSPACE (tend[-1]) && *tend == '-')
|
|
|
|
&& *tend != '\n' && *tend != 0);
|
2003-01-28 19:39:43 +08:00
|
|
|
tend++)
|
|
|
|
;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
for (i = 0; diropts[i].param; i++)
|
|
|
|
{
|
2009-12-11 21:42:17 +08:00
|
|
|
len = strlen (diropts[i].param);
|
2003-01-28 19:39:43 +08:00
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
if (tend - param >= len
|
|
|
|
&& strncmp (param, diropts[i].param, len) == 0
|
|
|
|
&& (param[len] == ':' || param[len] == ' '))
|
|
|
|
{
|
|
|
|
lex_parse_string_end = tend;
|
|
|
|
lex_parse_string = param + len + 1;
|
|
|
|
lex_forced_token = diropts[i].token;
|
|
|
|
saw_newline = 0;
|
2003-06-27 16:10:57 +08:00
|
|
|
if (def_parse ())
|
|
|
|
continue;
|
1999-05-03 15:29:11 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!diropts[i].param)
|
2003-06-27 16:10:57 +08:00
|
|
|
{
|
|
|
|
char saved;
|
|
|
|
|
|
|
|
saved = * tend;
|
|
|
|
* tend = 0;
|
|
|
|
/* xgettext:c-format */
|
|
|
|
einfo (_("Warning: .drectve `%s' unrecognized\n"), param);
|
|
|
|
* tend = saved;
|
|
|
|
}
|
2003-01-28 19:39:43 +08:00
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
lex_parse_string = 0;
|
|
|
|
param = tend;
|
|
|
|
}
|
|
|
|
|
|
|
|
def = save_def;
|
|
|
|
}
|
|
|
|
|
2003-01-28 19:39:43 +08:00
|
|
|
/* Parser Callbacks. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
static void
|
2005-01-16 17:18:35 +08:00
|
|
|
def_image_name (const char *name, int base, int is_dll)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2006-04-01 12:51:23 +08:00
|
|
|
/* If a LIBRARY or NAME statement is specified without a name, there is nothing
|
|
|
|
to do here. We retain the output filename specified on command line. */
|
|
|
|
if (*name)
|
|
|
|
{
|
|
|
|
const char* image_name = lbasename (name);
|
2009-12-11 21:42:17 +08:00
|
|
|
|
2006-04-01 12:51:23 +08:00
|
|
|
if (image_name != name)
|
|
|
|
einfo ("%s:%d: Warning: path components stripped from %s, '%s'\n",
|
|
|
|
def_filename, linenumber, is_dll ? "LIBRARY" : "NAME",
|
|
|
|
name);
|
|
|
|
if (def->name)
|
|
|
|
free (def->name);
|
|
|
|
/* Append the default suffix, if none specified. */
|
|
|
|
if (strchr (image_name, '.') == 0)
|
|
|
|
{
|
|
|
|
const char * suffix = is_dll ? ".dll" : ".exe";
|
|
|
|
|
|
|
|
def->name = xmalloc (strlen (image_name) + strlen (suffix) + 1);
|
|
|
|
sprintf (def->name, "%s%s", image_name, suffix);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
def->name = xstrdup (image_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Honor a BASE address statement, even if LIBRARY string is empty. */
|
1999-05-03 15:29:11 +08:00
|
|
|
def->base_address = base;
|
2005-01-16 17:18:35 +08:00
|
|
|
def->is_dll = is_dll;
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-28 13:28:54 +08:00
|
|
|
def_description (const char *text)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
int len = def->description ? strlen (def->description) : 0;
|
2003-01-28 19:39:43 +08:00
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
len += strlen (text) + 1;
|
|
|
|
if (def->description)
|
|
|
|
{
|
2003-06-28 13:28:54 +08:00
|
|
|
def->description = xrealloc (def->description, len);
|
1999-05-03 15:29:11 +08:00
|
|
|
strcat (def->description, text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-06-28 13:28:54 +08:00
|
|
|
def->description = xmalloc (len);
|
1999-05-03 15:29:11 +08:00
|
|
|
strcpy (def->description, text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-28 13:28:54 +08:00
|
|
|
def_stacksize (int reserve, int commit)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
def->stack_reserve = reserve;
|
|
|
|
def->stack_commit = commit;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-28 13:28:54 +08:00
|
|
|
def_heapsize (int reserve, int commit)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
def->heap_reserve = reserve;
|
|
|
|
def->heap_commit = commit;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-28 13:28:54 +08:00
|
|
|
def_section (const char *name, int attr)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
def_file_section *s;
|
2003-06-28 13:28:54 +08:00
|
|
|
int max_sections = ROUND_UP (def->num_section_defs, 4);
|
2003-01-28 19:39:43 +08:00
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
if (def->num_section_defs >= max_sections)
|
|
|
|
{
|
2003-06-28 13:28:54 +08:00
|
|
|
max_sections = ROUND_UP (def->num_section_defs+1, 4);
|
2003-01-28 19:39:43 +08:00
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
if (def->section_defs)
|
2003-06-28 13:28:54 +08:00
|
|
|
def->section_defs = xrealloc (def->section_defs,
|
|
|
|
max_sections * sizeof (def_file_import));
|
1999-05-03 15:29:11 +08:00
|
|
|
else
|
2003-06-28 13:28:54 +08:00
|
|
|
def->section_defs = xmalloc (max_sections * sizeof (def_file_import));
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
s = def->section_defs + def->num_section_defs;
|
|
|
|
memset (s, 0, sizeof (def_file_section));
|
|
|
|
s->name = xstrdup (name);
|
|
|
|
if (attr & 1)
|
|
|
|
s->flag_read = 1;
|
|
|
|
if (attr & 2)
|
|
|
|
s->flag_write = 1;
|
|
|
|
if (attr & 4)
|
|
|
|
s->flag_execute = 1;
|
|
|
|
if (attr & 8)
|
|
|
|
s->flag_shared = 1;
|
|
|
|
|
|
|
|
def->num_section_defs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-28 13:28:54 +08:00
|
|
|
def_section_alt (const char *name, const char *attr)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
int aval = 0;
|
2003-01-28 19:39:43 +08:00
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
for (; *attr; attr++)
|
|
|
|
{
|
|
|
|
switch (*attr)
|
|
|
|
{
|
|
|
|
case 'R':
|
|
|
|
case 'r':
|
|
|
|
aval |= 1;
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
case 'w':
|
|
|
|
aval |= 2;
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
case 'x':
|
|
|
|
aval |= 4;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
case 's':
|
|
|
|
aval |= 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
def_section (name, aval);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-28 13:28:54 +08:00
|
|
|
def_exports (const char *external_name,
|
|
|
|
const char *internal_name,
|
|
|
|
int ordinal,
|
2009-10-23 19:40:17 +08:00
|
|
|
int flags,
|
|
|
|
const char *its_name)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
def_file_export *dfe;
|
|
|
|
|
|
|
|
if (!internal_name && external_name)
|
|
|
|
internal_name = external_name;
|
|
|
|
#if TRACE
|
|
|
|
printf ("def_exports, ext=%s int=%s\n", external_name, internal_name);
|
|
|
|
#endif
|
|
|
|
|
2009-10-23 19:40:17 +08:00
|
|
|
dfe = def_file_add_export (def, external_name, internal_name, ordinal,
|
|
|
|
its_name);
|
1999-05-03 15:29:11 +08:00
|
|
|
if (flags & 1)
|
|
|
|
dfe->flag_noname = 1;
|
|
|
|
if (flags & 2)
|
|
|
|
dfe->flag_constant = 1;
|
|
|
|
if (flags & 4)
|
|
|
|
dfe->flag_data = 1;
|
|
|
|
if (flags & 8)
|
|
|
|
dfe->flag_private = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-28 13:28:54 +08:00
|
|
|
def_import (const char *internal_name,
|
|
|
|
const char *module,
|
|
|
|
const char *dllext,
|
|
|
|
const char *name,
|
2009-10-23 19:40:17 +08:00
|
|
|
int ordinal,
|
|
|
|
const char *its_name)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
char *buf = 0;
|
2003-03-13 17:39:09 +08:00
|
|
|
const char *ext = dllext ? dllext : "dll";
|
|
|
|
|
2003-06-28 13:28:54 +08:00
|
|
|
buf = xmalloc (strlen (module) + strlen (ext) + 2);
|
2003-03-13 17:39:09 +08:00
|
|
|
sprintf (buf, "%s.%s", module, ext);
|
|
|
|
module = buf;
|
1999-05-03 15:29:11 +08:00
|
|
|
|
2009-10-23 19:40:17 +08:00
|
|
|
def_file_add_import (def, name, module, ordinal, internal_name, its_name);
|
1999-05-03 15:29:11 +08:00
|
|
|
if (buf)
|
|
|
|
free (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-28 13:28:54 +08:00
|
|
|
def_version (int major, int minor)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
def->version_major = major;
|
|
|
|
def->version_minor = minor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-28 13:28:54 +08:00
|
|
|
def_directive (char *str)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2003-06-28 13:28:54 +08:00
|
|
|
struct directive *d = xmalloc (sizeof (struct directive));
|
2003-01-28 19:39:43 +08:00
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
d->next = directives;
|
|
|
|
directives = d;
|
|
|
|
d->name = xstrdup (str);
|
|
|
|
d->len = strlen (str);
|
|
|
|
}
|
|
|
|
|
2009-05-20 00:08:08 +08:00
|
|
|
static void
|
|
|
|
def_aligncomm (char *str, int align)
|
|
|
|
{
|
|
|
|
def_file_aligncomm *c = xmalloc (sizeof (def_file_aligncomm));
|
|
|
|
|
|
|
|
c->symbol_name = xstrdup (str);
|
|
|
|
c->alignment = (unsigned int) align;
|
|
|
|
|
|
|
|
c->next = def->aligncomms;
|
|
|
|
def->aligncomms = c;
|
|
|
|
}
|
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
static int
|
2003-06-28 13:28:54 +08:00
|
|
|
def_error (const char *err)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
2003-06-28 13:28:54 +08:00
|
|
|
einfo ("%P: %s:%d: %s\n",
|
|
|
|
def_filename ? def_filename : "<unknown-file>", linenumber, err);
|
1999-05-03 15:29:11 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-28 19:39:43 +08:00
|
|
|
/* Lexical Scanner. */
|
1999-05-03 15:29:11 +08:00
|
|
|
|
|
|
|
#undef TRACE
|
|
|
|
#define TRACE 0
|
|
|
|
|
2003-01-28 19:39:43 +08:00
|
|
|
/* Never freed, but always reused as needed, so no real leak. */
|
1999-05-03 15:29:11 +08:00
|
|
|
static char *buffer = 0;
|
|
|
|
static int buflen = 0;
|
|
|
|
static int bufptr = 0;
|
|
|
|
|
|
|
|
static void
|
2003-06-28 13:28:54 +08:00
|
|
|
put_buf (char c)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
if (bufptr == buflen)
|
|
|
|
{
|
2003-01-28 19:39:43 +08:00
|
|
|
buflen += 50; /* overly reasonable, eh? */
|
1999-05-03 15:29:11 +08:00
|
|
|
if (buffer)
|
2003-06-28 13:28:54 +08:00
|
|
|
buffer = xrealloc (buffer, buflen + 1);
|
1999-05-03 15:29:11 +08:00
|
|
|
else
|
2003-06-28 13:28:54 +08:00
|
|
|
buffer = xmalloc (buflen + 1);
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
buffer[bufptr++] = c;
|
2003-01-28 19:39:43 +08:00
|
|
|
buffer[bufptr] = 0; /* not optimal, but very convenient. */
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
int token;
|
|
|
|
}
|
|
|
|
tokens[] =
|
|
|
|
{
|
|
|
|
{ "BASE", BASE },
|
|
|
|
{ "CODE", CODE },
|
1999-09-29 04:22:55 +08:00
|
|
|
{ "CONSTANT", CONSTANTU },
|
|
|
|
{ "constant", CONSTANTL },
|
|
|
|
{ "DATA", DATAU },
|
|
|
|
{ "data", DATAL },
|
1999-05-03 15:29:11 +08:00
|
|
|
{ "DESCRIPTION", DESCRIPTION },
|
|
|
|
{ "DIRECTIVE", DIRECTIVE },
|
|
|
|
{ "EXECUTE", EXECUTE },
|
|
|
|
{ "EXPORTS", EXPORTS },
|
|
|
|
{ "HEAPSIZE", HEAPSIZE },
|
|
|
|
{ "IMPORTS", IMPORTS },
|
|
|
|
{ "LIBRARY", LIBRARY },
|
|
|
|
{ "NAME", NAME },
|
1999-09-29 04:22:55 +08:00
|
|
|
{ "NONAME", NONAMEU },
|
|
|
|
{ "noname", NONAMEL },
|
|
|
|
{ "PRIVATE", PRIVATEU },
|
|
|
|
{ "private", PRIVATEL },
|
1999-05-03 15:29:11 +08:00
|
|
|
{ "READ", READ },
|
|
|
|
{ "SECTIONS", SECTIONS },
|
|
|
|
{ "SEGMENTS", SECTIONS },
|
|
|
|
{ "SHARED", SHARED },
|
2009-04-29 09:17:54 +08:00
|
|
|
{ "STACKSIZE", STACKSIZE_K },
|
1999-05-03 15:29:11 +08:00
|
|
|
{ "VERSION", VERSIONK },
|
|
|
|
{ "WRITE", WRITE },
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2003-06-28 13:28:54 +08:00
|
|
|
def_getc (void)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
int rv;
|
2003-01-28 19:39:43 +08:00
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
if (lex_parse_string)
|
|
|
|
{
|
|
|
|
if (lex_parse_string >= lex_parse_string_end)
|
|
|
|
rv = EOF;
|
|
|
|
else
|
|
|
|
rv = *lex_parse_string++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rv = fgetc (the_file);
|
|
|
|
}
|
|
|
|
if (rv == '\n')
|
|
|
|
saw_newline = 1;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-06-28 13:28:54 +08:00
|
|
|
def_ungetc (int c)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
if (lex_parse_string)
|
|
|
|
{
|
|
|
|
lex_parse_string--;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ungetc (c, the_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-06-28 13:28:54 +08:00
|
|
|
def_lex (void)
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
int c, i, q;
|
|
|
|
|
|
|
|
if (lex_forced_token)
|
|
|
|
{
|
|
|
|
i = lex_forced_token;
|
|
|
|
lex_forced_token = 0;
|
|
|
|
#if TRACE
|
|
|
|
printf ("lex: forcing token %d\n", i);
|
|
|
|
#endif
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
c = def_getc ();
|
|
|
|
|
2003-01-28 19:39:43 +08:00
|
|
|
/* Trim leading whitespace. */
|
1999-05-03 15:29:11 +08:00
|
|
|
while (c != EOF && (c == ' ' || c == '\t') && saw_newline)
|
|
|
|
c = def_getc ();
|
|
|
|
|
|
|
|
if (c == EOF)
|
|
|
|
{
|
|
|
|
#if TRACE
|
|
|
|
printf ("lex: EOF\n");
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (saw_newline && c == ';')
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c = def_getc ();
|
|
|
|
}
|
|
|
|
while (c != EOF && c != '\n');
|
|
|
|
if (c == '\n')
|
|
|
|
return def_lex ();
|
|
|
|
return 0;
|
|
|
|
}
|
2003-01-28 19:39:43 +08:00
|
|
|
|
|
|
|
/* Must be something else. */
|
1999-05-03 15:29:11 +08:00
|
|
|
saw_newline = 0;
|
|
|
|
|
2001-09-19 13:33:36 +08:00
|
|
|
if (ISDIGIT (c))
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
bufptr = 0;
|
2001-09-19 13:33:36 +08:00
|
|
|
while (c != EOF && (ISXDIGIT (c) || (c == 'x')))
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
put_buf (c);
|
|
|
|
c = def_getc ();
|
|
|
|
}
|
|
|
|
if (c != EOF)
|
|
|
|
def_ungetc (c);
|
2009-05-28 02:40:56 +08:00
|
|
|
yylval.digits = xstrdup (buffer);
|
1999-05-03 15:29:11 +08:00
|
|
|
#if TRACE
|
2009-05-28 02:40:56 +08:00
|
|
|
printf ("lex: `%s' returns DIGITS\n", buffer);
|
1999-05-03 15:29:11 +08:00
|
|
|
#endif
|
2009-05-28 02:40:56 +08:00
|
|
|
return DIGITS;
|
1999-05-03 15:29:11 +08:00
|
|
|
}
|
|
|
|
|
2002-11-07 03:36:20 +08:00
|
|
|
if (ISALPHA (c) || strchr ("$:-_?@", c))
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
bufptr = 0;
|
2002-11-07 03:36:20 +08:00
|
|
|
q = c;
|
|
|
|
put_buf (c);
|
|
|
|
c = def_getc ();
|
|
|
|
|
|
|
|
if (q == '@')
|
|
|
|
{
|
|
|
|
if (ISBLANK (c) ) /* '@' followed by whitespace. */
|
|
|
|
return (q);
|
|
|
|
else if (ISDIGIT (c)) /* '@' followed by digit. */
|
|
|
|
{
|
|
|
|
def_ungetc (c);
|
|
|
|
return (q);
|
|
|
|
}
|
|
|
|
#if TRACE
|
|
|
|
printf ("lex: @ returns itself\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-10-23 19:33:44 +08:00
|
|
|
while (c != EOF && (ISALNUM (c) || strchr ("$:-_?/@<>", c)))
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
put_buf (c);
|
|
|
|
c = def_getc ();
|
|
|
|
}
|
|
|
|
if (c != EOF)
|
|
|
|
def_ungetc (c);
|
2002-11-07 03:36:20 +08:00
|
|
|
if (ISALPHA (q)) /* Check for tokens. */
|
|
|
|
{
|
|
|
|
for (i = 0; tokens[i].name; i++)
|
|
|
|
if (strcmp (tokens[i].name, buffer) == 0)
|
|
|
|
{
|
1999-05-03 15:29:11 +08:00
|
|
|
#if TRACE
|
2002-11-07 03:36:20 +08:00
|
|
|
printf ("lex: `%s' is a string token\n", buffer);
|
1999-05-03 15:29:11 +08:00
|
|
|
#endif
|
2002-11-07 03:36:20 +08:00
|
|
|
return tokens[i].token;
|
|
|
|
}
|
|
|
|
}
|
1999-05-03 15:29:11 +08:00
|
|
|
#if TRACE
|
|
|
|
printf ("lex: `%s' returns ID\n", buffer);
|
|
|
|
#endif
|
|
|
|
yylval.id = xstrdup (buffer);
|
|
|
|
return ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '\'' || c == '"')
|
|
|
|
{
|
|
|
|
q = c;
|
|
|
|
c = def_getc ();
|
|
|
|
bufptr = 0;
|
2003-01-28 19:39:43 +08:00
|
|
|
|
1999-05-03 15:29:11 +08:00
|
|
|
while (c != EOF && c != q)
|
|
|
|
{
|
|
|
|
put_buf (c);
|
|
|
|
c = def_getc ();
|
|
|
|
}
|
|
|
|
yylval.id = xstrdup (buffer);
|
|
|
|
#if TRACE
|
|
|
|
printf ("lex: `%s' returns ID\n", buffer);
|
|
|
|
#endif
|
|
|
|
return ID;
|
|
|
|
}
|
|
|
|
|
2009-10-23 19:40:17 +08:00
|
|
|
if ( c == '=')
|
|
|
|
{
|
|
|
|
c = def_getc ();
|
|
|
|
if (c == '=')
|
|
|
|
{
|
|
|
|
#if TRACE
|
|
|
|
printf ("lex: `==' returns EQUAL\n");
|
|
|
|
#endif
|
|
|
|
return EQUAL;
|
|
|
|
}
|
|
|
|
def_ungetc (c);
|
|
|
|
#if TRACE
|
|
|
|
printf ("lex: `=' returns itself\n");
|
|
|
|
#endif
|
|
|
|
return '=';
|
|
|
|
}
|
|
|
|
if (c == '.' || c == ',')
|
1999-05-03 15:29:11 +08:00
|
|
|
{
|
|
|
|
#if TRACE
|
|
|
|
printf ("lex: `%c' returns itself\n", c);
|
|
|
|
#endif
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == '\n')
|
|
|
|
{
|
|
|
|
linenumber++;
|
|
|
|
saw_newline = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*printf ("lex: 0x%02x ignored\n", c); */
|
|
|
|
return def_lex ();
|
|
|
|
}
|