public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [Patch 3/4]: Rewrite of the alpha-vms bfd back-end (ld)
@ 2010-04-09  9:35 Tristan Gingold
  2010-04-13 10:53 ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: Tristan Gingold @ 2010-04-09  9:35 UTC (permalink / raw)
  To: binutils

This adds support for alpha-vms to ld.

Tristan.

ld/
2010-04-09  Tristan Gingold  <gingold@adacore.com>

	* emulparams/alphavms.sh: New file.
	* emultempl/vms.em: New file.
	* scripttempl/alphavms.sc: New file.
	* configure.tgt (alpha*-*-*vms*): Added.
	* Makefile.am (ALL_EMULATIONS): Add ealphavms.o
	(ealphavms.c): New target.
	* Makefile.in: Regenerate.
---
 ld/Makefile.am             |    5 ++
 ld/configure.tgt           |    3 +-
 ld/emulparams/alphavms.sh  |    7 +++
 ld/emultempl/vms.em        |  123 ++++++++++++++++++++++++++++++++++++++++++++
 ld/scripttempl/alphavms.sc |   34 ++++++++++++
 5 files changed, 171 insertions(+), 1 deletions(-)
 create mode 100644 ld/emulparams/alphavms.sh
 create mode 100644 ld/emultempl/vms.em
 create mode 100644 ld/scripttempl/alphavms.sc

diff --git a/ld/Makefile.am b/ld/Makefile.am
index 010fb55..54e9309 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -118,6 +118,7 @@ ALL_EMULATIONS = \
 	eaixppc.o \
 	eaixrs6.o \
 	ealpha.o \
+	ealphavms.o \
 	earcelf.o \
 	earm_epoc_pe.o \
 	earm_wince_pe.o \
@@ -611,6 +612,10 @@ eaixrs6.c: $(srcdir)/emulparams/aixrs6.sh \
 ealpha.c: $(srcdir)/emulparams/alpha.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/alpha.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} alpha "$(tdir_alpha)"
+ealphavms.c: $(srcdir)/emulparams/alphavms.sh \
+  $(srcdir)/emultempl/vms.em $(srcdir)/scripttempl/alphavms.sc \
+  ${GEN_DEPENDS}
+	${GENSCRIPTS} alphavms "$(tdir_alphavms)"
 earcelf.c: $(srcdir)/emulparams/arcelf.sh \
   $(ELF_GEN_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} arcelf "$(tdir_arcelf)"
diff --git a/ld/configure.tgt b/ld/configure.tgt
index c519ba7..def0287 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -39,7 +39,8 @@ alpha*-*-osf*)		targ_emul=alpha ;;
 alpha*-*-gnu*)		targ_emul=elf64alpha ;;
 alpha*-*-netware*)	targ_emul=alpha ;;
 alpha*-*-netbsd*)	targ_emul=elf64alpha_nbsd ;;
-alpha*-*-openbsd*)	targ_emul=elf64alpha
+alpha*-*-openbsd*)	targ_emul=elf64alpha ;;
+alpha*-*-*vms*)		targ_emul=alphavms
 			;;
 arc-*-elf*)		targ_emul=arcelf
 			;;
