diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index cbfe6afe9f..7096709ac7 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,30 @@
+2010-05-14  Tristan Gingold  <gingold@adacore.com>
+
+	* vms-lib.c (_bfd_vms_lib_ia64_archive_p): New function.
+	* libbfd-in.h (_bfd_vms_lib_ia64_archive_p): Add prototype.
+	* libbfd.h: Regenerate.
+	* configure.in (havevecs): Define HAVE_all_vecs when
+	--enable-targets=all is set.  Use AC_SUBST on it.
+	(tdefaults): Do not add havevecs.
+	(bfd_elf64_ia64_vms_vec): Add vms-lib.lo and vms-misc.lo
+	* configure: Regenerate.
+	* Makefile.am (HAVEVECS): New variable.
+	(INCLUDES): Add HAVEVECS.
+	* Makefile.in: Regenerate.
+	* elfxx-ia64.c (INCLUDE_IA64_VMS): New macro, defined if vms
+	target is selected.  Add #ifdef/#endif around vms specific code.
+	(bfd_elfNN_archive_p, bfd_elfNN_archive_slurp_armap,
+	bfd_elfNN_archive_slurp_extended_name_table,
+	bfd_elfNN_archive_construct_extended_name_table,
+	bfd_elfNN_archive_truncate_arname,
+	bfd_elfNN_archive_write_armap,
+	bfd_elfNN_archive_read_ar_hdr,
+	bfd_elfNN_archive_write_ar_hdr,
+	bfd_elfNN_archive_openr_next_archived_file,
+	bfd_elfNN_archive_get_elt_at_index,
+	bfd_elfNN_archive_generic_stat_arch_elt,
+	bfd_elfNN_archive_update_armap_timestamp): Define to use vms archives.
+
 2010-05-11  Jie Zhang  <jie@codesourcery.com>
 
 	* elf32-arm.c (elf32_arm_merge_eabi_attributes): Merge
diff --git a/bfd/Makefile.am b/bfd/Makefile.am
index ef545f5f02..e6259305a8 100644
--- a/bfd/Makefile.am
+++ b/bfd/Makefile.am
@@ -682,8 +682,10 @@ ALL_BACKENDS = @all_backends@
 BFD_BACKENDS = @bfd_backends@
 BFD_MACHINES = @bfd_machines@
 TDEFAULTS = @tdefaults@
+HAVEVECS = @havevecs@
 
-INCLUDES = @HDEFINES@ @COREFLAG@ @TDEFINES@ $(CSEARCH) $(CSWITCHES) @INCINTL@
+INCLUDES = @HDEFINES@ @COREFLAG@ @TDEFINES@ $(CSEARCH) $(CSWITCHES) \
+	$(HAVEVECS) @INCINTL@
 
 # C source files that correspond to .o's.
 SOURCE_CFILES = \
diff --git a/bfd/Makefile.in b/bfd/Makefile.in
index f78a006849..e21c1cdbb4 100644
--- a/bfd/Makefile.in
+++ b/bfd/Makefile.in
@@ -277,6 +277,7 @@ datarootdir = @datarootdir@
 docdir = @docdir@
 dvidir = @dvidir@
 exec_prefix = @exec_prefix@
+havevecs = @havevecs@
 host = @host@
 host_alias = @host_alias@
 host_cpu = @host_cpu@
@@ -982,7 +983,10 @@ ALL_BACKENDS = @all_backends@
 BFD_BACKENDS = @bfd_backends@
 BFD_MACHINES = @bfd_machines@
 TDEFAULTS = @tdefaults@
-INCLUDES = @HDEFINES@ @COREFLAG@ @TDEFINES@ $(CSEARCH) $(CSWITCHES) @INCINTL@
+HAVEVECS = @havevecs@
+INCLUDES = @HDEFINES@ @COREFLAG@ @TDEFINES@ $(CSEARCH) $(CSWITCHES) \
+	$(HAVEVECS) @INCINTL@
+
 
 # C source files that correspond to .o's.
 SOURCE_CFILES = \
diff --git a/bfd/configure b/bfd/configure
index 6ace16c35e..a8b15a3d02 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -602,6 +602,7 @@ ac_subst_vars='am__EXEEXT_FALSE
 am__EXEEXT_TRUE
 LTLIBOBJS
 LIBOBJS
+havevecs
 tdefaults
 bfd_ufile_ptr
 bfd_file_ptr
@@ -11405,7 +11406,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11408 "configure"
+#line 11409 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11511,7 +11512,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11514 "configure"
+#line 11515 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15163,7 +15164,7 @@ do
     bfd_elf64_ia64_big_vec)	tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_ia64_hpux_big_vec) tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_ia64_little_vec)	tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
-    bfd_elf64_ia64_vms_vec)	tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
+    bfd_elf64_ia64_vms_vec)	tb="$tb elf64-ia64.lo elf64.lo vms-lib.lo vms-misc.lo $elf"; target_size=64 ;;
     bfd_elf64_little_generic_vec) tb="$tb elf64-gen.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_littlemips_vec) 	tb="$tb elf64-mips.lo elf64.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
     bfd_elf64_mmix_vec) 	tb="$tb elf64-mmix.lo elf64.lo $elf" target_size=64 ;;
