+Wed Oct 2 15:46:45 1996 Klaus Kaempf <kkaempf@progis.de>
+
+ 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 <ian@cygnus.com>
* cofflink.c (_bfd_coff_link_input_bfd): Don't crash if there is
PRIV(buf_size) = 0;
PRIV(rec_length) = 0;
PRIV(file_format) = FF_UNKNOWN;
- PRIV(filename) = NULL;
PRIV(fixup_done) = false;
PRIV(sections) = NULL;
}
PRIV(buf_size) = 0;
- if (PRIV(filename) != NULL)
- {
- free (PRIV(filename));
- PRIV(filename) = NULL;
- }
-
if (PRIV(output_buf) != 0)
{
free (PRIV(output_buf));
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);
}
}
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);
}
}
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 */
_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);
}
+/*-----------------------------------------------------------------------------*/
+/* 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 <sys/types.h>
+#include <time.h>
+
+ 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 <starlet.h>
+ 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);
_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);
/* 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, "<CASE:", 6) == 0)
+ {
+ PRIV(flag_hash_long_names) = symbol->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 */
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);
_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))
_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))
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
}
_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);
}
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;
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 <sys/types.h>
-#include <time.h>
-
- 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 <starlet.h>
- 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;
}
+
#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 */
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
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 */