* ar.c: (print_contents.c, extract_file, do_quick_append):

Malloc buffers rather than allocate on stack (so it works
	on NT).
	* deflex.l: Names can have an @ in them.
	* dlltool.c: Loads of stuff. Can now generate .imp files which
	work with NT .dlls.
This commit is contained in:
Steve Chamberlain 1995-06-29 00:59:07 +00:00
parent 30355216bd
commit 6f2d32120e
6 changed files with 683 additions and 282 deletions

View File

@ -1,3 +1,17 @@
Wed Jun 28 17:51:24 1995 Steve Chamberlain <sac@slash.cygnus.com>
* ar.c: (print_contents.c, extract_file, do_quick_append):
Malloc buffers rather than allocate on stack (so it works
on NT).
* deflex.l: Names can have an @ in them.
* dlltool.c: Loads of stuff. Can now generate .imp files which
work with NT .dlls.
Thu Jun 22 19:10:50 1995 Stan Shebs <shebs@andros.cygnus.com>
* mpw-make.in (demangle.c.o): Remove.
(arparse.h): Depend on arparse.c instead of arparse.y.
Wed Jun 21 17:32:45 1995 Ken Raeburn <raeburn@cujo.cygnus.com>
* Makefile.in (DISTSTUFF): Don't include info here.

View File