@@ -15354,7 +15355,7 @@ if test x${all_targets} = xtrue ; then
   bfd_backends="${bfd_backends}"' $(ALL_BACKENDS)'
   bfd_machines="${bfd_machines}"' $(ALL_MACHINES)'
   selvecs=
-  havevecs=
+  havevecs=-DHAVE_all_vecs
   selarchs=
   test -n "$assocvecs" &&
     assocvecs=`echo $assocvecs | sed -e 's/^/\&/' -e 's/ \(.\)/,\&\1/g'`
@@ -15500,7 +15501,7 @@ test -n "${defvec}" && tdefaults="${tdefaults} -DDEFAULT_VECTOR=${defvec}"
 test -n "${selvecs}" && tdefaults="${tdefaults} -DSELECT_VECS='${selvecs}'"
 test -n "${assocvecs}" && tdefaults="${tdefaults} -DASSOCIATED_VECS='${assocvecs}'"
 test -n "${selarchs}" && tdefaults="${tdefaults} -DSELECT_ARCHITECTURES='${selarchs}'"
-test -n "${havevecs}" && tdefaults="${tdefaults} ${havevecs}"
+
 
 
 for ac_header in stdlib.h unistd.h
diff --git a/bfd/configure.in b/bfd/configure.in
index 6f055056e0..dbbadc05ea 100644
--- a/bfd/configure.in
+++ b/bfd/configure.in
@@ -801,7 +801,7 @@ do
     bfd_elf64_ia64_big_vec)	tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_ia64_hpux_big_vec) tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_ia64_little_vec)	tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
-    bfd_elf64_ia64_vms_vec)	tb="$tb elf64-ia64.lo elf64.lo $elf"; target_size=64 ;;
+    bfd_elf64_ia64_vms_vec)	tb="$tb elf64-ia64.lo elf64.lo vms-lib.lo vms-misc.lo $elf"; target_size=64 ;;
     bfd_elf64_little_generic_vec) tb="$tb elf64-gen.lo elf64.lo $elf"; target_size=64 ;;
     bfd_elf64_littlemips_vec) 	tb="$tb elf64-mips.lo elf64.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
     bfd_elf64_mmix_vec) 	tb="$tb elf64-mmix.lo elf64.lo $elf" target_size=64 ;;
@@ -992,7 +992,7 @@ if test x${all_targets} = xtrue ; then
   bfd_backends="${bfd_backends}"' $(ALL_BACKENDS)'
   bfd_machines="${bfd_machines}"' $(ALL_MACHINES)'
   selvecs=
-  havevecs=
+  havevecs=-DHAVE_all_vecs
   selarchs=
   test -n "$assocvecs" &&
     assocvecs=`echo $assocvecs | sed -e 's/^/\&/' -e 's/ \(.\)/,\&\1/g'`
@@ -1077,8 +1077,8 @@ test -n "${defvec}" && tdefaults="${tdefaults} -DDEFAULT_VECTOR=${defvec}"
 test -n "${selvecs}" && tdefaults="${tdefaults} -DSELECT_VECS='${selvecs}'"
 test -n "${assocvecs}" && tdefaults="${tdefaults} -DASSOCIATED_VECS='${assocvecs}'"
 test -n "${selarchs}" && tdefaults="${tdefaults} -DSELECT_ARCHITECTURES='${selarchs}'"
-test -n "${havevecs}" && tdefaults="${tdefaults} ${havevecs}"
 AC_SUBST(tdefaults)
+AC_SUBST(havevecs)
 
 dnl AC_CHECK_HEADERS(sys/mman.h)
 AC_FUNC_MMAP
diff --git a/bfd/elfxx-ia64.c b/bfd/elfxx-ia64.c
index 7fde3d5c25..93baaf1ba1 100644
--- a/bfd/elfxx-ia64.c
+++ b/bfd/elfxx-ia64.c
@@ -67,6 +67,15 @@
   MIN_PLT	Created by PLTOFF entries against dynamic symbols.  This
  		does not require dynamic relocations.  */
 
+/* Only add code for vms when the vms target is enabled.  This is required
+   because it depends on vms-lib.c for its archive format and we don't want
+   to compile that code if it is not used.  */
+#if ARCH_SIZE == 64 && \
+  (defined (HAVE_bfd_elf64_ia64_vms_vec) || defined (HAVE_all_vecs))
+#define INCLUDE_IA64_VMS
+#endif
+
+
 #define NELEMS(a)	((int) (sizeof (a) / sizeof ((a)[0])))
 
 typedef struct bfd_hash_entry *(*new_hash_entry_func)
@@ -5723,6 +5732,8 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
     }
 }
 
