X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=ld%2Fdeffilep.y;h=706ad374d032519cbbb38ef369daa5e94450394d;hb=424908eba6008ba81a554c062a185f02c15bdc79;hp=45b1bda6f43a936f4cf6176eeeaae4d94e76ec52;hpb=4064c856436483cfa8f13114c208a1f4c3bd6e8e;p=deliverable%2Fbinutils-gdb.git diff --git a/ld/deffilep.y b/ld/deffilep.y index 45b1bda6f4..706ad374d0 100644 --- a/ld/deffilep.y +++ b/ld/deffilep.y @@ -1,13 +1,13 @@ %{ /* deffilep.y - parser for .def files */ -/* Copyright 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003 - Free Software Foundation, Inc. +/* Copyright 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, + 2007, 2009 Free Software Foundation, Inc. This file is part of GNU Binutils. 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,13 +17,13 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ -#include +#include "sysdep.h" #include "libiberty.h" #include "safe-ctype.h" #include "bfd.h" -#include "sysdep.h" #include "ld.h" #include "ldmisc.h" #include "deffile.h" @@ -78,24 +78,21 @@ #define yytable def_yytable #define yycheck def_yycheck -static void def_description PARAMS ((const char *)); -static void def_exports PARAMS ((const char *, const char *, int, int)); -static void def_heapsize PARAMS ((int, int)); -static void def_import PARAMS ((const char *, const char *, const char *, const char *, int)); -static void def_library PARAMS ((const char *, int)); -static def_file_module *def_stash_module PARAMS ((def_file *, const char *)); -static void def_name PARAMS ((const char *, int)); -static void def_section PARAMS ((const char *, int)); -static void def_section_alt PARAMS ((const char *, const char *)); -static void def_stacksize PARAMS ((int, int)); -static void def_version PARAMS ((int, int)); -static void def_directive PARAMS ((char *)); -static int def_parse PARAMS ((void)); -static int def_error PARAMS ((const char *)); -static void put_buf PARAMS ((char)); -static int def_getc PARAMS ((void)); -static int def_ungetc PARAMS ((int)); -static int def_lex PARAMS ((void)); +static void def_description (const char *); +static void def_exports (const char *, const char *, int, int); +static void def_heapsize (int, int); +static void def_import (const char *, const char *, const char *, const char *, + int); +static void def_image_name (const char *, int, int); +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 *); +static void def_aligncomm (char *str, int align); +static int def_parse (void); +static int def_error (const char *); +static int def_lex (void); static int lex_forced_token = 0; static const char *lex_parse_string = 0; @@ -106,17 +103,20 @@ static const char *lex_parse_string_end = 0; %union { char *id; int number; + char *digits; }; -%token NAME, LIBRARY, DESCRIPTION, STACKSIZE, HEAPSIZE, CODE, DATAU, DATAL -%token SECTIONS, EXPORTS, IMPORTS, VERSIONK, BASE, CONSTANTU, CONSTANTL -%token PRIVATEU, PRIVATEL +%token NAME LIBRARY DESCRIPTION STACKSIZE_K HEAPSIZE CODE DATAU DATAL +%token SECTIONS EXPORTS IMPORTS VERSIONK BASE CONSTANTU CONSTANTL +%token PRIVATEU PRIVATEL ALIGNCOMM %token READ WRITE EXECUTE SHARED NONAMEU NONAMEL DIRECTIVE %token ID -%token NUMBER +%token DIGITS +%type NUMBER +%type opt_digits %type opt_base opt_ordinal %type attr attr_list opt_number exp_opt_list exp_opt -%type opt_name opt_equal_name dot_name +%type opt_name opt_equal_name dot_name anylang_id opt_id %% @@ -125,10 +125,10 @@ start: start command ; command: - NAME opt_name opt_base { def_name ($2, $3); } - | LIBRARY opt_name opt_base { def_library ($2, $3); } + NAME opt_name opt_base { def_image_name ($2, $3, 0); } + | LIBRARY opt_name opt_base { def_image_name ($2, $3, 1); } | DESCRIPTION ID { def_description ($2);} - | STACKSIZE NUMBER opt_number { def_stacksize ($2, $3);} + | STACKSIZE_K NUMBER opt_number { def_stacksize ($2, $3);} | HEAPSIZE NUMBER opt_number { def_heapsize ($2, $3);} | CODE attr_list { def_section ("CODE", $2);} | DATAU attr_list { def_section ("DATA", $2);} @@ -138,6 +138,7 @@ command: | VERSIONK NUMBER { def_version ($2, 0);} | VERSIONK NUMBER '.' NUMBER { def_version ($2, $4);} | DIRECTIVE ID { def_directive ($2);} + | ALIGNCOMM anylang_id ',' NUMBER { def_aligncomm ($2, $4);} ; @@ -218,7 +219,7 @@ attr: opt_name: ID { $$ = $1; } | ID '.' ID { - char * name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1); + char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1); sprintf (name, "%s.%s", $1, $3); $$ = name; } @@ -242,12 +243,30 @@ opt_base: BASE '=' NUMBER { $$ = $3;} dot_name: ID { $$ = $1; } | dot_name '.' ID { - char * name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1); + char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1); sprintf (name, "%s.%s", $1, $3); $$ = name; } ; - + +anylang_id: ID { $$ = $1; } + | 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); } %% @@ -271,12 +290,12 @@ struct directive static struct directive *directives = 0; def_file * -def_file_empty () +def_file_empty (void) { - def_file *rv = (def_file *) xmalloc (sizeof (def_file)); + def_file *rv = xmalloc (sizeof (def_file)); memset (rv, 0, sizeof (def_file)); rv->is_dll = -1; - rv->base_address = (bfd_vma) (-1); + rv->base_address = (bfd_vma) -1; rv->stack_reserve = rv->stack_commit = -1; rv->heap_reserve = rv->heap_commit = -1; rv->version_major = rv->version_minor = -1; @@ -284,9 +303,7 @@ def_file_empty () } def_file * -def_file_parse (filename, add_to) - const char *filename; - def_file *add_to; +def_file_parse (const char *filename, def_file *add_to) { struct directive *d; @@ -329,8 +346,7 @@ def_file_parse (filename, add_to) } void -def_file_free (def) - def_file *def; +def_file_free (def_file *def) { int i; @@ -386,14 +402,20 @@ def_file_free (def) free (m); } + while (def->aligncomms) + { + def_file_aligncomm *c = def->aligncomms; + def->aligncomms = def->aligncomms->next; + free (c->symbol_name); + free (c); + } + free (def); } #ifdef DEF_FILE_PRINT void -def_file_print (file, def) - FILE *file; - def_file *def; +def_file_print (FILE *file, def_file *def) { int i; @@ -402,7 +424,7 @@ def_file_print (file, def) fprintf (file, " name: %s\n", def->name ? def->name : "(unspecified)"); if (def->is_dll != -1) fprintf (file, " is dll: %s\n", def->is_dll ? "yes" : "no"); - if (def->base_address != (bfd_vma) (-1)) + if (def->base_address != (bfd_vma) -1) fprintf (file, " base address: 0x%08x\n", def->base_address); if (def->description) fprintf (file, " description: `%s'\n", def->description); @@ -478,11 +500,10 @@ def_file_print (file, def) #endif def_file_export * -def_file_add_export (def, external_name, internal_name, ordinal) - def_file *def; - const char *external_name; - const char *internal_name; - int ordinal; +def_file_add_export (def_file *def, + const char *external_name, + const char *internal_name, + int ordinal) { def_file_export *e; int max_exports = ROUND_UP(def->num_exports, 32); @@ -491,11 +512,10 @@ def_file_add_export (def, external_name, internal_name, ordinal) { max_exports = ROUND_UP(def->num_exports + 1, 32); if (def->exports) - def->exports = (def_file_export *) - xrealloc (def->exports, max_exports * sizeof (def_file_export)); + def->exports = xrealloc (def->exports, + max_exports * sizeof (def_file_export)); else - def->exports = (def_file_export *) - xmalloc (max_exports * sizeof (def_file_export)); + def->exports = xmalloc (max_exports * sizeof (def_file_export)); } e = def->exports + def->num_exports; memset (e, 0, sizeof (def_file_export)); @@ -511,9 +531,7 @@ def_file_add_export (def, external_name, internal_name, ordinal) } def_file_module * -def_get_module (def, name) - def_file *def; - const char *name; +def_get_module (def_file *def, const char *name) { def_file_module *s; @@ -521,19 +539,17 @@ def_get_module (def, name) if (strcmp (s->name, name) == 0) return s; - return (def_file_module *) 0; + return NULL; } static def_file_module * -def_stash_module (def, name) - def_file *def; - const char *name; +def_stash_module (def_file *def, const char *name) { def_file_module *s; - if ((s = def_get_module (def, name)) != (def_file_module *) 0) + if ((s = def_get_module (def, name)) != NULL) return s; - s = (def_file_module *) xmalloc (sizeof (def_file_module) + strlen (name)); + s = xmalloc (sizeof (def_file_module) + strlen (name)); s->next = def->modules; def->modules = s; s->user_data = 0; @@ -542,26 +558,24 @@ def_stash_module (def, name) } def_file_import * -def_file_add_import (def, name, module, ordinal, internal_name) - def_file *def; - const char *name; - const char *module; - int ordinal; - const char *internal_name; +def_file_add_import (def_file *def, + const char *name, + const char *module, + int ordinal, + const char *internal_name) { def_file_import *i; - int max_imports = ROUND_UP(def->num_imports, 16); + int max_imports = ROUND_UP (def->num_imports, 16); if (def->num_imports >= max_imports) { - max_imports = ROUND_UP(def->num_imports+1, 16); + max_imports = ROUND_UP (def->num_imports+1, 16); if (def->imports) - def->imports = (def_file_import *) - xrealloc (def->imports, max_imports * sizeof (def_file_import)); + def->imports = xrealloc (def->imports, + max_imports * sizeof (def_file_import)); else - def->imports = (def_file_import *) - xmalloc (max_imports * sizeof (def_file_import)); + def->imports = xmalloc (max_imports * sizeof (def_file_import)); } i = def->imports + def->num_imports; memset (i, 0, sizeof (def_file_import)); @@ -587,32 +601,41 @@ struct diropts[] = { { "-heap", HEAPSIZE }, - { "-stack", STACKSIZE }, + { "-stack", STACKSIZE_K }, { "-attr", SECTIONS }, { "-export", EXPORTS }, + { "-aligncomm", ALIGNCOMM }, { 0, 0 } }; void -def_file_add_directive (my_def, param, len) - def_file *my_def; - const char *param; - int len; +def_file_add_directive (def_file *my_def, const char *param, int len) { def_file *save_def = def; const char *pend = param + len; - const char *tend = param; + char * tend = (char *) param; int i; def = my_def; while (param < pend) { - while (param < pend && ISSPACE (*param)) + while (param < pend + && (ISSPACE (*param) || *param == '\n' || *param == 0)) param++; - for (tend = param + 1; - tend < pend && !(ISSPACE (tend[-1]) && *tend == '-'); + 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); + (tend < pend + && !(ISSPACE (tend[-1]) && *tend == '-') + && *tend != '\n' && *tend != 0); tend++) ; @@ -628,15 +651,22 @@ def_file_add_directive (my_def, param, len) lex_parse_string = param + len + 1; lex_forced_token = diropts[i].token; saw_newline = 0; - def_parse (); + if (def_parse ()) + continue; break; } } if (!diropts[i].param) - /* xgettext:c-format */ - einfo (_("Warning: .drectve `%.*s' unrecognized\n"), - tend - param, param); + { + char saved; + + saved = * tend; + * tend = 0; + /* xgettext:c-format */ + einfo (_("Warning: .drectve `%s' unrecognized\n"), param); + * tend = saved; + } lex_parse_string = 0; param = tend; @@ -648,82 +678,83 @@ def_file_add_directive (my_def, param, len) /* Parser Callbacks. */ static void -def_name (name, base) - const char *name; - int base; +def_image_name (const char *name, int base, int is_dll) { - if (def->name) - free (def->name); - def->name = xstrdup (name); - def->base_address = base; - def->is_dll = 0; -} + /* 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); + 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"; -static void -def_library (name, base) - const char *name; - int base; -{ - if (def->name) - free (def->name); - def->name = xstrdup (name); + 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. */ def->base_address = base; - def->is_dll = 1; + def->is_dll = is_dll; } static void -def_description (text) - const char *text; +def_description (const char *text) { int len = def->description ? strlen (def->description) : 0; len += strlen (text) + 1; if (def->description) { - def->description = (char *) xrealloc (def->description, len); + def->description = xrealloc (def->description, len); strcat (def->description, text); } else { - def->description = (char *) xmalloc (len); + def->description = xmalloc (len); strcpy (def->description, text); } } static void -def_stacksize (reserve, commit) - int reserve; - int commit; +def_stacksize (int reserve, int commit) { def->stack_reserve = reserve; def->stack_commit = commit; } static void -def_heapsize (reserve, commit) - int reserve; - int commit; +def_heapsize (int reserve, int commit) { def->heap_reserve = reserve; def->heap_commit = commit; } static void -def_section (name, attr) - const char *name; - int attr; +def_section (const char *name, int attr) { def_file_section *s; - int max_sections = ROUND_UP(def->num_section_defs, 4); + int max_sections = ROUND_UP (def->num_section_defs, 4); if (def->num_section_defs >= max_sections) { - max_sections = ROUND_UP(def->num_section_defs+1, 4); + max_sections = ROUND_UP (def->num_section_defs+1, 4); if (def->section_defs) - def->section_defs = (def_file_section *) xrealloc (def->section_defs, max_sections * sizeof (def_file_import)); + def->section_defs = xrealloc (def->section_defs, + max_sections * sizeof (def_file_import)); else - def->section_defs = (def_file_section *) xmalloc (max_sections * sizeof (def_file_import)); + def->section_defs = xmalloc (max_sections * sizeof (def_file_import)); } s = def->section_defs + def->num_section_defs; memset (s, 0, sizeof (def_file_section)); @@ -741,9 +772,7 @@ def_section (name, attr) } static void -def_section_alt (name, attr) - const char *name; - const char *attr; +def_section_alt (const char *name, const char *attr) { int aval = 0; @@ -773,11 +802,10 @@ def_section_alt (name, attr) } static void -def_exports (external_name, internal_name, ordinal, flags) - const char *external_name; - const char *internal_name; - int ordinal; - int flags; +def_exports (const char *external_name, + const char *internal_name, + int ordinal, + int flags) { def_file_export *dfe; @@ -799,17 +827,16 @@ def_exports (external_name, internal_name, ordinal, flags) } static void -def_import (internal_name, module, dllext, name, ordinal) - const char *internal_name; - const char *module; - const char *dllext; - const char *name; - int ordinal; +def_import (const char *internal_name, + const char *module, + const char *dllext, + const char *name, + int ordinal) { char *buf = 0; const char *ext = dllext ? dllext : "dll"; - buf = (char *) xmalloc (strlen (module) + strlen (ext) + 2); + buf = xmalloc (strlen (module) + strlen (ext) + 2); sprintf (buf, "%s.%s", module, ext); module = buf; @@ -819,19 +846,16 @@ def_import (internal_name, module, dllext, name, ordinal) } static void -def_version (major, minor) - int major; - int minor; +def_version (int major, int minor) { def->version_major = major; def->version_minor = minor; } static void -def_directive (str) - char *str; +def_directive (char *str) { - struct directive *d = (struct directive *) xmalloc (sizeof (struct directive)); + struct directive *d = xmalloc (sizeof (struct directive)); d->next = directives; directives = d; @@ -839,12 +863,23 @@ def_directive (str) d->len = strlen (str); } -static int -def_error (err) - const char *err; +static void +def_aligncomm (char *str, int align) { - einfo ("%P: %s:%d: %s\n", def_filename, linenumber, err); + 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; +} + +static int +def_error (const char *err) +{ + einfo ("%P: %s:%d: %s\n", + def_filename ? def_filename : "", linenumber, err); return 0; } @@ -860,16 +895,15 @@ static int buflen = 0; static int bufptr = 0; static void -put_buf (c) - char c; +put_buf (char c) { if (bufptr == buflen) { buflen += 50; /* overly reasonable, eh? */ if (buffer) - buffer = (char *) xrealloc (buffer, buflen + 1); + buffer = xrealloc (buffer, buflen + 1); else - buffer = (char *) xmalloc (buflen + 1); + buffer = xmalloc (buflen + 1); } buffer[bufptr++] = c; buffer[bufptr] = 0; /* not optimal, but very convenient. */ @@ -904,14 +938,14 @@ tokens[] = { "SECTIONS", SECTIONS }, { "SEGMENTS", SECTIONS }, { "SHARED", SHARED }, - { "STACKSIZE", STACKSIZE }, + { "STACKSIZE", STACKSIZE_K }, { "VERSION", VERSIONK }, { "WRITE", WRITE }, { 0, 0 } }; static int -def_getc () +def_getc (void) { int rv; @@ -932,8 +966,7 @@ def_getc () } static int -def_ungetc (c) - int c; +def_ungetc (int c) { if (lex_parse_string) { @@ -945,7 +978,7 @@ def_ungetc (c) } static int -def_lex () +def_lex (void) { int c, i, q; @@ -998,11 +1031,11 @@ def_lex () } if (c != EOF) def_ungetc (c); - yylval.number = strtoul (buffer, 0, 0); + yylval.digits = xstrdup (buffer); #if TRACE - printf ("lex: `%s' returns NUMBER %d\n", buffer, yylval.number); + printf ("lex: `%s' returns DIGITS\n", buffer); #endif - return NUMBER; + return DIGITS; } if (ISALPHA (c) || strchr ("$:-_?@", c)) @@ -1026,7 +1059,7 @@ def_lex () #endif } - while (c != EOF && (ISALNUM (c) || strchr ("$:-_?/@", c))) + while (c != EOF && (ISALNUM (c) || strchr ("$:-_?/@<>", c))) { put_buf (c); c = def_getc ();