From: Ian Lance Taylor Date: Wed, 2 Oct 1996 19:49:01 +0000 (+0000) Subject: Wed Oct 2 15:46:45 1996 Klaus Kaempf X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bf53bd9faab2babf447b569a03f04663abece21c;p=binutils-gdb.git Wed Oct 2 15:46:45 1996 Klaus Kaempf openVMS/Alpha: Provide filename and case_hack flags via symbol table from gas. Add case_hack code for symbol output from vax/vms. * evax-alpha.c (evax_initialize): Remove filename handling, filename is provided via symbol table. (evax_get_symtab): Use local symbol count when setting up table. * evax-egsd.c (_bfd_evax_slurp_egsd): Print correct name when debugging. (_bfd_evax_write_egsd): Skip file name symbol. * evax-emh.c (get_vms_time_string): Local function now. (_bfd_evax_write_emh): Extract source filename and case_hack flags from symbol table. * evax_write_etir (_bfd_evax_write_etir): Pass all symbol names through _bfd_evax_case_hack_symbol. * evax-misc.c (hash_string, _bfd_evax_case_hack_symbol): New functions. (_bfd_evax_basename): Removed. (_bfd_get_vms_time_string): Moved to evax-emh.c. * evax.h (evax_private_data_struct): Remove filename. (flag_hash_long_names, flag_show_after_trunc, flag_no_hash_mixed_case, vms_name_mapping): New flags for vms_case_hack. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 45761e5717a..a22a7f0ec1e 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,28 @@ +Wed Oct 2 15:46:45 1996 Klaus Kaempf + + openVMS/Alpha: Provide filename and case_hack flags via + symbol table from gas. + Add case_hack code for symbol output from vax/vms. + * evax-alpha.c (evax_initialize): Remove filename handling, + filename is provided via symbol table. + (evax_get_symtab): Use local symbol count when setting up table. + * evax-egsd.c (_bfd_evax_slurp_egsd): Print correct name when + debugging. + (_bfd_evax_write_egsd): Skip file name symbol. + * evax-emh.c (get_vms_time_string): Local function now. + (_bfd_evax_write_emh): Extract source filename and case_hack flags + from symbol table. + * evax_write_etir (_bfd_evax_write_etir): Pass all symbol names + through _bfd_evax_case_hack_symbol. + * evax-misc.c (hash_string, _bfd_evax_case_hack_symbol): New + functions. + (_bfd_evax_basename): Removed. + (_bfd_get_vms_time_string): Moved to evax-emh.c. + * evax.h (evax_private_data_struct): Remove filename. + (flag_hash_long_names, flag_show_after_trunc, + flag_no_hash_mixed_case, vms_name_mapping): New flags for + vms_case_hack. + Wed Oct 2 12:02:02 1996 Ian Lance Taylor * cofflink.c (_bfd_coff_link_input_bfd): Don't crash if there is diff --git a/bfd/evax-alpha.c b/bfd/evax-alpha.c index 20a5a979fd2..a13ae6eb97e 100644 --- a/bfd/evax-alpha.c +++ b/bfd/evax-alpha.c @@ -196,7 +196,6 @@ evax_initialize (abfd) PRIV(buf_size) = 0; PRIV(rec_length) = 0; PRIV(file_format) = FF_UNKNOWN; - PRIV(filename) = NULL; PRIV(fixup_done) = false; PRIV(sections) = NULL; @@ -530,12 +529,6 @@ evax_close_and_cleanup (abfd) } PRIV(buf_size) = 0; - if (PRIV(filename) != NULL) - { - free (PRIV(filename)); - PRIV(filename) = NULL; - } - if (PRIV(output_buf) != 0) { free (PRIV(output_buf)); @@ -1010,9 +1003,9 @@ evax_get_symtab (abfd, symbols) PRIV(symcache) = symbols; bfd_hash_traverse(PRIV(evax_symbol_table), copy_symbols, (PTR)abfd); - symbols[bfd_get_symcount(abfd)] = NULL; + symbols[PRIV(egsd_sym_count)] = NULL; - return bfd_get_symcount(abfd); + return PRIV(egsd_sym_count); } diff --git a/bfd/evax-egsd.c b/bfd/evax-egsd.c index f5275a98567..f766ecb7391 100644 --- a/bfd/evax-egsd.c +++ b/bfd/evax-egsd.c @@ -318,11 +318,12 @@ _bfd_evax_slurp_egsd (abfd) } else /* symbol reference */ { -#if EVAX_DEBUG - evax_debug(3, "egsd sym ref #%d (%s, %04x=%s)\n", abfd->symcount, evax_rec+9, old_flags, flag2str(gsyflagdesc, old_flags)); -#endif symbol->name = _bfd_evax_save_counted_string ((char *)evax_rec+8); +#if EVAX_DEBUG + evax_debug(3, "egsd sym ref #%d (%s, %04x=%s)\n", abfd->symcount, + symbol->name, old_flags, flag2str(gsyflagdesc, old_flags)); +#endif symbol->section = bfd_make_section (abfd, BFD_UND_SECTION_NAME); } @@ -496,6 +497,9 @@ _bfd_evax_write_egsd (abfd) } old_flags = symbol->flags; + if (old_flags & BSF_FILE) + continue; + if (((old_flags & BSF_GLOBAL) == 0) /* not xdef */ && (!bfd_is_und_section (symbol->section))) /* and not xref */ continue; /* dont output */ @@ -551,24 +555,7 @@ _bfd_evax_write_egsd (abfd) _bfd_evax_output_long (abfd, symbol->section->index);/* L_PSINDX, FIXME */ } } - if (strlen ((char *)symbol->name) > 198) - { - (*_bfd_error_handler) ("Name '%s' too long\n", symbol->name); - abort (); - } - nptr = (char *)symbol->name; - uptr = uname; - while (*nptr) - { - if (islower (*nptr)) - *uptr = toupper (*nptr); - else - *uptr = *nptr; - uptr++; - nptr++; - } - *uptr = 0; - _bfd_evax_output_counted (abfd, uname); + _bfd_evax_output_counted (abfd, _bfd_evax_case_hack_symbol (abfd, symbol->name)); _bfd_evax_output_flush (abfd); diff --git a/bfd/evax-emh.c b/bfd/evax-emh.c index 69f7e0be91b..b59023b5a48 100644 --- a/bfd/evax-emh.c +++ b/bfd/evax-emh.c @@ -124,13 +124,62 @@ _bfd_evax_slurp_emh (abfd) } +/*-----------------------------------------------------------------------------*/ +/* Output routines. */ + + +/* Manufacure a VMS like time on a unix based system. + stolen from obj-vms.c */ + +static unsigned char * +get_vms_time_string () +{ + static unsigned char tbuf[18]; +#ifndef VMS +#include +#include + + char *pnt; + time_t timeb; + time (&timeb); + pnt = ctime (&timeb); + pnt[3] = 0; + pnt[7] = 0; + pnt[10] = 0; + pnt[16] = 0; + pnt[24] = 0; + sprintf (tbuf, "%2s-%3s-%s %s", pnt + 8, pnt + 4, pnt + 20, pnt + 11); +#else +#include + struct + { + int Size; + unsigned char *Ptr; + } Descriptor; + Descriptor.Size = 17; + Descriptor.Ptr = tbuf; + sys$asctim (0, &Descriptor, 0, 0); +#endif /* not VMS */ + +#if EVAX_DEBUG + evax_debug (6, "vmstimestring:'%s'\n", tbuf); +#endif + + return tbuf; +} + + /* write object header for bfd abfd */ int _bfd_evax_write_emh (abfd) bfd *abfd; { - char *name; + asymbol *symbol; + int symnum; + int had_case = 0; + int had_file = 0; + #if EVAX_DEBUG evax_debug (2, "evax_write_emh(%p)\n", abfd); @@ -145,16 +194,14 @@ _bfd_evax_write_emh (abfd) _bfd_evax_output_long (abfd, 0); _bfd_evax_output_long (abfd, 0); _bfd_evax_output_long (abfd, MAX_OUTREC_SIZE); - if (bfd_get_filename (abfd) != NULL) - { - name = strdup (bfd_get_filename (abfd)); - _bfd_evax_output_counted (abfd, _bfd_evax_basename (name)); - } + + if (bfd_get_filename (abfd) != 0) + _bfd_evax_output_counted (abfd, bfd_get_filename (abfd)); else _bfd_evax_output_counted (abfd, "NONAME"); + _bfd_evax_output_counted (abfd, BFD_VERSION); - _bfd_evax_output_dump (abfd, (unsigned char *)_bfd_get_vms_time_string (), - 17); + _bfd_evax_output_dump (abfd, get_vms_time_string (), 17); _bfd_evax_output_fill (abfd, 0, 17); _bfd_evax_output_flush (abfd); @@ -167,10 +214,38 @@ _bfd_evax_write_emh (abfd) /* SRC */ _bfd_evax_output_begin (abfd, EOBJ_S_C_EMH, EMH_S_C_SRC); - if (PRIV(filename) != 0) - _bfd_evax_output_dump (abfd, (unsigned char *)PRIV(filename), strlen (PRIV(filename))); - else - _bfd_evax_output_dump (abfd, (unsigned char *)"noname", 6); + + for (symnum = 0; symnum < abfd->symcount; symnum++) + { + symbol = abfd->outsymbols[symnum]; + + if (symbol->flags & BSF_FILE) + { + char *s; + + if (strncmp ((char *)symbol->name, "name[6] - '0'; + PRIV(flag_show_after_trunc) = symbol->name[7] - '0'; + PRIV(flag_no_hash_mixed_case) = symbol->name[8] - '0'; + PRIV(vms_name_mapping) = symbol->name[9] - '0'; + + if (had_file) + break; + had_case = 1; + continue; + } + + _bfd_evax_output_dump (abfd, (char *)symbol->name, strlen (symbol->name)); + if (had_case) + break; + had_file = 1; + } + } + + if (symnum == abfd->symcount) + _bfd_evax_output_dump (abfd, "noname", 6); + _bfd_evax_output_flush (abfd); /* TTL */ diff --git a/bfd/evax-etir.c b/bfd/evax-etir.c index cb186f11e96..067af829bb9 100644 --- a/bfd/evax-etir.c +++ b/bfd/evax-etir.c @@ -1121,8 +1121,6 @@ _bfd_evax_write_etir (abfd) asection *section; evax_section *sptr; int nextoffset; - char uname[200]; - char *nptr, *uptr; #if EVAX_DEBUG evax_debug (2, "evax_write_etir(%p)\n", abfd); @@ -1247,19 +1245,8 @@ _bfd_evax_write_etir (abfd) _bfd_evax_output_begin (abfd, ETIR_S_C_STO_GBL_LW, -1); - uptr = uname; - nptr = (char *)sym->name; - while (*nptr) - { - if (islower (*nptr)) - *uptr = toupper (*nptr); - else - *uptr = *nptr; - nptr++; - uptr++; - } - *uptr = 0; - _bfd_evax_output_counted (abfd, uname); + _bfd_evax_output_counted (abfd, + _bfd_evax_case_hack_symbol (abfd, sym->name)); _bfd_evax_output_flush (abfd); } else if (bfd_is_abs_section (sym->section)) @@ -1324,19 +1311,8 @@ _bfd_evax_write_etir (abfd) _bfd_evax_output_begin (abfd, ETIR_S_C_STO_GBL, -1); - uptr = uname; - nptr = (char *)sym->name; - while (*nptr) - { - if (islower (*nptr)) - *uptr = toupper (*nptr); - else - *uptr = *nptr; - nptr++; - uptr++; - } - *uptr = 0; - _bfd_evax_output_counted (abfd, uname); + _bfd_evax_output_counted (abfd, + _bfd_evax_case_hack_symbol (abfd, sym->name)); _bfd_evax_output_flush (abfd); } else if (bfd_is_abs_section (sym->section)) @@ -1397,20 +1373,8 @@ _bfd_evax_write_etir (abfd) evax_output_begin(abfd, ETIR_S_C_STO_HINT_GBL, -1); evax_output_long(abfd, (unsigned long)(sec->index)); evax_output_quad(abfd, (uquad)addr); - uptr = uname; - nptr = (char *)(*(*rptr)->sym_ptr_ptr)->name; - while (*nptr) - { - if (islower (*nptr)) - *uptr = toupper (*nptr); - else - *uptr = *nptr; - nptr++; - uptr++; - } - *uptr = 0; - evax_output_counted(abfd, uname); + evax_output_counted(abfd, _bfd_evax_case_hack_symbol (abfd, sym->name)); evax_output_flush(abfd); #endif } @@ -1447,19 +1411,8 @@ _bfd_evax_write_etir (abfd) _bfd_evax_output_long (abfd, (unsigned long)PRIV(evax_linkage_index)); PRIV(evax_linkage_index) += 2; - uptr = uname; - nptr = (char *)(*(*rptr)->sym_ptr_ptr)->name; - while (*nptr) - { - if (islower (*nptr)) - *uptr = toupper (*nptr); - else - *uptr = *nptr; - nptr++; - uptr++; - } - *uptr = 0; - _bfd_evax_output_counted (abfd, uname); + _bfd_evax_output_counted (abfd, + _bfd_evax_case_hack_symbol (abfd, sym->name)); _bfd_evax_output_byte (abfd, 0); _bfd_evax_output_flush (abfd); } diff --git a/bfd/evax-misc.c b/bfd/evax-misc.c index 3da89997805..ce72ea4fa34 100644 --- a/bfd/evax-misc.c +++ b/bfd/evax-misc.c @@ -565,7 +565,7 @@ add_new_contents (abfd, section) newptr = (evax_section *) bfd_malloc (sizeof (evax_section)); if (newptr == (evax_section *) NULL) return NULL; - newptr->contents = (unsigned char *) bfd_alloc (abfd, section->_raw_size); + newptr->contents = (unsigned char *) bfd_alloc (abfd, (int)section->_raw_size); if (newptr->contents == (unsigned char *)NULL) return NULL; newptr->offset = 0; @@ -952,98 +952,195 @@ _bfd_evax_output_fill (abfd, value, count) return; } -/*-----------------------------------------------------------------------------*/ +/* this hash routine borrowed from GNU-EMACS, and strengthened slightly ERY*/ -/* Return basename (stripped of directory information) of filename */ +static int +hash_string (ptr) + const char *ptr; +{ + register const unsigned char *p = (unsigned char *) ptr; + register const unsigned char *end = p + strlen (ptr); + register unsigned char c; + register int hash = 0; + while (p != end) + { + c = *p++; + hash = ((hash << 3) + (hash << 15) + (hash >> 28) + c); + } + return hash; +} + +/* Generate a Case-Hacked VMS symbol name (limited to 64 chars). */ char * -_bfd_evax_basename (name) - char *name; +_bfd_evax_case_hack_symbol (abfd, in) + bfd *abfd; + const char *in; { - char *ptr; + long int init; + long int result; + char *pnt = 0; + char *new_name; + const char *old_name; + int i; + int destructor = 0; /*hack to allow for case sens in a destructor*/ + int truncate = 0; + int case_hack_bits = 0; + int saw_dollar = 0; + static char hex_table[16] = + {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + + static char outbuf[65]; + char *out = outbuf; #if EVAX_DEBUG - evax_debug (6, "_bfd_evax_basename %s -> ", name); + evax_debug(4, "_bfd_evax_case_hack_symbol \"%s\"\n", in); #endif -#ifndef VMS - /* assume unix host */ - ptr = strrchr (name, '.'); - if (ptr) - *ptr = 0; - ptr = strrchr (name, '/'); - if (ptr) - *ptr++ = 0; - else - ptr = name; -#else - /* assume vms host */ - ptr = strrchr (name, '.'); - if (ptr) - { - *ptr = 0; - ptr = name; - } - else +#if 0 + /* Kill any leading "_". */ /* Why ? FIXME ! */ + + if ((in[0] == '_') && ((in[1] > '9') || (in[1] < '0'))) + in++; +#endif + + new_name = out; /* save this for later. */ + + /* We may need to truncate the symbol, save the hash for later. */ + + result = (strlen (in) > 56) ? hash_string (in) : 0; + + old_name = in; + + /* Do the case conversion. */ + + i = 56; /* Maximum of 56 chars */ + + while (*in && (--i >= 0)) { - ptr = strrchr (name, ']'); - if (ptr) - *ptr++ = 0; - else + case_hack_bits <<= 1; + if (*in == '$') + saw_dollar = 1; + if ((destructor == 1) && (i == 54)) + saw_dollar = 0; + switch (PRIV(vms_name_mapping)) { - ptr = strrchr (name, ':'); - if (ptr) - *ptr++ = 0; - else - ptr = name; + case 0: + if (isupper (*in)) { + *out++ = *in++; + case_hack_bits |= 1; + } else { + *out++ = islower (*in) ? toupper (*in++) : *in++; + } + break; + case 3: *out++ = *in++; + break; + case 2: + if (islower (*in)) { + *out++ = *in++; + } else { + *out++ = isupper (*in) ? tolower (*in++) : *in++; + } + break; } } -#endif -#if EVAX_DEBUG - evax_debug (6, "%s\n", ptr); -#endif + /* if we saw a dollar sign, we don't do case hacking. */ + + if (PRIV(flag_no_hash_mixed_case) || saw_dollar) + case_hack_bits = 0; - return ptr; + /* if we have more than 56 characters and everything is lowercase + we can insert the full 64 characters. */ + + if (*in) + { + /* We have more than 56 characters + If we must add the case hack, then we have truncated the str. */ + pnt = out; + truncate = 1; + if (case_hack_bits == 0) + { + /* And so far they are all lower case: + Check up to 8 more characters + and ensure that they are lowercase. */ + + for (i = 0; (in[i] != 0) && (i < 8); i++) + if (isupper (in[i]) && !saw_dollar && !PRIV(flag_no_hash_mixed_case)) + break; + + if (in[i] == 0) + truncate = 0; + + if ((i == 8) || (in[i] == 0)) + { + /* They are: Copy up to 64 characters + to the output string. */ + + i = 8; + while ((--i >= 0) && (*in)) + { + switch (PRIV(vms_name_mapping)) + { + case 0: + *out++ = islower (*in) ? toupper (*in++) : *in++; + break; + case 3: + *out++ = *in++; + break; + case 2: + *out++ = isupper (*in) ? tolower (*in++) : *in++; + break; + } + } + } + } } + /* If there were any uppercase characters in the name we + take on the case hacking string. */ -/* Manufacure a VMS like time on a unix based system. - stolen from obj-vms.c */ + /* Old behavior for regular GNU-C compiler */ -char * -_bfd_get_vms_time_string () -{ - static char tbuf[18]; -#ifndef VMS -#include -#include - - char *pnt; - time_t timeb; - time (&timeb); - pnt = ctime (&timeb); - pnt[3] = 0; - pnt[7] = 0; - pnt[10] = 0; - pnt[16] = 0; - pnt[24] = 0; - sprintf (tbuf, "%2s-%3s-%s %s", pnt + 8, pnt + 4, pnt + 20, pnt + 11); -#else -#include - struct - { - int Size; - char *Ptr; - } Descriptor; - Descriptor.Size = 17; - Descriptor.Ptr = tbuf; - sys$asctim (0, &Descriptor, 0, 0); -#endif /* not VMS */ + if (!PRIV(flag_hash_long_names)) + truncate = 0; + + if ((case_hack_bits != 0) || (truncate == 1)) + { + if (truncate == 0) + { + *out++ = '_'; + for (i = 0; i < 6; i++) + { + *out++ = hex_table[case_hack_bits & 0xf]; + case_hack_bits >>= 4; + } + *out++ = 'X'; + } + else + { + out = pnt; /* Cut back to 56 characters maximum */ + *out++ = '_'; + for (i = 0; i < 7; i++) + { + init = result & 0x01f; + *out++ = (init < 10) ? ('0' + init) : ('A' + init - 10); + result = result >> 5; + } + } + } + + *out = 0; #if EVAX_DEBUG - evax_debug (6, "vmstimestring:'%s'\n", tbuf); + evax_debug(4, "--> [%d]\"%s\"\n", strlen (outbuf), outbuf); #endif - return tbuf; + if (truncate == 1 + && PRIV(flag_hash_long_names) + && PRIV(flag_show_after_trunc)) + printf ("Symbol %s replaced by %s\n", old_name, new_name); + + return outbuf; } + diff --git a/bfd/evax.h b/bfd/evax.h index 7d6c9b4ec42..be627657cc1 100644 --- a/bfd/evax.h +++ b/bfd/evax.h @@ -279,7 +279,6 @@ struct location_struct { #define EVAX_SECTION_COUNT 32 struct evax_private_data_struct { - char *filename; /* Filename of object file */ boolean fixup_done; /* Flag to indicate if all section pointers and PRIV(sections) are set up correctly */ @@ -328,6 +327,11 @@ struct evax_private_data_struct { int evax_linkage_index; + /* see tc-alpha.c of gas for a description. */ + int flag_hash_long_names; /* -+ */ + int flag_show_after_trunc; /* -H */ + int flag_no_hash_mixed_case; /* -h NUM */ + char vms_name_mapping; }; #define PRIV(name) ((struct evax_private_data_struct *)abfd->tdata.any)->name @@ -373,7 +377,6 @@ extern void _bfd_evax_output_counted PARAMS ((bfd *abfd, char *value)); extern void _bfd_evax_output_dump PARAMS ((bfd *abfd, unsigned char *data, int length)); extern void _bfd_evax_output_fill PARAMS ((bfd *abfd, int value, int length)); -extern char *_bfd_get_vms_time_string PARAMS ((void)); -extern char *_bfd_evax_basename PARAMS ((char *name)); +extern char *_bfd_evax_case_hack_symbol PARAMS ((bfd *abfd, const char *in)); #endif /* EVAX_H */