+#ifdef INCLUDE_IA64_VMS
+
 static bfd_boolean
 elfNN_vms_section_from_shdr (bfd *abfd,
 			     Elf_Internal_Shdr *hdr,
@@ -5984,6 +5995,7 @@ elfNN_vms_close_and_cleanup (bfd *abfd)
 
   return _bfd_generic_close_and_cleanup (abfd);
 }
+#endif /* INCLUDE_IA64_VMS */
 
 #define TARGET_LITTLE_SYM		bfd_elfNN_ia64_little_vec
 #define TARGET_LITTLE_NAME		"elfNN-ia64-little"
@@ -6117,6 +6129,7 @@ elfNN_vms_close_and_cleanup (bfd *abfd)
 #include "elfNN-target.h"
 
 /* VMS-specific vectors.  */
+#ifdef INCLUDE_IA64_VMS
 
 #undef  TARGET_LITTLE_SYM
 #define TARGET_LITTLE_SYM		bfd_elfNN_ia64_vms_vec
@@ -6160,4 +6173,36 @@ elfNN_vms_close_and_cleanup (bfd *abfd)
 #undef  elfNN_bed
 #define elfNN_bed elfNN_ia64_vms_bed
 
+/* Use VMS-style archives (in particular, don't use the standard coff
+   archive format).  */
+#define bfd_elfNN_archive_functions
+
+#undef bfd_elfNN_archive_p
+#define bfd_elfNN_archive_p _bfd_vms_lib_ia64_archive_p
+
+#define bfd_elfNN_archive_slurp_armap \
+  _bfd_vms_lib_slurp_armap
+#define bfd_elfNN_archive_slurp_extended_name_table \
+  _bfd_vms_lib_slurp_extended_name_table
+#define bfd_elfNN_archive_construct_extended_name_table \
+  _bfd_vms_lib_construct_extended_name_table
+#define bfd_elfNN_archive_truncate_arname \
+  _bfd_vms_lib_truncate_arname
+#define bfd_elfNN_archive_write_armap \
+  _bfd_vms_lib_write_armap
+#define bfd_elfNN_archive_read_ar_hdr \
+  _bfd_vms_lib_read_ar_hdr
+#define bfd_elfNN_archive_write_ar_hdr \
+  _bfd_vms_lib_write_ar_hdr
+#define bfd_elfNN_archive_openr_next_archived_file \
+  _bfd_vms_lib_openr_next_archived_file
+#define bfd_elfNN_archive_get_elt_at_index \
+  _bfd_vms_lib_get_elt_at_index
+#define bfd_elfNN_archive_generic_stat_arch_elt \
+  _bfd_vms_lib_generic_stat_arch_elt
+#define bfd_elfNN_archive_update_armap_timestamp \
+  _bfd_vms_lib_update_armap_timestamp
+
 #include "elfNN-target.h"
+
+#endif /* INCLUDE_IA64_VMS */
diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
index 89d0df6905..5e636a3e10 100644
--- a/bfd/libbfd-in.h
+++ b/bfd/libbfd-in.h
@@ -375,6 +375,7 @@ extern int _bfd_vms_lib_generic_stat_arch_elt (bfd *, struct stat *);
 extern symindex _bfd_vms_lib_find_symbol (bfd *, const char *);
 extern bfd *_bfd_vms_lib_get_imagelib_file (bfd *);
 extern const bfd_target *_bfd_vms_lib_alpha_archive_p (bfd *abfd);
+extern const bfd_target *_bfd_vms_lib_ia64_archive_p (bfd *abfd);
 extern bfd_boolean _bfd_vms_lib_mkarchive (bfd *abfd);
 
 /* Routines to use for BFD_JUMP_TABLE_SYMBOLS where there is no symbol
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index c02063a360..7275dd9f1a 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -380,6 +380,7 @@ extern int _bfd_vms_lib_generic_stat_arch_elt (bfd *, struct stat *);
 extern symindex _bfd_vms_lib_find_symbol (bfd *, const char *);
 extern bfd *_bfd_vms_lib_get_imagelib_file (bfd *);
 extern const bfd_target *_bfd_vms_lib_alpha_archive_p (bfd *abfd);
+extern const bfd_target *_bfd_vms_lib_ia64_archive_p (bfd *abfd);
 extern bfd_boolean _bfd_vms_lib_mkarchive (bfd *abfd);
 
 /* Routines to use for BFD_JUMP_TABLE_SYMBOLS where there is no symbol
diff --git a/bfd/vms-lib.c b/bfd/vms-lib.c
index 0b45a131b8..3877686b3e 100644
--- a/bfd/vms-lib.c
+++ b/bfd/vms-lib.c
@@ -619,6 +619,14 @@ _bfd_vms_lib_alpha_archive_p (bfd *abfd)
   return _bfd_vms_lib_archive_p (abfd, vms_lib_alpha);
 }
 
+/* Standard function for ia64 libraries.  */
+
+const bfd_target *
+_bfd_vms_lib_ia64_archive_p (bfd *abfd)
+{
+  return _bfd_vms_lib_archive_p (abfd, vms_lib_ia64);
+}
+
 /* Standard function for text libraries.  */
 
 static const bfd_target *