aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorKai Tietz <kai.tietz@onevision.com>2009-10-23 14:53:57 +0000
committerKai Tietz <kai.tietz@onevision.com>2009-10-23 14:53:57 +0000
commitbf201fddaaaae8fbd048f6d58b315080f5069b9f (patch)
tree61af7147e3b585fbd897a63f51be9cd3b6055107 /binutils
parent6a0fa04300e300a1df9cc137f868a91be3854225 (diff)
downloadgdb-bf201fddaaaae8fbd048f6d58b315080f5069b9f.zip
gdb-bf201fddaaaae8fbd048f6d58b315080f5069b9f.tar.gz
gdb-bf201fddaaaae8fbd048f6d58b315080f5069b9f.tar.bz2
2009-10-23 Kai Tietz <kai.tietz@onevision.com>
* deflex.l: Allow '<' and '>' in ID names. * defparse.y (EQUAL): New token constant. (opt_import_name): New rule for emptry or '==' ID. (expline): Add opt_import_name as last line element. (impline): Likewise. * dlltool.c (ifunct): New member its_name. (export): Likewise. (append_import): Add its_name argument. (defexports): Likewise. (defimport): Likewise. (scan_drectve_symbols): Adjust calls to def_exports. (dump_def_info): Print new optinal import/export table symbol name. (generate_idata_ofile): Use its_name member. (make_one_lib_file): Likewise. (nfunc): Take its_name in account on sort. * dlltool.h (def_exports): Add its_name as argument. (def_import): Likewise. * doc/binutils.texi: Add new def file syntax extension. * deflex.l (EQUAL): Add rule for '=='. * NEWS: Mention new feature. 2009-10-23 Kai Tietz <kai.tietz@onevision.com> * binutils-all/dlltool.exp: Add new test. * binutils-all/alias-2.def: New file.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/ChangeLog25
-rw-r--r--binutils/NEWS3
-rw-r--r--binutils/deflex.l3
-rw-r--r--binutils/defparse.y35
-rw-r--r--binutils/dlltool.c69
-rw-r--r--binutils/dlltool.h4
-rw-r--r--binutils/doc/binutils.texi8
-rw-r--r--binutils/testsuite/ChangeLog5
-rw-r--r--binutils/testsuite/binutils-all/alias-2.def2
-rw-r--r--binutils/testsuite/binutils-all/dlltool.exp30
10 files changed, 146 insertions, 38 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index fd9b2f5..eeeb615 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,28 @@
+2009-10-23 Kai Tietz <kai.tietz@onevision.com>
+
+ * deflex.l: Allow '<' and '>' in ID names.
+
+ * defparse.y (EQUAL): New token constant.
+ (opt_import_name): New rule for emptry or '==' ID.
+ (expline): Add opt_import_name as last line element.
+ (impline): Likewise.
+ * dlltool.c (ifunct): New member its_name.
+ (export): Likewise.
+ (append_import): Add its_name argument.
+ (defexports): Likewise.
+ (defimport): Likewise.
+ (scan_drectve_symbols): Adjust calls to def_exports.
+ (dump_def_info): Print new optinal import/export table
+ symbol name.
+ (generate_idata_ofile): Use its_name member.
+ (make_one_lib_file): Likewise.
+ (nfunc): Take its_name in account on sort.
+ * dlltool.h (def_exports): Add its_name as argument.
+ (def_import): Likewise.
+ * doc/binutils.texi: Add new def file syntax extension.
+ * deflex.l (EQUAL): Add rule for '=='.
+ * NEWS: Mention new feature.
+
2009-10-23 Thomas Cougnard <thomas.cougnard@gmail.com>
* readelf.c (dynamic_info): Correct size of array.
diff --git a/binutils/NEWS b/binutils/NEWS
index 4d0143b..3edee4b 100644
--- a/binutils/NEWS
+++ b/binutils/NEWS
@@ -1,5 +1,8 @@
-*- text -*-
+* Add to dlltool .def file feature of aliasing PE internal symbol name by
+ '== <ID>' option.
+
Changes in 2.20:
* Add support for delay importing to dlltool. Use the --output-delaylib <file>
diff --git a/binutils/deflex.l b/binutils/deflex.l
index bd8fbdc..317f6be 100644
--- a/binutils/deflex.l
+++ b/binutils/deflex.l
@@ -64,7 +64,7 @@ int linenumber;
[0-9][x0-9A-Fa-f]* { yylval.number = strtol (yytext,0,0);
return NUMBER; }
-(@)?[A-Za-z$:\-\_?][A-Za-z0-9/$:\-\_@?]* {
+(@)?[A-Za-z$:\-\_?][A-Za-z0-9/$:\<\>\-\_@?]* {
yylval.id = xstrdup (yytext);
return ID;
}
@@ -86,6 +86,7 @@ int linenumber;
"\t" { }
"\r" { }
"\n" { linenumber ++ ;}
+"==" { return EQUAL;}
"=" { return '=';}
"." { return '.';}
"@" { return '@';}
diff --git a/binutils/defparse.y b/binutils/defparse.y
index 6493c12..c05254a 100644
--- a/binutils/defparse.y
+++ b/binutils/defparse.y
@@ -35,11 +35,12 @@
%token SECTIONS EXPORTS IMPORTS VERSIONK BASE CONSTANT
%token READ WRITE EXECUTE SHARED NONSHARED NONAME PRIVATE
%token SINGLE MULTIPLE INITINSTANCE INITGLOBAL TERMINSTANCE TERMGLOBAL
+%token EQUAL
%token <id> ID
%token <number> NUMBER
%type <number> opt_base opt_ordinal opt_NONAME opt_CONSTANT opt_DATA opt_PRIVATE
%type <number> attr attr_list opt_number
-%type <id> opt_name opt_equal_name
+%type <id> opt_name opt_equal_name opt_import_name
%%
@@ -70,7 +71,8 @@ explist:
expline:
ID opt_equal_name opt_ordinal opt_NONAME opt_CONSTANT opt_DATA opt_PRIVATE
- { def_exports ($1, $2, $3, $4, $5, $6, $7);}
+ opt_import_name
+ { def_exports ($1, $2, $3, $4, $5, $6, $7, $8);}
;
implist:
implist impline
@@ -78,14 +80,22 @@ implist:
;
impline:
- ID '=' ID '.' ID '.' ID { def_import ($1,$3,$5,$7, 0); }
- | ID '=' ID '.' ID '.' NUMBER { def_import ($1,$3,$5, 0,$7); }
- | ID '=' ID '.' ID { def_import ($1,$3, 0,$5, 0); }
- | ID '=' ID '.' NUMBER { def_import ($1,$3, 0, 0,$5); }
- | ID '.' ID '.' ID { def_import ( 0,$1,$3,$5, 0); }
- | ID '.' ID '.' NUMBER { def_import ( 0,$1,$3, 0,$5); }
- | ID '.' ID { def_import ( 0,$1, 0,$3, 0); }
- | ID '.' NUMBER { def_import ( 0,$1, 0, 0,$3); }
+ ID '=' ID '.' ID '.' ID opt_import_name
+ { def_import ($1,$3,$5,$7, 0, $8); }
+ | ID '=' ID '.' ID '.' NUMBER opt_import_name
+ { def_import ($1,$3,$5, 0,$7, $8); }
+ | ID '=' ID '.' ID opt_import_name
+ { def_import ($1,$3, 0,$5, 0, $6); }
+ | ID '=' ID '.' NUMBER opt_import_name
+ { def_import ($1,$3, 0, 0,$5, $6); }
+ | ID '.' ID '.' ID opt_import_name
+ { def_import ( 0,$1,$3,$5, 0, $6); }
+ | ID '.' ID '.' NUMBER opt_import_name
+ { def_import ( 0,$1,$3, 0,$5, $6); }
+ | ID '.' ID opt_import_name
+ { def_import ( 0,$1, 0,$3, 0, $4); }
+ | ID '.' NUMBER opt_import_name
+ { def_import ( 0,$1, 0, 0,$3, $4); }
;
seclist:
@@ -155,6 +165,11 @@ opt_ordinal:
| { $$=-1;}
;
+opt_import_name:
+ EQUAL ID { $$ = $2; }
+ | { $$ = 0; }
+ ;
+
opt_equal_name:
'=' ID { $$ = $2; }
| '=' ID '.' ID
diff --git a/binutils/dlltool.c b/binutils/dlltool.c
index 585c780..4c9d2ec 100644
--- a/binutils/dlltool.c
+++ b/binutils/dlltool.c
@@ -329,6 +329,7 @@ static void mcore_elf_gen_out_file (void);
typedef struct ifunct
{
char * name; /* Name of function being imported. */
+ char * its_name; /* Optional import table symbol name. */
int ord; /* Two-byte ordinal value associated with function. */
struct ifunct *next;
} ifunctype;
@@ -747,6 +748,7 @@ typedef struct export
const char *name;
const char *internal_name;
const char *import_name;
+ const char *its_name;
int ordinal;
int constant;
int noname; /* Don't put name in image file. */
@@ -773,7 +775,7 @@ static const char *rvabefore (int);
static const char *asm_prefix (int, const char *);
static void process_def_file (const char *);
static void new_directive (char *);
-static void append_import (const char *, const char *, int);
+static void append_import (const char *, const char *, int, const char *);
static void run (const char *, char *);
static void scan_drectve_symbols (bfd *);
static void scan_filtered_symbols (bfd *, void *, long, unsigned int);
@@ -1021,12 +1023,14 @@ yyerror (const char * err ATTRIBUTE_UNUSED)
void
def_exports (const char *name, const char *internal_name, int ordinal,
- int noname, int constant, int data, int private)
+ int noname, int constant, int data, int private,
+ const char *its_name)
{
struct export *p = (struct export *) xmalloc (sizeof (*p));
p->name = name;
p->internal_name = internal_name ? internal_name : name;
+ p->its_name = its_name;
p->import_name = name;
p->ordinal = ordinal;
p->constant = constant;
@@ -1138,7 +1142,8 @@ def_stacksize (int reserve, int commit)
import_list. It is used by def_import. */
static void
-append_import (const char *symbol_name, const char *dll_name, int func_ordinal)
+append_import (const char *symbol_name, const char *dll_name, int func_ordinal,
+ const char *its_name)
{
iheadtype **pq;
iheadtype *q;
@@ -1152,6 +1157,7 @@ append_import (const char *symbol_name, const char *dll_name, int func_ordinal)
q->functail = q->functail->next;
q->functail->ord = func_ordinal;
q->functail->name = xstrdup (symbol_name);
+ q->functail->its_name = (its_name ? xstrdup (its_name) : NULL);
q->functail->next = NULL;
q->nfuncs++;
return;
@@ -1165,6 +1171,7 @@ append_import (const char *symbol_name, const char *dll_name, int func_ordinal)
q->functail = q->funchead;
q->next = NULL;
q->functail->name = xstrdup (symbol_name);
+ q->functail->its_name = (its_name ? xstrdup (its_name) : NULL);
q->functail->ord = func_ordinal;
q->functail->next = NULL;
@@ -1203,7 +1210,7 @@ append_import (const char *symbol_name, const char *dll_name, int func_ordinal)
void
def_import (const char *app_name, const char *module, const char *dllext,
- const char *entry, int ord_val)
+ const char *entry, int ord_val, const char *its_name)
{
const char *application_name;
char *buf;
@@ -1225,7 +1232,7 @@ def_import (const char *app_name, const char *module, const char *dllext,
module = buf;
}
- append_import (application_name, module, ord_val);
+ append_import (application_name, module, ord_val, its_name);
}
void
@@ -1397,7 +1404,7 @@ scan_drectve_symbols (bfd *abfd)
/* FIXME: The 5th arg is for the `constant' field.
What should it be? Not that it matters since it's not
currently useful. */
- def_exports (c, 0, -1, 0, 0, ! (flags & BSF_FUNCTION), 0);
+ def_exports (c, 0, -1, 0, 0, ! (flags & BSF_FUNCTION), 0, NULL);
if (add_stdcall_alias && strchr (c, '@'))
{
@@ -1406,7 +1413,7 @@ scan_drectve_symbols (bfd *abfd)
char *atsym = strchr (exported_name, '@');
*atsym = '\0';
/* Note: stdcall alias symbols can never be data. */
- def_exports (exported_name, xstrdup (c), -1, 0, 0, 0, 0);
+ def_exports (exported_name, xstrdup (c), -1, 0, 0, 0, 0, NULL);
}
}
else
@@ -1445,7 +1452,7 @@ scan_filtered_symbols (bfd *abfd, void *minisyms, long symcount,
++symbol_name;
def_exports (xstrdup (symbol_name) , 0, -1, 0, 0,
- ! (sym->flags & BSF_FUNCTION), 0);
+ ! (sym->flags & BSF_FUNCTION), 0, NULL);
if (add_stdcall_alias && strchr (symbol_name, '@'))
{
@@ -1454,7 +1461,7 @@ scan_filtered_symbols (bfd *abfd, void *minisyms, long symcount,
char *atsym = strchr (exported_name, '@');
*atsym = '\0';
/* Note: stdcall alias symbols can never be data. */
- def_exports (exported_name, xstrdup (symbol_name), -1, 0, 0, 0, 0);
+ def_exports (exported_name, xstrdup (symbol_name), -1, 0, 0, 0, 0, NULL);
}
}
}
@@ -1669,7 +1676,7 @@ dump_def_info (FILE *f)
fprintf (f, "\n");
for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
{
- fprintf (f, "%s %d = %s %s @ %d %s%s%s%s\n",
+ fprintf (f, "%s %d = %s %s @ %d %s%s%s%s%s%s\n",
ASM_C,
i,
exp->name,
@@ -1678,7 +1685,9 @@ dump_def_info (FILE *f)
exp->noname ? "NONAME " : "",
exp->private ? "PRIVATE " : "",
exp->constant ? "CONSTANT" : "",
- exp->data ? "DATA" : "");
+ exp->data ? "DATA" : "",
+ exp->its_name ? " ==" : "",
+ exp->its_name ? exp->its_name : "");
}
}
@@ -1761,20 +1770,22 @@ gen_def_file (void)
if (strcmp (exp->name, exp->internal_name) == 0)
{
- fprintf (output_def, "\t%s%s%s @ %d%s%s%s\n",
+ fprintf (output_def, "\t%s%s%s @ %d%s%s%s%s%s\n",
quote,
exp->name,
quote,
exp->ordinal,
exp->noname ? " NONAME" : "",
exp->private ? "PRIVATE " : "",
- exp->data ? " DATA" : "");
+ exp->data ? " DATA" : "",
+ exp->its_name ? " ==" : "",
+ exp->its_name ? exp->its_name : "");
}
else
{
char * quote1 = strchr (exp->internal_name, '.') ? "\"" : "";
/* char *alias = */
- fprintf (output_def, "\t%s%s%s = %s%s%s @ %d%s%s%s\n",
+ fprintf (output_def, "\t%s%s%s = %s%s%s @ %d%s%s%s%s%s\n",
quote,
exp->name,
quote,
@@ -1784,7 +1795,9 @@ gen_def_file (void)
exp->ordinal,
exp->noname ? " NONAME" : "",
exp->private ? "PRIVATE " : "",
- exp->data ? " DATA" : "");
+ exp->data ? " DATA" : "",
+ exp->its_name ? " ==" : "",
+ exp->its_name ? exp->its_name : "");
}
}
@@ -1888,7 +1901,8 @@ generate_idata_ofile (FILE *filvar)
fprintf (filvar,"funcptr%d_%d:\n", headindex, funcindex);
fprintf (filvar,"\t%s\t%d\n", ASM_SHORT,
((funcptr->ord) & 0xFFFF));
- fprintf (filvar,"\t%s\t\"%s\"\n", ASM_TEXT, funcptr->name);
+ fprintf (filvar,"\t%s\t\"%s\"\n", ASM_TEXT,
+ (funcptr->its_name ? funcptr->its_name : funcptr->name));
fprintf (filvar,"\t%s\t0\n", ASM_BYTE);
funcindex++;
}
@@ -2023,7 +2037,8 @@ gen_exp_file (void)
{
if (!exp->noname || show_allnames)
fprintf (f, "n%d: %s \"%s\"\n",
- exp->ordinal, ASM_TEXT, xlate (exp->name));
+ exp->ordinal, ASM_TEXT,
+ (exp->its_name ? exp->its_name : xlate (exp->name)));
if (exp->forward != 0)
fprintf (f, "f%d: %s \"%s\"\n",
exp->forward, ASM_TEXT, exp->internal_name);
@@ -2663,11 +2678,17 @@ make_one_lib_file (export_type *exp, int i, int delay)
why it did that, and it does not match what I see
in programs compiled with the MS tools. */
int idx = exp->hint;
- si->size = strlen (xlate (exp->import_name)) + 3;
+ if (exp->its_name)
+ si->size = strlen (exp->its_name) + 3;
+ else
+ si->size = strlen (xlate (exp->import_name)) + 3;
si->data = xmalloc (si->size);
si->data[0] = idx & 0xff;
si->data[1] = idx >> 8;
- strcpy ((char *) si->data + 2, xlate (exp->import_name));
+ if (exp->its_name)
+ strcpy ((char *) si->data + 2, exp->its_name);
+ else
+ strcpy ((char *) si->data + 2, xlate (exp->import_name));
}
break;
case IDATA7:
@@ -2958,7 +2979,7 @@ make_delay_head (void)
if (!no_idata5)
{
- fprintf (f, "\t.section\t.idata$5\n");
+ fprintf (f, "\t.section\t.idata$5\n");
/* NULL terminating list. */
#ifdef DLLTOOL_MX86_64
fprintf (f,"\t%s\t0\n\t%s\t0\n", ASM_LONG, ASM_LONG);
@@ -3118,6 +3139,7 @@ gen_lib_file (int delay)
assert (i < PREFIX_ALIAS_BASE);
alias_exp.name = make_imp_label (ext_prefix_alias, exp->name);
alias_exp.internal_name = exp->internal_name;
+ alias_exp.its_name = exp->its_name;
alias_exp.import_name = exp->name;
alias_exp.ordinal = exp->ordinal;
alias_exp.constant = exp->constant;
@@ -3626,7 +3648,10 @@ nfunc (const void *a, const void *b)
export_type *bp = *(export_type **) b;
const char *an = ap->name;
const char *bn = bp->name;
-
+ if (ap->its_name)
+ an = ap->its_name;
+ if (bp->its_name)
+ an = bp->its_name;
if (killat)
{
an = (an[0] == '@') ? an + 1 : an;
@@ -4153,7 +4178,7 @@ main (int ac, char **av)
if (mtable[machine].how_dljtab == 0)
{
- inform (_("Warning, machine type (%d) not supported for "
+ inform (_("Warning, machine type (%d) not supported for "
"delayimport."), machine);
}
else
diff --git a/binutils/dlltool.h b/binutils/dlltool.h
index e31916d..35a2280 100644
--- a/binutils/dlltool.h
+++ b/binutils/dlltool.h
@@ -24,10 +24,10 @@
extern void def_code (int);
extern void def_data (int);
extern void def_description (const char *);
-extern void def_exports (const char *, const char *, int, int, int, int, int);
+extern void def_exports (const char *, const char *, int, int, int, int, int, const char *);
extern void def_heapsize (int, int);
extern void def_import
- (const char *, const char *, const char *, const char *, int);
+ (const char *, const char *, const char *, const char *, int, const char *);
extern void def_library (const char *, int);
extern void def_name (const char *, int);
extern void def_section (const char *, int);
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 2cb56be..cb48014 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -3807,19 +3807,21 @@ The result is going to be named @var{name}@code{.exe}.
@item @code{LIBRARY} @var{name} @code{[ ,} @var{base} @code{]}
The result is going to be named @var{name}@code{.dll}.
-@item @code{EXPORTS ( ( (} @var{name1} @code{[ = } @var{name2} @code{] ) | ( } @var{name1} @code{=} @var{module-name} @code{.} @var{external-name} @code{) )}
+@item @code{EXPORTS ( ( (} @var{name1} @code{[ = } @var{name2} @code{] ) | ( } @var{name1} @code{=} @var{module-name} @code{.} @var{external-name} @code{) ) [ == } @var{its_name} @code{]}
@item @code{[} @var{integer} @code{] [ NONAME ] [ CONSTANT ] [ DATA ] [ PRIVATE ] ) *}
Declares @var{name1} as an exported symbol from the DLL, with optional
ordinal number @var{integer}, or declares @var{name1} as an alias
-(forward) of the function @var{external-name} in the DLL
+(forward) of the function @var{external-name} in the DLL.
+If @var{its_name} is specified, this name is used as string in export table.
@var{module-name}.
-@item @code{IMPORTS ( (} @var{internal-name} @code{=} @var{module-name} @code{.} @var{integer} @code{) | [} @var{internal-name} @code{= ]} @var{module-name} @code{.} @var{external-name} @code{) ) *}
+@item @code{IMPORTS ( (} @var{internal-name} @code{=} @var{module-name} @code{.} @var{integer} @code{) | [} @var{internal-name} @code{= ]} @var{module-name} @code{.} @var{external-name} @code{) [ == ) @var{its_name} @code{]} *}
Declares that @var{external-name} or the exported function whose
ordinal number is @var{integer} is to be imported from the file
@var{module-name}. If @var{internal-name} is specified then this is
the name that the imported function will be referred to in the body of
the DLL.
+If @var{its_name} is specified, this name is used as string in import table.
@item @code{DESCRIPTION} @var{string}
Puts @var{string} into the output @file{.exp} file in the
diff --git a/binutils/testsuite/ChangeLog b/binutils/testsuite/ChangeLog
index 6df00eb..4c5f2b7 100644
--- a/binutils/testsuite/ChangeLog
+++ b/binutils/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2009-10-23 Kai Tietz <kai.tietz@onevision.com>
+
+ * binutils-all/dlltool.exp: Add new test.
+ * binutils-all/alias-2.def: New file.
+
2009-10-18 Vincent Rivière <vincent.riviere@freesbee.fr>
* binutils-all/copy-2.d: Exclude more aout targets.
diff --git a/binutils/testsuite/binutils-all/alias-2.def b/binutils/testsuite/binutils-all/alias-2.def
new file mode 100644
index 0000000..ef41eec
--- /dev/null
+++ b/binutils/testsuite/binutils-all/alias-2.def
@@ -0,0 +1,2 @@
+EXPORTS
+symbol=nothing ==something
diff --git a/binutils/testsuite/binutils-all/dlltool.exp b/binutils/testsuite/binutils-all/dlltool.exp
index e0337f4..e9654ab 100644
--- a/binutils/testsuite/binutils-all/dlltool.exp
+++ b/binutils/testsuite/binutils-all/dlltool.exp
@@ -79,3 +79,33 @@ if [regexp $want $got] then {
} else {
fail "dlltool -p (import name)"
}
+
+verbose "$DLLTOOL -p prefix -l tmpdir/libalias2.a -d $srcdir/$subdir/alias-2.def $dlltool_gas_flag" 1
+catch "exec $DLLTOOL -p prefix -l tmpdir/libalias2.a -d $srcdir/$subdir/alias-2.def $dlltool_gas_flag" err
+
+if ![string match "" $err] then {
+ send_log "$err\n"
+ verbose "$err" 1
+ fail "dlltool -p (execution) alias-2.def"
+ continue
+}
+
+pass "dlltool -p (execution) alias-2.def"
+
+set got [binutils_run $NM "tmpdir/libalias2.a"]
+set want "00000000 I __imp__prefix_symbol.*00000000 T _prefix_symbol.*00000000 I __imp__symbol.*00000000 T _symbol"
+
+if [regexp $want $got] then {
+ pass "dlltool -p (symbol names) alias-2.def"
+} else {
+ fail "dlltool -p (symbol names) alias-2.def"
+}
+
+set got [binutils_run $OBJDUMP "-s -j .idata\$6 tmpdir/libalias2.a"]
+set want "(Contents of section .idata\\\$6:.*\\.\\.something\\..*){2,2}"
+
+if [regexp $want $got] then {
+ pass "dlltool -p (import name) alias-2.def"
+} else {
+ fail "dlltool -p (import name) alias-2.def"
+}