diff --git a/ld/emulparams/alphavms.sh b/ld/emulparams/alphavms.sh
new file mode 100644
index 0000000..ac9b3a2
--- /dev/null
+++ b/ld/emulparams/alphavms.sh
@@ -0,0 +1,7 @@
+SCRIPT_NAME=alphavms
+
+OUTPUT_FORMAT="vms-alpha"
+ARCH=alpha
+
+COMPILE_IN=yes
+EXTRA_EM_FILE=vms
\ No newline at end of file
diff --git a/ld/emultempl/vms.em b/ld/emultempl/vms.em
new file mode 100644
index 0000000..ec52de7
--- /dev/null
+++ b/ld/emultempl/vms.em
@@ -0,0 +1,123 @@
+# This shell script emits a C file. -*- C -*-
+#   Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+#   Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# 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.
+#
+
+# This file is sourced from generic.em.
+
+fragment <<EOF
+static void
+gld${EMULATION_NAME}_before_parse (void)
+{
+  ldfile_set_output_arch ("${ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
+  config.dynamic_link = TRUE;
+  config.has_shared = FALSE; /* Not yet.  */
+}
+
+/* This is called before the input files are opened.  We add the
+   standard library.  */
+
+static void
+gld${EMULATION_NAME}_create_output_section_statements (void)
+{
+  lang_add_input_file ("imagelib", lang_input_file_is_l_enum, NULL);
+  lang_add_input_file ("starlet", lang_input_file_is_l_enum, NULL);
+  lang_add_input_file ("sys\$public_vectors", lang_input_file_is_l_enum, NULL);
+}
+
+/* Try to open a dynamic archive.  This is where we know that VMS
+   shared images (dynamic libraries) have an extension of .exe.  */
+
+static bfd_boolean
+gld${EMULATION_NAME}_open_dynamic_archive (const char *arch ATTRIBUTE_UNUSED,
+                                           search_dirs_type *search,
+                                           lang_input_statement_type *entry)
+{
+  char *string;
+
+  if (! entry->is_archive)
+    return FALSE;
+
+  string = (char *) xmalloc (strlen (search->name)
+			     + strlen (entry->filename)
+			     + sizeof "/.exe");
+
+  sprintf (string, "%s/%s.exe", search->name, entry->filename);
+
+  if (! ldfile_try_open_bfd (string, entry))
+    {
+      free (string);
+      return FALSE;
+    }
+
+  entry->filename = string;
+
+  return TRUE;
+}
+
+static int
+gld${EMULATION_NAME}_find_potential_libraries
+  (char *name, lang_input_statement_type *entry)
+{
+  return ldfile_open_file_search (name, entry, "", ".olb");
+}
+
+/* Place an orphan section.  We use this to put random OVR sections.
+   Much borrowed from elf32.em.  */
+
+static lang_output_section_statement_type *
+vms_place_orphan (asection *s,
+		  const char *secname ATTRIBUTE_UNUSED,
+		  int constraint ATTRIBUTE_UNUSED)
+{
+  static struct orphan_save hold_data =
+    {
+      "\$DATA\$",
+      SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
+      0, 0, 0, 0
+    };
+
+  /* We have nothing to say for anything other than a final link.  */
+  if (link_info.relocatable
+      || (s->flags & (SEC_EXCLUDE | SEC_LOAD)) != SEC_LOAD)
+    return NULL;
+
+  /* Only handle data sections.  */
+  if ((s->flags & SEC_DATA) == 0)
+    return NULL;
+
+  if (hold_data.os == NULL)
+    hold_data.os = lang_output_section_find (hold_data.name);
+
+  if (hold_data.os != NULL)
+    {
+      lang_add_section (&hold_data.os->children, s, hold_data.os);
+      return hold_data.os;
+    }
+  else
+    return NULL;
+}
+EOF
+
+LDEMUL_PLACE_ORPHAN=vms_place_orphan
+LDEMUL_BEFORE_PARSE=gld"$EMULATION_NAME"_before_parse
+LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=gld"$EMULATION_NAME"_create_output_section_statements
+LDEMUL_FIND_POTENTIAL_LIBRARIES=gld"$EMULATION_NAME"_find_potential_libraries
+LDEMUL_OPEN_DYNAMIC_ARCHIVE=gld"$EMULATION_NAME"_open_dynamic_archive
diff --git a/ld/scripttempl/alphavms.sc b/ld/scripttempl/alphavms.sc
new file mode 100644
index 0000000..ed4ec68
--- /dev/null
+++ b/ld/scripttempl/alphavms.sc
@@ -0,0 +1,34 @@
+# Linker script for Alpha VMS systems.
+# Tristan Gingold <gingold@adacore.com>.
+
+PAGESIZE=0x10000
+
+cat <<EOF
+OUTPUT_FORMAT("${OUTPUT_FORMAT}")
+${LIB_SEARCH_DIRS}
+
+SECTIONS
+{
+  ${RELOCATING+. = ${PAGESIZE};}
+
+  \$DATA\$ ALIGN (${PAGESIZE}) : {
+    *(\$DATA\$)
+    *(\$LINK\$)
+  }
+  \$BSS\$ ALIGN (${PAGESIZE}) : {
+    *(\$BSS\$)
+  }
+  \$CODE\$ ALIGN (${PAGESIZE}) : {
+    *(\$CODE\$)
+  }
+  \$LITERAL\$ ALIGN (${PAGESIZE}) : {
+    *(\$LITERAL\$)
+    *(\$READONLY\$)
+    *(\$READONLY_ADDR\$)
+  }
+
+  \$DST\$ 0 : {
+    *(\$DST\$)
+  }
+}
+EOF
-- 
1.6.2

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch 3/4]: Rewrite of the alpha-vms bfd back-end (ld)
  2010-04-09  9:35 [Patch 3/4]: Rewrite of the alpha-vms bfd back-end (ld) Tristan Gingold