@ -27,6 +27,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "bfd.h"
#include "sysdep.h"
#include "libiberty.h"
#include "progress.h"
#include "bucomm.h"
#include "aout/ar.h"
#include "libbfd.h"
@ -163,7 +164,10 @@ map_over_members (arch, function, files, count)
if (count == 0)
{
for (head = arch->next; head; head = head->next)
function (head);
{
PROGRESS (1);
function (head);
}
return;
}
/* This may appear to be a baroque way of accomplishing what we want.
@ -175,8 +179,10 @@ map_over_members (arch, function, files, count)
for (; count > 0; files++, count--)
{
boolean found = false;
for (head = arch->next; head; head = head->next)
{
PROGRESS (1);
if (head->filename == NULL)
{
/* Some archive formats don't get the filenames filled in
@ -218,6 +224,7 @@ Usage: %s [-]{dmpqrtx}[abcilosuvV] [member-name] archive-file file...\n\
else
fprintf (stderr, "\
Usage: %s [-vV] archive\n", program_name);
list_supported_targets (program_name, stderr);
xexit (1);
}
@ -283,6 +290,8 @@ main (argc, argv)
program_name = argv[0];
xmalloc_set_program_name (program_name);
START_PROGRESS (program_name, 0);
bfd_init ();
show_version = 0;
@ -410,6 +419,13 @@ main (argc, argv)
case 'M':
mri_mode = 1;
break;
case 'f':
/* On HP/UX 9, the f modifier means to truncate names to 14
characters when comparing them to existing names. We
always use an extended name table, so the truncation has
no purpose for us. We ignore the modifier for
compatibility with the AR_FLAGS definition in make. */
break;
default:
fprintf (stderr, "%s: illegal option -- %c\n", program_name, c);
usage ();
@ -523,6 +539,8 @@ main (argc, argv)
}
}
END_PROGRESS (program_name);
xexit (0);
return 0;
}
@ -579,6 +597,7 @@ open_inarch (archive_filename)
next_one;
next_one = bfd_openr_next_archived_file (arch, next_one))
{
PROGRESS (1);
*last_one = next_one;
last_one = &next_one->next;
}
@ -593,6 +612,7 @@ print_contents (abfd)
bfd *abfd;
{
int ncopied = 0;
char *cbuf = xmalloc (BUFSIZE);
struct stat buf;
long size;
if (bfd_stat_arch_elt (abfd, &buf) != 0)
@ -606,7 +626,7 @@ print_contents (abfd)
size = buf.st_size;
while (ncopied < size)
{
char cbuf[BUFSIZE];
int nread;
int tocopy = size - ncopied;
if (tocopy > BUFSIZE)
@ -620,6 +640,7 @@ print_contents (abfd)
fwrite (cbuf, 1, nread, stdout);
ncopied += tocopy;
}
free (cbuf);
}
/* Extract a member of the archive into its own file.
@ -637,7 +658,7 @@ extract_file (abfd)
bfd *abfd;
{
FILE *ostream;
char cbuf[BUFSIZE];
char *cbuf = xmalloc (BUFSIZE);
int nread, tocopy;
int ncopied = 0;
long size;
@ -706,7 +727,7 @@ extract_file (abfd)
if (preserve_dates)
{
#ifdef POSIX_UTIME
#if POSIX_UTIME
struct utimbuf tb;
tb.actime = buf.st_mtime;
tb.modtime = buf.st_mtime;
@ -727,6 +748,7 @@ extract_file (abfd)
#endif /* ! USE_UTIME */
#endif /* ! POSIX_UTIME */
}
free (cbuf);
}
/* Just do it quickly; don't worry about dups, armap, or anything like that */
@ -737,7 +759,7 @@ do_quick_append (archive_filename, files_to_append)
char **files_to_append;
{
FILE *ofile, *ifile;
char buf[BUFSIZE];
char *buf = xmalloc (BUFSIZE);
long tocopy, thistime;
bfd *temp;
struct stat sbuf;
@ -830,6 +852,7 @@ do_quick_append (archive_filename, files_to_append)
}
fclose (ofile);
bfd_close (temp);
free (buf);
}
@ -838,19 +861,12 @@ write_archive (iarch)
bfd *iarch;
{
bfd *obfd;
int namelen = strlen (bfd_get_filename (iarch));
char *old_name = xmalloc (namelen + 1);
char *new_name = xmalloc (namelen + EXT_NAME_LEN);
char *old_name, *new_name;
bfd *contents_head = iarch->next;
old_name = xmalloc (strlen (bfd_get_filename (iarch)) + 1);
strcpy (old_name, bfd_get_filename (iarch));
strcpy (new_name, bfd_get_filename (iarch));
#ifdef __GO32__ /* avoid long .extensions for MS-DOS */
strcpy (new_name + namelen, "-a");
#else
strcpy (new_name + namelen, "-art");
#endif
new_name = make_tempname (old_name);
output_filename = new_name;
@ -1037,7 +1053,8 @@ replace_members (arch, files_to_move)
{
current = *current_ptr;
if (!strcmp (normalize (*files_to_move), current->filename))
if (!strcmp (normalize (*files_to_move),
normalize (current->filename)))
{
if (newer_only)
{

85
binutils/deflex.l Normal file
View File

@ -0,0 +1,85 @@
%{
/* deflex.l - Lexer for .def files */
/* Copyright (C) 1995 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
(at your option) any later version.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Contributed by Steve Chamberlain
sac@cygnus.com
*/
#define DONTDECLARE_MALLOC
#include "defparse.h"
extern char *strdup();
int linenumber;
%}
%%
"NAME" { return NAME;}
"LIBRARY" { return LIBRARY;}
"DESCRIPTION" { return DESCRIPTION;}
"STACKSIZE" { return STACKSIZE;}
"HEAPSIZE" { return HEAPSIZE;}
"CODE" { return CODE;}
"DATA" { return DATA;}
"SECTIONS" { return SECTIONS;}
"EXPORTS" { return EXPORTS;}
"IMPORTS" { return IMPORTS;}
"VERSION" { return VERSION;}
"BASE" { return BASE;}
"CONSTANT" { return CONSTANT; }
"NONAME" { return NONAME; }
"READ" { return READ;}
"WRITE" { return WRITE;}
"EXECUTE" { return EXECUTE;}
"SHARED" { return SHARED;}
[0-9][x0-9A-Fa-f]* { yylval.number = strtol (yytext,0,0);
return NUMBER; }
[A-Za-z$:\-\_][A-Za-z0-9/$:\-\_@]+ {
yylval.id = strdup(yytext);
return ID;
}
"\""[^\"]*"\"" {
yylval.string = strdup (yytext+1);
yylval.string[yyleng-2] = 0;
return STRING;
}
"\'"[^\']*"\'" {
yylval.string = strdup (yytext+1);
yylval.string[yyleng-2] = 0;
return STRING;
}
"*".* { }
";".* { }
" " { }
"\t" { }
"\n" { linenumber ++ ;}
"=" { return '=';}
"." { return '.';}
"@" { return '@';}
"," { return ',';}
%%
#ifndef yywrap
/* Needed for lex, though not flex. */
int yywrap() { return 1; }
#endif

File diff suppressed because it is too large Load Diff

View File

@ -25,19 +25,18 @@
All debugging information is preserved */
#include <bfd.h>
#include <getopt.h>
#include <stdio.h>
#include <time.h>
#include <libiberty.h>
#include "sysdep.h"
#include "bucomm.h"
#include "sysroff.h"
#include "coffgrok.h"
#include <libiberty.h>
#include <getopt.h>
#include "coff/internal.h"
#include "../bfd/libcoff.h"
#define PROGRAM_VERSION "1.5"
/*#define FOOP1 1*/
/*#define FOOP1 1 */
static int sh;
static int h8300;
@ -50,10 +49,12 @@ static FILE *file;
static bfd *abfd;
static int debug = 0;
static int quick = 0;
static int noprescan = 0;
static struct coff_ofile *tree;
/* Obsolete ??
static int absolute_p;
*/
static int absolute_p;
static int segmented_p;
static int code;
@ -298,10 +299,11 @@ wr_tr ()
}
static void
wr_un (ptr, sfile, first)
wr_un (ptr, sfile, first, nsecs)
struct coff_ofile *ptr;
struct coff_sfile *sfile;
int first;
int nsecs;
{
struct IT_un un;
@ -314,7 +316,15 @@ wr_un (ptr, sfile, first)
else
un.format = FORMAT_OM;
un.spare1 = 0;
#if 0
un.nsections = ptr->nsections - 1; /* Don't count the abs section */
#else
/*NEW - only count sections with size */
un.nsections = nsecs;
#endif
un.nextdefs = 0;
un.nextrefs = 0;
/* Count all the undefined and defined variables with global scope */
@ -440,13 +450,13 @@ wr_ob (p, section)
unsigned char stuff[200];
i = 0;
while (i < section->size)
while (i < section->bfd_section->_raw_size)
{
struct IT_ob ob;
int todo = 200; /* Copy in 200 byte lumps */
ob.spare = 0;
if (i + todo > section->size)
todo = section->size - i;
if (i + todo > section->bfd_section->_raw_size)
todo = section->bfd_section->_raw_size - i;
if (first)
{
@ -467,9 +477,28 @@ wr_ob (p, section)
ob.data.len = todo;
bfd_get_section_contents (abfd, section->bfd_section, stuff, i, todo);
ob.data.data = stuff;
sysroff_swap_ob_out (file, &ob /*, i + todo < section->size*/ );
sysroff_swap_ob_out (file, &ob /*, i + todo < section->size */ );
i += todo;
}
/* Now fill the rest with blanks */
while (i < section->size)
{
struct IT_ob ob;
int todo = 200; /* Copy in 200 byte lumps */
ob.spare = 0;
if (i + todo > section->size)
todo = section->size - i;
ob.saf = 0;
ob.cpf = 0; /* Never compress */
ob.data.len = todo;
memset (stuff, 0, todo);
ob.data.data = stuff;
sysroff_swap_ob_out (file, &ob);
i += todo;
}
/* Now fill the rest with blanks */
}
static void
@ -824,42 +853,43 @@ walk_tree_type_1 (sfile, symbol, type, nest)
}
}
static void
dty_start ()
{
struct IT_dty dty;
dty.end = 0;
dty.neg = 0x1001;
dty.spare = 0;
sysroff_swap_dty_out (file, &dty);
}
/* Obsolete ?
static void
dty_start ()
{
struct IT_dty dty;
dty.end = 0;
dty.neg = 0x1001;
dty.spare = 0;
sysroff_swap_dty_out (file, &dty);
}
static void
dty_stop ()
{
struct IT_dty dty;
dty.end = 0;
dty.neg = 0x1001;
dty.end = 1;
sysroff_swap_dty_out (file, &dty);
}
static void
dty_stop ()
{
struct IT_dty dty;
dty.end = 0;
dty.neg = 0x1001;
dty.end = 1;
sysroff_swap_dty_out (file, &dty);
}
static void
dump_tree_structure (sfile, symbol, type, nest)
struct coff_sfile *sfile;
struct coff_symbol *symbol;
struct coff_type *type;
int nest;
{
if (symbol->type->type == coff_function_type)
{
static void
dump_tree_structure (sfile, symbol, type, nest)
struct coff_sfile *sfile;
struct coff_symbol *symbol;
struct coff_type *type;
int nest;
{
if (symbol->type->type == coff_function_type)
{
}
}
}
}
*/
static void
walk_tree_type (sfile, symbol, type, nest)
@ -1067,8 +1097,8 @@ walk_tree_symbol (sfile, section, symbol, nest)
break;
case coff_where_member_of_enum:
/* dsy.bitunit = 0;
dsy.field_len = symbol->type->size;
dsy.field_off = symbol->where->offset;*/
dsy.field_len = symbol->type->size;
dsy.field_off = symbol->where->offset; */
break;
case coff_where_register:
case coff_where_unknown:
@ -1327,7 +1357,7 @@ wr_dus (p, sfile)
}
/* Find the offset of the .text section for this sfile in the
.text section for the output file */
.text section for the output file */
static int
find_base (sfile, section)
@ -1537,12 +1567,13 @@ wr_cs ()
for all the sections which appear in the output file, even
if there isn't an equivalent one on the input */
static void
static int
wr_sc (ptr, sfile)
struct coff_ofile *ptr;
struct coff_sfile *sfile;
{
int i;
int scount = 0;
/* First work out the total number of sections */
int total_sec = ptr->nsections;
@ -1555,7 +1586,7 @@ wr_sc (ptr, sfile)
struct coff_symbol *symbol;
struct myinfo *info
= (struct myinfo *) calloc (total_sec, sizeof (struct myinfo));
= (struct myinfo *) calloc (total_sec, sizeof (struct myinfo));
@ -1646,14 +1677,13 @@ wr_sc (ptr, sfile)
{
sc.contents = CONTENTS_CODE;
}
sysroff_swap_sc_out (file, &sc);
/* NEW */
if (sc.length) {
sysroff_swap_sc_out (file, &sc);
scount++;
}
}
return scount;
}
static void
@ -1731,8 +1761,16 @@ wr_unit_info (ptr)
sfile;
sfile = sfile->next)
{
wr_un (ptr, sfile, first);
wr_sc (ptr, sfile);
long p1;
long p2;
int nsecs;
p1 = ftell (file);
wr_un (ptr, sfile, first, 0);
nsecs = wr_sc (ptr, sfile);
p2 = ftell (file);
fseek (file, p1, 0);
wr_un (ptr, sfile, first, nsecs);
fseek (file, p2, 0);
wr_er (ptr, sfile, first);
wr_ed (ptr, sfile, first);
first = 0;
@ -1776,7 +1814,7 @@ prescan (tree)
if (s->visible->type == coff_vis_common)
{
struct coff_where *w = s->where;
/* s->visible->type = coff_vis_ext_def; leave it as common */
/* s->visible->type = coff_vis_ext_def; leave it as common */
common_section->size = align (common_section->size);
w->offset = common_section->size + common_section->address;
w->section = common_section;
@ -1817,6 +1855,7 @@ main (ac, av)
{
{"debug", no_argument, 0, 'd'},
{"quick", no_argument, 0, 'q'},
{"noprescan", no_argument, 0, 'n'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{NULL, no_argument, 0, 0}
@ -1828,7 +1867,7 @@ main (ac, av)
program_name = av[0];
xmalloc_set_program_name (program_name);
while ((opt = getopt_long (ac, av, "dhVq", long_options,
while ((opt = getopt_long (ac, av, "dhVqn", long_options,
(int *) NULL))
!= EOF)
{
@ -1837,21 +1876,24 @@ main (ac, av)
case 'q':
quick = 1;
break;
case 'n':
noprescan = 1;
break;
case 'd':
debug = 1;
break;
case 'h':
show_help ();
/*NOTREACHED*/
/*NOTREACHED */
case 'V':
printf ("GNU %s version %s\n", program_name, PROGRAM_VERSION);
exit (0);
/*NOTREACHED*/
/*NOTREACHED */
case 0:
break;
default:
show_usage (stderr, 1);
/*NOTREACHED*/
/*NOTREACHED */
}
}
@ -1889,7 +1931,7 @@ main (ac, av)
if (!output_file)
{
/* Take a .o off the input file and stick on a .obj. If
it doesn't end in .o, then stick a .obj on anyway */
it doesn't end in .o, then stick a .obj on anyway */
int len = strlen (input_file);
output_file = xmalloc (len + 5);
@ -1936,7 +1978,8 @@ main (ac, av)
if (debug)
printf ("ids %d %d\n", base1, base2);
tree = coff_grok (abfd);
prescan (tree);
if (!noprescan)
prescan (tree);
wr_module (tree);
return 0;
}

View File

@ -47,14 +47,17 @@ if ![string match "" $got] then {
# in the first place, and may order things a little differently.
# Those systems should use setup_xfail here.
setup_xfail "sh-*-coff" "sh-*-hms"
setup_xfail "sh-*-coff" "sh-*-hms"
setup_xfail "arm-*-pe"
setup_xfail "m68*-*-hpux*" "m68*-*-sunos*" "m68*-*-coff" "m68*-*-vxworks*"
setup_xfail "m68*-ericsson-ose"
setup_xfail "i*86-*-linux"
setup_xfail "a29k-*-udi" "a29k-*-coff"
setup_xfail "i960-*-vxworks5.1" "i960-*-coff"
setup_xfail "h8300-*-hms" "h8300-*-coff"
setup_xfail "h8500-*-hms" "h8500-*-coff"
setup_xfail "hppa*-*-*"
clear_xfail "hppa*-*-*elf*"
setup_xfail "m88*-*-coff"
if [string match "" $exec_output] then {