binutils-gdb/bfd/vmsutil.c

263 lines
6.2 KiB
C
Raw Normal View History

* include/elf/ia64.h (SHT_IA_64_VMS_DISPLAY_NAME_INFO, EF_IA_64_ARCHVER_1): New macros. Minor reformatting. * bfd/Makefile.am (BFD32_BACKENDS): Add new object vmsutil.lo (BFD32_BACKENDS_CFILES): Add new file vmsutil.c (vmsutil.lo): Add dependency rule * bfd/Makefile.in: Regenerate * bfd/config.bfd (ia64*-*-*vms*): Add case. * bfd/configure.in (bfd_elf64_ia64_vms_vec): Add case. * bfd/configure: Regenerate * bfd/vmsutil.[ch]: New files * bfd/elf-bfd.h (struct bfd_elf_special_section): Change type of attr to bfd_vma. * bfd/elfxx-ia64.c (elfNN_vms_post_process_headers, elfNN_vms_section_processing, elfNN_vms_final_write_processing, elfNN_vms_close_and_cleanup, elfNN_vms_section_from_shdr, elfNN_vms_object_p): New functions * bfd/targets.c (bfd_elf64_ia64_vms_vec): New target. * gas/configure.tgt(ia64-*-*vms*): New target. * gas/dwarf2dbg.h (dwarf2_loc_mark_labels): Make extern. * gas/tc.h (md_number_to_chars): Declare iff undefined. * gas/config/obj-elf.c (obj_elf_change_section): Change type of arg attr to bfd_vma. (obj_elf_parse_section_letters): Return a bfd_vma. Change type of variables attr, md_attr to bfd_vma. (obj_elf_section_word): Likewise. (obj_elf_section): Change type of variable attr to bfd_vma * gas/config/obj-elf.h (obj_elf_change_section): Change type of arg attr to bfd_vma * gas/config/tc-ia64.c (bfdver.h,time.h): Include. (ia64_elf_section_letter): Now returns a bfd_vma. Handle VMS specific attributes. (ia64_elf_section_flags): Arg attr now a bfd_vma. (ia64_init): Don't turn on dependency checking for VMS. (ia64_target_format): Check for VMS flag bit. (do_alias): Hande decc$ functions. (get_vms_time): New function. (ia64_vms_note): New function. * gas/config/tc-ia64.h (ia64_elf_section_letter): Now returns a bfd_vma. (ia64_elf_section_flags): Arg attr now a bfd_vma. (tc_init_after_args): Define for VMS. * gas/config/tc-alpha.c (alpha_elf_section_letter): Return a bfd_vma. (alpha_elf_section_flags): Change type of arg attr to bfd_vma. * gas/config/tc-alpha.h: Likewise. * gas/config/tc-i386.c (x86_64_section_letter): Return a bfd_vma. (x86_64_section_word): Return a bfd_vma. * gas/config/tc-i386.h: Likewise. * gas/config/tc-ip2k.c (ip2k_elf_section_flags): Change type of arg attr to bfd_vma. * gas/config/tc-ip2k.h: Likewise. * gas/config/tc-mep.c (mep_elf_section_letter): Return a bfd_vma. (mep_elf_section_flags): Change type of arg attr to bfd_vma. * gas/config/tc-mep.h: Likewise. * gas/config/tc-ppc.c (ppc_section_letter): Return a bfd_vma. (ppc_section_word): Return a bfd_vma. (ppc_section_flags): Change type of arg attr to bfd_vma. * gas/config/tc-ppc.h: Likewise. * gas/config/te-vms.h (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR, DWAR2_FILE_TIME_NAME, DWARF2_FILE_SIZE_NAME, DWARF2_FILEN_NAME): New file with new macros * gas/dwarf2dbg.c (get_filenum, out_file_list): Default and call new macros.
2009-01-15 20:42:52 +08:00
/* vmsutil.c -- Utilities for VMS.
Copyright 2009 Free Software Foundation, Inc.
Written by Douglas B Rupp <rupp@gnat.com>
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 3 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
#include "ansidecl.h"
#include "vmsutil.h"
#ifdef VMS
#define __NEW_STARLET 1
#include <vms/starlet.h>
#include <vms/rms.h>
#include <vms/atrdef.h>
#include <vms/fibdef.h>
#include <vms/stsdef.h>
#include <vms/iodef.h>
#include <vms/fatdef.h>
#include <errno.h>
#include <vms/descrip.h>
#include <string.h>
#include <unixlib.h>
#define MAXPATH 256
/* Descrip.h doesn't have everything... */
typedef struct fibdef * __fibdef_ptr32 __attribute__ (( mode (SI) ));
struct dsc$descriptor_fib
{
unsigned int fib$l_len;
__fibdef_ptr32 fib$l_addr;
};
/* I/O Status Block. */
struct IOSB
{
unsigned short status, count;
unsigned int devdep;
};
static char *tryfile;
/* Variable length string. */
struct vstring
{
short length;
char string[NAM$C_MAXRSS+1];
};
static char filename_buff [MAXPATH];
static char vms_filespec [MAXPATH];
/* Callback function for filespec style conversion. */
static int
translate_unix (char *name, int type ATTRIBUTE_UNUSED)
{
strncpy (filename_buff, name, MAXPATH);
filename_buff [MAXPATH - 1] = (char) 0;
return 0;
}
/* Wrapper for DECC function that converts a Unix filespec
to VMS style filespec. */
static char *
to_vms_file_spec (char *filespec)
{
strncpy (vms_filespec, "", MAXPATH);
decc$to_vms (filespec, translate_unix, 1, 1);
strncpy (vms_filespec, filename_buff, MAXPATH);
vms_filespec [MAXPATH - 1] = (char) 0;
return vms_filespec;
}
#else
#include <sys/stat.h>
#include <time.h>
#define VMS_EPOCH_OFFSET 35067168000000000LL
#define VMS_GRANULARITY_FACTOR 10000000
#endif
/* Return VMS file date, size, format, version given a name. */
int
vms_file_stats_name (const char *filename,
long long *cdt,
long *siz,
char *rfo,
int *ver)
{
#ifdef VMS
struct FAB fab;
struct NAM nam;
unsigned long long create;
FAT recattr;
char ascnamebuff [256];
ATRDEF atrlst[]
= {
{ ATR$S_CREDATE, ATR$C_CREDATE, &create },
{ ATR$S_RECATTR, ATR$C_RECATTR, &recattr },
{ ATR$S_ASCNAME, ATR$C_ASCNAME, &ascnamebuff },
{ 0, 0, 0}
};
FIBDEF fib;
struct dsc$descriptor_fib fibdsc = {sizeof (fib), (void *) &fib};
struct IOSB iosb;
long status;
unsigned short chan;
struct vstring file;
struct dsc$descriptor_s filedsc
= {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) file.string};
struct vstring device;
struct dsc$descriptor_s devicedsc
= {NAM$C_MAXRSS, DSC$K_DTYPE_T, DSC$K_CLASS_S, (void *) device.string};
struct vstring result;
struct dsc$descriptor_s resultdsc
= {NAM$C_MAXRSS, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, (void *) result.string};
if (strcmp (filename, "<internal>") == 0
|| strcmp (filename, "<built-in>") == 0)
{
if (cdt)
*cdt = 0;
if (siz)
*siz = 0;
if (rfo)
*rfo = 0;
if (ver)
*ver = 0;
return 0;
}
tryfile = to_vms_file_spec ((char *) filename);
/* Allocate and initialize a FAB and NAM structures. */
fab = cc$rms_fab;
nam = cc$rms_nam;
nam.nam$l_esa = file.string;
nam.nam$b_ess = NAM$C_MAXRSS;
nam.nam$l_rsa = result.string;
nam.nam$b_rss = NAM$C_MAXRSS;
fab.fab$l_fna = tryfile;
fab.fab$b_fns = strlen (tryfile);
fab.fab$l_nam = &nam;
/* Validate filespec syntax and device existence. */
status = SYS$PARSE (&fab, 0, 0);
if ((status & 1) != 1)
return 1;
file.string[nam.nam$b_esl] = 0;
/* Find matching filespec. */
status = SYS$SEARCH (&fab, 0, 0);
if ((status & 1) != 1)
return 1;
file.string[nam.nam$b_esl] = 0;
result.string[result.length=nam.nam$b_rsl] = 0;
/* Get the device name and assign an IO channel. */
strncpy (device.string, nam.nam$l_dev, nam.nam$b_dev);
devicedsc.dsc$w_length = nam.nam$b_dev;
chan = 0;
status = SYS$ASSIGN (&devicedsc, &chan, 0, 0, 0);
if ((status & 1) != 1)
return 1;
/* Initialize the FIB and fill in the directory id field. */
memset (&fib, 0, sizeof (fib));
fib.fib$w_did[0] = nam.nam$w_did[0];
fib.fib$w_did[1] = nam.nam$w_did[1];
fib.fib$w_did[2] = nam.nam$w_did[2];
fib.fib$l_acctl = 0;
fib.fib$l_wcc = 0;
strcpy (file.string, (strrchr (result.string, ']') + 1));
filedsc.dsc$w_length = strlen (file.string);
result.string[result.length = 0] = 0;
/* Open and close the file to fill in the attributes. */
status
= SYS$QIOW (0, chan, IO$_ACCESS|IO$M_ACCESS, &iosb, 0, 0,
&fibdsc, &filedsc, &result.length, &resultdsc, &atrlst, 0);
if ((status & 1) != 1)
return 1;
if ((iosb.status & 1) != 1)
return 1;
result.string[result.length] = 0;
status = SYS$QIOW (0, chan, IO$_DEACCESS, &iosb, 0, 0, &fibdsc, 0, 0, 0,
&atrlst, 0);
if ((status & 1) != 1)
return 1;
if ((iosb.status & 1) != 1)
return 1;
/* Deassign the channel and exit. */
status = SYS$DASSGN (chan);
if ((status & 1) != 1)
return 1;
if (cdt) *cdt = create;
if (siz) *siz = (512 * 65536 * recattr.fat$w_efblkh) +
(512 * (recattr.fat$w_efblkl - 1)) +
recattr.fat$w_ffbyte;
if (rfo) *rfo = recattr.fat$v_rtype;
if (ver) *ver = strtol (strrchr (ascnamebuff, ';')+1, 0, 10);
return 0;
#else
struct stat buff;
if ((stat (filename, &buff)) != 0)
return 1;
if (cdt)
{
*cdt = (long long) (buff.st_mtime * VMS_GRANULARITY_FACTOR)
* include/elf/ia64.h (SHT_IA_64_VMS_DISPLAY_NAME_INFO, EF_IA_64_ARCHVER_1): New macros. Minor reformatting. * bfd/Makefile.am (BFD32_BACKENDS): Add new object vmsutil.lo (BFD32_BACKENDS_CFILES): Add new file vmsutil.c (vmsutil.lo): Add dependency rule * bfd/Makefile.in: Regenerate * bfd/config.bfd (ia64*-*-*vms*): Add case. * bfd/configure.in (bfd_elf64_ia64_vms_vec): Add case. * bfd/configure: Regenerate * bfd/vmsutil.[ch]: New files * bfd/elf-bfd.h (struct bfd_elf_special_section): Change type of attr to bfd_vma. * bfd/elfxx-ia64.c (elfNN_vms_post_process_headers, elfNN_vms_section_processing, elfNN_vms_final_write_processing, elfNN_vms_close_and_cleanup, elfNN_vms_section_from_shdr, elfNN_vms_object_p): New functions * bfd/targets.c (bfd_elf64_ia64_vms_vec): New target. * gas/configure.tgt(ia64-*-*vms*): New target. * gas/dwarf2dbg.h (dwarf2_loc_mark_labels): Make extern. * gas/tc.h (md_number_to_chars): Declare iff undefined. * gas/config/obj-elf.c (obj_elf_change_section): Change type of arg attr to bfd_vma. (obj_elf_parse_section_letters): Return a bfd_vma. Change type of variables attr, md_attr to bfd_vma. (obj_elf_section_word): Likewise. (obj_elf_section): Change type of variable attr to bfd_vma * gas/config/obj-elf.h (obj_elf_change_section): Change type of arg attr to bfd_vma * gas/config/tc-ia64.c (bfdver.h,time.h): Include. (ia64_elf_section_letter): Now returns a bfd_vma. Handle VMS specific attributes. (ia64_elf_section_flags): Arg attr now a bfd_vma. (ia64_init): Don't turn on dependency checking for VMS. (ia64_target_format): Check for VMS flag bit. (do_alias): Hande decc$ functions. (get_vms_time): New function. (ia64_vms_note): New function. * gas/config/tc-ia64.h (ia64_elf_section_letter): Now returns a bfd_vma. (ia64_elf_section_flags): Arg attr now a bfd_vma. (tc_init_after_args): Define for VMS. * gas/config/tc-alpha.c (alpha_elf_section_letter): Return a bfd_vma. (alpha_elf_section_flags): Change type of arg attr to bfd_vma. * gas/config/tc-alpha.h: Likewise. * gas/config/tc-i386.c (x86_64_section_letter): Return a bfd_vma. (x86_64_section_word): Return a bfd_vma. * gas/config/tc-i386.h: Likewise. * gas/config/tc-ip2k.c (ip2k_elf_section_flags): Change type of arg attr to bfd_vma. * gas/config/tc-ip2k.h: Likewise. * gas/config/tc-mep.c (mep_elf_section_letter): Return a bfd_vma. (mep_elf_section_flags): Change type of arg attr to bfd_vma. * gas/config/tc-mep.h: Likewise. * gas/config/tc-ppc.c (ppc_section_letter): Return a bfd_vma. (ppc_section_word): Return a bfd_vma. (ppc_section_flags): Change type of arg attr to bfd_vma. * gas/config/tc-ppc.h: Likewise. * gas/config/te-vms.h (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR, DWAR2_FILE_TIME_NAME, DWARF2_FILE_SIZE_NAME, DWARF2_FILEN_NAME): New file with new macros * gas/dwarf2dbg.c (get_filenum, out_file_list): Default and call new macros.
2009-01-15 20:42:52 +08:00
+ VMS_EPOCH_OFFSET;
}
if (siz)
*siz = buff.st_size;
if (rfo)
*rfo = 2; /* Stream LF format. */
if (ver)
*ver = 0;
return 0;
#endif
}