@ 2010-04-13 10:53 ` Nick Clifton
  2010-04-13 11:20   ` Tristan Gingold
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Clifton @ 2010-04-13 10:53 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils

Hi Tristan,

   A couple of minor points:

> diff --git a/ld/emultempl/vms.em b/ld/emultempl/vms.em
> new file mode 100644
> index 0000000..ec52de7
> --- /dev/null
> +++ b/ld/emultempl/vms.em
> @@ -0,0 +1,123 @@
> +# This shell script emits a C file. -*- C -*-
> +#   Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009

You really only need 2010 listed as a copyright year here.

> +  string = (char *) xmalloc (strlen (search->name)
> +			     + strlen (entry->filename)
> +			     + sizeof "/.exe");
> +
> +  sprintf (string, "%s/%s.exe", search->name, entry->filename);

What about the zero-terminator for the string ?  Ie this looks like a 
possible memory corruption bug to me.

Cheers
   Nick

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch 3/4]: Rewrite of the alpha-vms bfd back-end (ld)
  2010-04-13 10:53 ` Nick Clifton
@ 2010-04-13 11:20   ` Tristan Gingold
  2010-04-13 17:00     ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: Tristan Gingold @ 2010-04-13 11:20 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils


On Apr 13, 2010, at 12:53 PM, Nick Clifton wrote:

> Hi Tristan,
> 
>  A couple of minor points:
> 
>> diff --git a/ld/emultempl/vms.em b/ld/emultempl/vms.em
>> new file mode 100644
>> index 0000000..ec52de7
>> --- /dev/null
>> +++ b/ld/emultempl/vms.em
>> @@ -0,0 +1,123 @@
>> +# This shell script emits a C file. -*- C -*-
>> +#   Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
> 
> You really only need 2010 listed as a copyright year here.

Sure.

> 
>> +  string = (char *) xmalloc (strlen (search->name)
>> +			     + strlen (entry->filename)
>> +			     + sizeof "/.exe");
>> +
>> +  sprintf (string, "%s/%s.exe", search->name, entry->filename);
> 
> What about the zero-terminator for the string ?  Ie this looks like a possible memory corruption bug to me.

Isn't sizeof ("./exe") == 6 (ie, strlen + 1) ?

Tristan.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch 3/4]: Rewrite of the alpha-vms bfd back-end (ld)
  2010-04-13 11:20   ` Tristan Gingold
@ 2010-04-13 17:00     ` Nick Clifton
  2010-04-14  9:30       ` Tristan Gingold
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Clifton @ 2010-04-13 17:00 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils

Hi Tristan,

>>> +  string = (char *) xmalloc (strlen (search->name)
>>> +			     + strlen (entry->filename)
>>> +			     + sizeof "/.exe");
>>> +
>>> +  sprintf (string, "%s/%s.exe", search->name, entry->filename);
>>
>> What about the zero-terminator for the string ?  Ie this looks like a possible memory corruption bug to me.
>
> Isn't sizeof ("./exe") == 6 (ie, strlen + 1) ?

Mea culpa.  You're right.  Patch approved.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch 3/4]: Rewrite of the alpha-vms bfd back-end (ld)
  2010-04-13 17:00     ` Nick Clifton
@ 2010-04-14  9:30       ` Tristan Gingold
  0 siblings, 0 replies; 5+ messages in thread
From: Tristan Gingold @ 2010-04-14  9:30 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils


On Apr 13, 2010, at 7:00 PM, Nick Clifton wrote:

> Hi Tristan,
> 
>>>> +  string = (char *) xmalloc (strlen (search->name)
>>>> +			     + strlen (entry->filename)
>>>> +			     + sizeof "/.exe");
>>>> +
>>>> +  sprintf (string, "%s/%s.exe", search->name, entry->filename);
>>> 
>>> What about the zero-terminator for the string ?  Ie this looks like a possible memory corruption bug to me.
>> 
>> Isn't sizeof ("./exe") == 6 (ie, strlen + 1) ?
> 
> Mea culpa.  You're right.  Patch approved.

Thanks, committed.

Tristan.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-04-14  9:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-09  9:35 [Patch 3/4]: Rewrite of the alpha-vms bfd back-end (ld) Tristan Gingold
2010-04-13 10:53 ` Nick Clifton
2010-04-13 11:20   ` Tristan Gingold
2010-04-13 17:00     ` Nick Clifton
2010-04-14  9:30       ` Tristan Gingold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).