Mon Oct 9 13:06:31 1995 steve chamberlain <sac@slash.cygnus.com>

* dlltool.c (add_underscore): New.
	(xlate): Use new name.
	(main, usage): Update.
This commit is contained in:
Steve Chamberlain 1995-10-09 20:08:13 +00:00
parent b2a8627896
commit 531f86b422
2 changed files with 239 additions and 184 deletions

View file

@ -1,3 +1,9 @@
Mon Oct 9 13:06:31 1995 steve chamberlain <sac@slash.cygnus.com>
* dlltool.c (add_underscore): New.
(xlate): Use new name.
(main, usage): Update.
Fri Oct 6 14:08:51 1995 Ken Raeburn <raeburn@cygnus.com>
* sysinfo.y: Eliminate unused terminals "[" and "]" and unused

View file

@ -164,8 +164,8 @@
#include "libiberty.h"
#include "bucomm.h"
#include "getopt.h"
#include <sys/types.h>
#include "demangle.h"
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
@ -184,16 +184,18 @@
#endif
#endif
char *ar_name = "ar";
char *as_name = "as";
char *ranlib_name = "ranlib";
char *exp_name;
char *imp_name;
char *imp_name_lab;
char *dll_name;
int add_indirect = 0;
int add_underscore = 0;
int dontdeltemps = 0;
int yydebug;
@ -204,9 +206,9 @@ char *strrchr ();
char *strdup ();
static int machine;
int suckunderscore;
int killat;
static int verbose;
FILE *output_def;
FILE *base_file;
#ifdef DLLTOOL_ARM
static char *mname = "arm";
@ -248,8 +250,9 @@ mtable[]
};
char *rvaafter (machine)
int machine;
char *
rvaafter (machine)
int machine;
{
switch (machine)
{
@ -260,8 +263,9 @@ int machine;
}
}
char *rvabefore (machine)
int machine;
char *
rvabefore (machine)
int machine;
{
switch (machine)
{
@ -272,7 +276,8 @@ int machine;
}
}
char *asm_prefix (machine)
char *
asm_prefix (machine)
{
switch (machine)
{
@ -524,7 +529,7 @@ run (what, args)
/* Count the args */
i = 0;
for (s = args; *s ; s++)
for (s = args; *s; s++)
if (*s == ' ')
i++;
i++;
@ -532,7 +537,8 @@ run (what, args)
i = 0;
argv[i++] = what;
s = args;
while (1) {
while (1)
{
argv[i++] = s;
while (*s != ' ' && *s != 0)
s++;
@ -754,6 +760,24 @@ flush_page (f, need, page_addr, on_page)
}
void
gen_def_file ()
{
int i;
export_type *exp;
fprintf (output_def, ";");
for (i = 0; oav[i]; i++)
fprintf (output_def, " %s", oav[i]);
fprintf (output_def, "\nEXPORTS\n");
for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
{
fprintf (output_def, "\t%s @ %d; %s\n",
exp->name,
exp->ordinal,
cplus_demangle (exp->internal_name, DMGL_ANSI | DMGL_PARAMS));
}
}
void
gen_exp_file ()
{
@ -782,7 +806,8 @@ gen_exp_file ()
}
dump_def_info (f);
if (d_exports) {
if (d_exports)
{
fprintf (f, "\t.section .edata\n\n");
fprintf (f, "\t%s 0 %s Allways 0\n", ASM_LONG, ASM_C);
fprintf (f, "\t%s 0 %s Time and date\n", ASM_LONG, ASM_C);
@ -816,7 +841,7 @@ gen_exp_file ()
i = exp->ordinal;
}
#endif
fprintf (f, "\t%s%s%s%s\t%s %d\n",ASM_RVA_BEFORE,
fprintf (f, "\t%s%s%s%s\t%s %d\n", ASM_RVA_BEFORE,
ASM_PREFIX,
exp->internal_name, ASM_RVA_AFTER, ASM_C, exp->ordinal);
i++;
@ -896,12 +921,13 @@ gen_exp_file ()
without using the import library. */
if (add_indirect)
{
fprintf (f,"\t.section\t.rdata\n");
fprintf (f, "\t.section\t.rdata\n");
for (i = 0, exp = d_exports; exp; i++, exp = exp->next)
if (!exp->noname) {
if (!exp->noname)
{
fprintf (f, "\t%s\t__imp_%s\n", ASM_GLOBAL, exp->name);
fprintf (f, "__imp_%s:\n", exp->name);
fprintf (f,"\t%s\t%s\n", ASM_LONG, exp->name);
fprintf (f, "\t%s\t%s\n", ASM_LONG, exp->name);
}
}
@ -916,8 +942,8 @@ gen_exp_file ()
long *copy;
int j;
int on_page;
fprintf (f,"\t.section\t.init\n");
fprintf (f,"lab:\n");
fprintf (f, "\t.section\t.init\n");
fprintf (f, "lab:\n");
fseek (base_file, 0, SEEK_END);
numbytes = ftell (base_file);
@ -926,8 +952,10 @@ gen_exp_file ()
fread (copy, 1, numbytes, base_file);
num_entries = numbytes / sizeof (long);
if (num_entries) {
fprintf (f, "\t.section\t.reloc\n");
if (num_entries)
{
qsort (copy, num_entries, sizeof (long), sfunc);
addr = copy[0];
@ -953,11 +981,11 @@ gen_exp_file ()
fclose (f);
/* assemble the file */
sprintf (outfile,"-o %s t%s", exp_name, exp_name);
sprintf (outfile, "-o %s t%s", exp_name, exp_name);
run (as_name, outfile);
if (dontdeltemps==0)
if (dontdeltemps == 0)
{
sprintf (outfile,"t%s", exp_name);
sprintf (outfile, "t%s", exp_name);
unlink (outfile);
}
}
@ -965,12 +993,14 @@ gen_exp_file ()
static char *
xlate (char *name)
{
if (add_underscore)
{
char *copy = malloc (strlen (name) + 2);
copy[0] = '_';
strcpy (copy + 1, name);
name = copy;
}
if (!suckunderscore)
return name;
if (name[0] == '_')
name++;
if (killat)
{
char *p;
@ -1005,8 +1035,8 @@ gen_lib_file ()
fprintf (f, "%s IMAGE_IMPORT_DESCRIPTOR\n", ASM_C);
fprintf (f, "\t.section .idata$2\n");
fprintf (f, "\t%s\t__%s_head\n", ASM_GLOBAL, imp_name);
fprintf (f, "__%s_head:\n", imp_name);
fprintf (f, "\t%s\t__%s_head\n", ASM_GLOBAL, imp_name_lab);
fprintf (f, "__%s_head:\n", imp_name_lab);
fprintf (f, "\t%shname%s\t%sPtr to image import by name list\n",
ASM_RVA_BEFORE, ASM_RVA_AFTER, ASM_C);
@ -1017,7 +1047,7 @@ gen_lib_file ()
fprintf (f, "\t%s\t0\t%s Forwarder chain\n", ASM_LONG, ASM_C);
fprintf (f, "\t%s__%s_iname%s\t%s imported dll's name\n",
ASM_RVA_BEFORE,
imp_name,
imp_name_lab,
ASM_RVA_AFTER,
ASM_C);
fprintf (f, "\t%sfthunk%s\t%s pointer to firstthunk\n",
@ -1049,7 +1079,7 @@ gen_lib_file ()
exp->name, ASM_JUMP, exp->name);
fprintf (f, "\t.section\t.idata$7\t%s To force loading of head\n", ASM_C);
fprintf (f, "\t%s\t__%s_head\n", ASM_LONG, imp_name);
fprintf (f, "\t%s\t__%s_head\n", ASM_LONG, imp_name_lab);
fprintf (f, "\t.section .idata$5\n");
@ -1081,9 +1111,9 @@ gen_lib_file ()
sprintf (outfile, "%st.s", prefix);
f = fopen (outfile, "w");
fprintf (f, "\t.section .idata$7\n");
fprintf (f, "\t%s\t__%s_iname\n", ASM_GLOBAL, imp_name);
fprintf (f, "\t%s\t__%s_iname\n", ASM_GLOBAL, imp_name_lab);
fprintf (f, "__%s_iname:\t%s\t\"%s\"\n",
imp_name, ASM_TEXT, dll_name);
imp_name_lab, ASM_TEXT, dll_name);
fprintf (f, "\t.section .idata$4\n");
@ -1115,7 +1145,7 @@ gen_lib_file ()
sprintf (outfile + sol, " %ss%d.o", prefix, i);
sol = strlen (outfile);
if (sol >100)
if (sol > 100)
{
run (ar_name, outfile);
sol = 0;
@ -1406,9 +1436,9 @@ workout_prefix ()
if (strncmp (p, "dlltool", 7) == 0)
{
int len = p - program_name;
ar_name = xmalloc (len + strlen ("ar") +1);
ranlib_name = xmalloc (len + strlen ("ranlib")+1);
as_name = xmalloc (len + strlen ("as")+1);
ar_name = xmalloc (len + strlen ("ar") + 1);
ranlib_name = xmalloc (len + strlen ("ranlib") + 1);
as_name = xmalloc (len + strlen ("as") + 1);
memcpy (ar_name, program_name, len);
strcpy (ar_name + len, "ar");
@ -1436,9 +1466,10 @@ usage (file, status)
fprintf (file, " --add-indirect Add dll indirects to export file.\n");
fprintf (file, " --dllname <name> Name of input dll to put into output lib.\n");
fprintf (file, " --def <deffile> Name input .def file\n");
fprintf (file, " --output-def <deffile> Name output .def file\n");
fprintf (file, " --base-file <basefile> Read linker generated base file\n");
fprintf (file, " -v Verbose\n");
fprintf (file, " -u Remove leading underscore from .lib\n");
fprintf (file, " -U Add underscores to .lib\n");
fprintf (file, " -k Kill @<n> from exported names\n");
fprintf (file, " --nodelete Keep temp files.\n");
exit (status);
@ -1446,12 +1477,13 @@ usage (file, status)
static struct option long_options[] =
{
{"nodelete", no_argument, NULL,'n'},
{"dllname", required_argument, NULL,'D'},
{"nodelete", no_argument, NULL, 'n'},
{"dllname", required_argument, NULL, 'D'},
{"output-exp", required_argument, NULL, 'e'},
{"output-def", required_argument, NULL, 'z'},
{"output-lib", required_argument, NULL, 'l'},
{"def", required_argument, NULL, 'd'},
{"underscore", no_argument, NULL, 'u'},
{"add-underscore", no_argument, NULL, 'U'},
{"killat", no_argument, NULL, 'k'},
{"help", no_argument, NULL, 'h'},
{"machine", required_argument, NULL, 'm'},
@ -1472,13 +1504,19 @@ main (ac, av)
program_name = av[0];
oav = av;
while ((c = getopt_long (ac, av, "aD:l:e:nkvbuh?m:yd:", long_options, 0)) != EOF)
while ((c = getopt_long (ac, av, "uaD:l:e:nkvbUh?m:yd:", long_options, 0)) != EOF)
{
switch (c)
{
/* ignored for compatibility */
case 'u':
break;
case 'a':
add_indirect = 1;
break;
case 'z':
output_def = fopen (optarg, "w");
break;
case 'D':
dll_name = optarg;
break;
@ -1501,8 +1539,8 @@ main (ac, av)
case 'y':
yydebug = 1;
break;
case 'u':
suckunderscore = 1;
case 'U':
add_underscore = 1;
break;
case 'k':
killat = 1;
@ -1571,8 +1609,19 @@ main (ac, av)
if (exp_name)
gen_exp_file ();
if (imp_name)
{
/* Make imp_name safe for use as a label. */
char *p;
imp_name_lab = strdup (imp_name);
for (p = imp_name_lab; *p; *p++)
{
if (!isalpha (*p) && !isdigit (*p))
*p = '_';
}
gen_lib_file ();
}
if (output_def)
gen_def_file ();
return 0;
}