Removed usage of alloca, lint.

This commit is contained in:
Steve Chamberlain
1991-12-03 22:16:29 +00:00
parent 706e58f11b
commit 242bfe8791
3 changed files with 101 additions and 196 deletions

View File

@ -4,4 +4,3 @@ TDEFINES=-DBFD_HEADERS -DMANY_SEGMENTS -DBFD

View File

@ -40,7 +40,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "obstack.h" #include "obstack.h"
#include "subsegs.h" #include "subsegs.h"
#include "frags.h" #include "frags.h"
#include "../bfd/libbfd.h"
/* This vector is used to turn an internal segment into a section # /* This vector is used to turn an internal segment into a section #
@ -108,9 +108,17 @@ static symbolS *EXFUN(tag_find_or_make,(char *name));
static symbolS* EXFUN(tag_find,(char *name)); static symbolS* EXFUN(tag_find,(char *name));
static void EXFUN(w_symbols,( static int
bfd *abfd , EXFUN(c_line_new,(
char **where , symbolS *symbol,
long paddr,
unsigned short line_number,
fragS* frag));
static void EXFUN(w_symbols,
(bfd *abfd ,
char *where ,
symbolS *symbol_rootP)); symbolS *symbol_rootP));
@ -125,7 +133,6 @@ static void EXFUN( obj_coff_line,(void));
static void EXFUN( obj_coff_ln,(void)); static void EXFUN( obj_coff_ln,(void));
static void EXFUN( obj_coff_scl,(void)); static void EXFUN( obj_coff_scl,(void));
static void EXFUN( obj_coff_size,(void)); static void EXFUN( obj_coff_size,(void));
static void EXFUN( obj_coff_stab,(int what));
static void EXFUN( obj_coff_tag,(void)); static void EXFUN( obj_coff_tag,(void));
static void EXFUN( obj_coff_type,(void)); static void EXFUN( obj_coff_type,(void));
static void EXFUN( obj_coff_val,(void)); static void EXFUN( obj_coff_val,(void));
@ -211,12 +218,10 @@ seg_info_type seg_info_off_by_4[N_SEG] =
{18}, {18},
{19}, {19},
{20}, {20},
{21}, {0},
{22}, {0},
{23}, {0},
{SEG_REGISTER},0x1111,0x2222,0x3333,0x4444 {SEG_REGISTER},0,0,0,0};
};
#define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4]) #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
#define SEG_INFO_FROM_SEG_NUMBER(x) (seg_info_off_by_4[(x)]) #define SEG_INFO_FROM_SEG_NUMBER(x) (seg_info_off_by_4[(x)])
@ -251,7 +256,7 @@ static unsigned int DEFUN(size_section,(abfd, idx),
bfd *abfd AND bfd *abfd AND
unsigned int idx) unsigned int idx)
{ {
asection *sec;
unsigned int size = 0; unsigned int size = 0;
fragS *frag = segment_info[idx].frchainP->frch_root; fragS *frag = segment_info[idx].frchainP->frch_root;
while (frag) { while (frag) {
@ -311,14 +316,14 @@ void DEFUN(do_relocs_for,(abfd, file_cursor),
unsigned long *file_cursor) unsigned long *file_cursor)
{ {
unsigned int nrelocs; unsigned int nrelocs;
arelent **reloc_ptr_vector;
arelent *reloc_vector;
asymbol **ptrs;
unsigned int idx; unsigned int idx;
unsigned int i;
fixS *from;
for (idx = SEG_E0; idx < SEG_E9; idx++) for (idx = SEG_E0; idx < SEG_E9; idx++)
{ {
if (segment_info[idx].scnhdr.s_name[0]) if (segment_info[idx].scnhdr.s_name[0])
@ -333,7 +338,7 @@ void DEFUN(do_relocs_for,(abfd, file_cursor),
nrelocs = count_entries_in_chain(idx); nrelocs = count_entries_in_chain(idx);
external_reloc_size = nrelocs * RELSZ; external_reloc_size = nrelocs * RELSZ;
external_reloc_vec = external_reloc_vec =
(struct external_reloc*)alloca(external_reloc_size); (struct external_reloc*)malloc(external_reloc_size);
@ -397,8 +402,9 @@ void DEFUN(do_relocs_for,(abfd, file_cursor),
/* Write out the reloc table */ /* Write out the reloc table */
segment_info[idx].scnhdr.s_relptr = *file_cursor; segment_info[idx].scnhdr.s_relptr = *file_cursor;
segment_info[idx].scnhdr.s_nreloc = nrelocs; segment_info[idx].scnhdr.s_nreloc = nrelocs;
bfd_write(external_reloc_vec, 1, external_reloc_size, abfd); bfd_write((PTR)external_reloc_vec, 1, external_reloc_size, abfd);
*file_cursor += external_reloc_size; *file_cursor += external_reloc_size;
free( external_reloc_vec);
} }
} }
} }
@ -424,7 +430,7 @@ static void DEFUN(fill_section,(abfd, filehdr, file_cursor),
if (s->s_name[0]) { if (s->s_name[0]) {
fragS *frag = segment_info[i].frchainP->frch_root; fragS *frag = segment_info[i].frchainP->frch_root;
char *buffer = alloca(s->s_size); char *buffer = malloc(s->s_size);
s->s_scnptr = *file_cursor; s->s_scnptr = *file_cursor;
s->s_paddr = paddr; s->s_paddr = paddr;
s->s_vaddr = paddr; s->s_vaddr = paddr;
@ -440,6 +446,7 @@ static void DEFUN(fill_section,(abfd, filehdr, file_cursor),
while (frag) { while (frag) {
unsigned int fill_size; unsigned int fill_size;
switch (frag->fr_type) { switch (frag->fr_type) {
case rs_fill: case rs_fill:
case rs_align: case rs_align:
case rs_org: case rs_org:
@ -475,8 +482,9 @@ static void DEFUN(fill_section,(abfd, filehdr, file_cursor),
} }
bfd_write(buffer, s->s_size,1,abfd); bfd_write(buffer, s->s_size,1,abfd);
free(buffer);
*file_cursor += s->s_size; *file_cursor += s->s_size;
paddr += s->s_size; paddr += s->s_size;
} }
@ -525,10 +533,10 @@ DEFUN(coff_header_append,(abfd, filehdr, aouthdr),
} }
void char *
DEFUN(symbol_to_chars,(abfd, where, symbolP), DEFUN(symbol_to_chars,(abfd, where, symbolP),
bfd*abfd AND bfd*abfd AND
char **where AND char *where AND
symbolS *symbolP) symbolS *symbolP)
{ {
unsigned int numaux = symbolP->sy_symbol.ost_entry.n_numaux; unsigned int numaux = symbolP->sy_symbol.ost_entry.n_numaux;
@ -545,17 +553,19 @@ DEFUN(symbol_to_chars,(abfd, where, symbolP),
segment_info[S_GET_SEGMENT(symbolP)].scnhdr.s_paddr segment_info[S_GET_SEGMENT(symbolP)].scnhdr.s_paddr
+ S_GET_VALUE(symbolP)); + S_GET_VALUE(symbolP));
*where += bfd_coff_swap_sym_out(abfd, &symbolP->sy_symbol.ost_entry, where += bfd_coff_swap_sym_out(abfd, &symbolP->sy_symbol.ost_entry,
*where); where);
for (i = 0; i < numaux; i++) for (i = 0; i < numaux; i++)
{ {
*where += bfd_coff_swap_aux_out(abfd, where += bfd_coff_swap_aux_out(abfd,
&symbolP->sy_symbol.ost_auxent[i], &symbolP->sy_symbol.ost_auxent[i],
S_GET_DATA_TYPE(symbolP), S_GET_DATA_TYPE(symbolP),
S_GET_STORAGE_CLASS(symbolP), S_GET_STORAGE_CLASS(symbolP),
*where); where);
} }
return where;
} }
@ -643,6 +653,7 @@ stack* st;
st->pointer = 0; st->pointer = 0;
return (char*)0; return (char*)0;
} }
return st->data + st->pointer; return st->data + st->pointer;
} }
@ -745,7 +756,7 @@ int what;
unsigned int dim_index; unsigned int dim_index;
static void obj_coff_endef() { static void obj_coff_endef() {
symbolS *symbolP; symbolS *symbolP = 0;
/* DIM BUG FIX sac@cygnus.com */ /* DIM BUG FIX sac@cygnus.com */
dim_index =0; dim_index =0;
if (def_symbol_in_progress == NULL) { if (def_symbol_in_progress == NULL) {
@ -878,7 +889,12 @@ static void obj_coff_endef() {
if (SF_GET_FUNCTION(def_symbol_in_progress)) { if (SF_GET_FUNCTION(def_symbol_in_progress)) {
know(sizeof(def_symbol_in_progress) <= sizeof(long)); know(sizeof(def_symbol_in_progress) <= sizeof(long));
function_lineoff = c_line_new((long) def_symbol_in_progress,0, 0, &zero_address_frag); function_lineoff
= c_line_new((long)
def_symbol_in_progress,0, 0, &zero_address_frag);
SF_SET_PROCESS(def_symbol_in_progress); SF_SET_PROCESS(def_symbol_in_progress);
if (symbolP == NULL) { if (symbolP == NULL) {
@ -1413,8 +1429,8 @@ static void DEFUN(crawl_symbols,(headers, abfd),
* Find strings by crawling along symbol table chain. * Find strings by crawling along symbol table chain.
*/ */
w_strings(where) void DEFUN(w_strings,(where),
char *where; char *where)
{ {
symbolS *symbolP; symbolS *symbolP;
@ -1441,72 +1457,6 @@ char *where;
/* This is a copy from aout. All I do is neglect to actually build the symbol. */
static void obj_coff_stab(what)
int what;
{
char *string;
expressionS e;
int goof = 0; /* TRUE if we have aborted. */
int length;
int saved_type = 0;
long longint;
symbolS *symbolP = 0;
if (what == 's') {
string = demand_copy_C_string(&length);
SKIP_WHITESPACE();
if (*input_line_pointer == ',') {
input_line_pointer++;
} else {
as_bad("I need a comma after symbol's name");
goof = 1;
} /* better be a comma */
} /* skip the string */
/*
* Input_line_pointer->after ','. String->symbol name.
*/
if (!goof) {
if (get_absolute_expression_and_terminator(&longint) != ',') {
as_bad("I want a comma after the n_type expression");
goof = 1;
input_line_pointer--; /* Backup over a non-',' char. */
} /* on error */
} /* no error */
if (!goof) {
if (get_absolute_expression_and_terminator(&longint) != ',') {
as_bad("I want a comma after the n_other expression");
goof = 1;
input_line_pointer--; /* Backup over a non-',' char. */
} /* on error */
} /* no error */
if (!goof) {
get_absolute_expression();
if (what == 's' || what == 'n') {
if (*input_line_pointer != ',') {
as_bad("I want a comma after the n_desc expression");
goof = 1;
} else {
input_line_pointer++;
} /* on goof */
} /* not stabd */
} /* no error */
expression(&e);
if (goof) {
ignore_rest_of_line();
} else {
demand_empty_rest_of_line();
} /* on error */
} /* obj_coff_stab() */
static void static void
DEFUN(do_linenos_for,(abfd, file_cursor), DEFUN(do_linenos_for,(abfd, file_cursor),
@ -1524,7 +1474,7 @@ DEFUN(do_linenos_for,(abfd, file_cursor),
struct lineno_list *line_ptr ; struct lineno_list *line_ptr ;
struct external_lineno *buffer = struct external_lineno *buffer =
(struct external_lineno *)alloca(s->scnhdr.s_nlnno * LINESZ); (struct external_lineno *)xmalloc(s->scnhdr.s_nlnno * LINESZ);
struct external_lineno *dst= buffer; struct external_lineno *dst= buffer;
@ -1548,6 +1498,8 @@ DEFUN(do_linenos_for,(abfd, file_cursor),
s->scnhdr.s_lnnoptr = *file_cursor; s->scnhdr.s_lnnoptr = *file_cursor;
bfd_write(buffer, 1, s->scnhdr.s_nlnno* LINESZ, abfd); bfd_write(buffer, 1, s->scnhdr.s_nlnno* LINESZ, abfd);
free(buffer);
*file_cursor += s->scnhdr.s_nlnno * LINESZ; *file_cursor += s->scnhdr.s_nlnno * LINESZ;
} }
} }
@ -1590,7 +1542,7 @@ extern void DEFUN_VOID(write_object_file)
{ {
int i; int i;
struct frchain *frchain_ptr; struct frchain *frchain_ptr;
struct frag *frag_ptr;
struct internal_filehdr filehdr; struct internal_filehdr filehdr;
struct internal_aouthdr aouthdr; struct internal_aouthdr aouthdr;
unsigned long file_cursor; unsigned long file_cursor;
@ -1692,15 +1644,13 @@ extern void DEFUN_VOID(write_object_file)
{ {
unsigned int symtable_size = filehdr.f_nsyms * SYMESZ; unsigned int symtable_size = filehdr.f_nsyms * SYMESZ;
char *buffer1 = alloca(symtable_size); char *buffer1 = malloc(symtable_size + string_byte_count + 4);
char *buffer2 = alloca(string_byte_count+4);
char *ptr = buffer1; char *ptr = buffer1;
filehdr.f_symptr = bfd_tell(abfd); filehdr.f_symptr = bfd_tell(abfd);
w_symbols(abfd,&buffer1, symbol_rootP); w_symbols(abfd, buffer1, symbol_rootP);
bfd_write(ptr, 1, symtable_size, abfd); w_strings(buffer1 + symtable_size);
bfd_write(buffer1, 1,symtable_size + string_byte_count + 4, abfd);
w_strings(buffer2); free(buffer1);
bfd_write(buffer2, 1, string_byte_count, abfd);
} }
coff_header_append(abfd, &filehdr, &aouthdr); coff_header_append(abfd, &filehdr, &aouthdr);
@ -1798,12 +1748,12 @@ symbolS *normal;
SF_SET_DEBUG_FIELD(normal, SF_GET_DEBUG_FIELD(debug)); SF_SET_DEBUG_FIELD(normal, SF_GET_DEBUG_FIELD(debug));
} /* c_symbol_merge() */ } /* c_symbol_merge() */
int static int
c_line_new(symbol, paddr, line_number, frag) DEFUN(c_line_new,(symbol, paddr, line_number, frag),
symbolS *symbol; symbolS *symbol AND
long paddr; long paddr AND
unsigned short line_number; unsigned short line_number AND
fragS* frag; fragS* frag)
{ {
struct lineno_list* new_line = struct lineno_list* new_line =
(struct lineno_list *)xmalloc(sizeof(struct lineno_list)); (struct lineno_list *)xmalloc(sizeof(struct lineno_list));
@ -1887,10 +1837,11 @@ int idx;
return symbolP; return symbolP;
} /* c_section_symbol() */ } /* c_section_symbol() */
static void static void
DEFUN(w_symbols,(abfd, where, symbol_rootP), DEFUN(w_symbols,(abfd, where, symbol_rootP),
bfd *abfd AND bfd *abfd AND
char **where AND char *where AND
symbolS *symbol_rootP) symbolS *symbol_rootP)
{ {
symbolS *symbolP; symbolS *symbolP;
@ -1928,9 +1879,10 @@ symbolS *symbol_rootP)
bzero(symbolP->sy_symbol.ost_entry.n_name, SYMNMLEN); bzero(symbolP->sy_symbol.ost_entry.n_name, SYMNMLEN);
strncpy(symbolP->sy_symbol.ost_entry.n_name, temp, SYMNMLEN); strncpy(symbolP->sy_symbol.ost_entry.n_name, temp, SYMNMLEN);
} }
symbol_to_chars(abfd, where, symbolP); where = symbol_to_chars(abfd, where, symbolP);
S_SET_NAME(symbolP,temp); S_SET_NAME(symbolP,temp);
} }
} /* w_symbols() */ } /* w_symbols() */
static void DEFUN_VOID(obj_coff_lcomm) static void DEFUN_VOID(obj_coff_lcomm)

View File

@ -23,11 +23,9 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "targ-cpu.h" #include "targ-cpu.h"
#ifdef BFD_HEADERS
#include "bfd.h" #include "bfd.h"
extern bfd *stdoutput; /*extern bfd *stdoutput;*/
/* This internal_lineno crap is to stop namespace pollution from the /* This internal_lineno crap is to stop namespace pollution from the
bfd internal coff headerfile. */ bfd internal coff headerfile. */
@ -44,21 +42,8 @@ extern bfd *stdoutput;
#else #else
help me help me
#endif #endif
#else
#include "coff.gnu.h"
#endif
#ifdef USE_NATIVE_HEADERS
#include <filehdr.h>
#include <aouthdr.h>
#include <scnhdr.h>
#include <storclass.h>
#include <linenum.h>
#include <syms.h>
#include <reloc.h>
#include <sys/types.h>
#endif /* USE_NATIVE_HEADERS */
#if 0
/* Define some processor dependent values according to the processor we are /* Define some processor dependent values according to the processor we are
on. */ on. */
#if defined(TC_H8300) #if defined(TC_H8300)
@ -96,24 +81,18 @@ help me
you lose you lose
#endif #endif
#endif
#ifndef OBJ_COFF_MAX_AUXENTRIES #ifndef OBJ_COFF_MAX_AUXENTRIES
#define OBJ_COFF_MAX_AUXENTRIES 1 #define OBJ_COFF_MAX_AUXENTRIES 1
#endif /* OBJ_COFF_MAX_AUXENTRIES */ #endif /* OBJ_COFF_MAX_AUXENTRIES */
/*extern const short seg_N_TYPE[];*/
extern const segT N_TYPE_seg[]; extern const segT N_TYPE_seg[];
/* Magic number of paged executable. */ /* Magic number of paged executable. */
#define DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE 0x8300 #define DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE 0x8300
#ifndef BFD_HEADERS
/* Add these definitions to have a consistent convention for all the
types used in COFF format. */
#define AOUTHDR struct aouthdr
#define AOUTHDRSZ sizeof(AOUTHDR)
#endif
/* SYMBOL TABLE */ /* SYMBOL TABLE */
@ -483,31 +462,21 @@ typedef struct {
unsigned long pointer; unsigned long pointer;
} stack; } stack;
#ifdef __STDC__
char *stack_pop(stack *st);
char *stack_push(stack *st, char *element);
char *stack_top(stack *st);
stack *stack_init(unsigned long chunk_size, unsigned long element_size);
void c_dot_file_symbol(char *filename);
void obj_extra_stuff(object_headers *headers);
void stack_delete(stack *st);
#ifndef tc_headers_hook char *EXFUN(stack_pop,(stack *st));
void tc_headers_hook(object_headers *headers); char *EXFUN(stack_push,(stack *st, char *element));
#endif /* tc_headers_hook */ char *EXFUN(stack_top,(stack *st));
stack *EXFUN(stack_init,(unsigned long chunk_size, unsigned long element_size));
void EXFUN(c_dot_file_symbol,(char *filename));
void EXFUN(obj_extra_stuff,(object_headers *headers));
void EXFUN(stack_delete,(stack *st));
#ifndef tc_coff_symbol_emit_hook
void tc_coff_symbol_emit_hook(); /* really tc_coff_symbol_emit_hook(symbolS *symbolP) */
#endif /* tc_coff_symbol_emit_hook */
void c_section_header(
#ifdef BFD_HEADERS void EXFUN(c_section_header,(
struct internal_scnhdr *header, struct internal_scnhdr *header,
#else
SCNHDR *header,
#endif
char *name, char *name,
long core_address, long core_address,
long size, long size,
@ -516,22 +485,7 @@ void c_section_header(
long lineno_ptr, long lineno_ptr,
long reloc_number, long reloc_number,
long lineno_number, long lineno_number,
long alignment); long alignment));
#else /* __STDC__ */
char *stack_pop();
char *stack_push();
char *stack_top();
stack *stack_init();
void c_dot_file_symbol();
void c_section_header();
void obj_extra_stuff();
void stack_delete();
void tc_headers_hook();
void tc_coff_symbol_emit_hook();
#endif /* __STDC__ */
/* sanity check */ /* sanity check */