[PATCH,AIX] Optimize the time required for loading XCOFF data

2018-07-31 Thread REIX, Tony

Description:
 * This patch optimizes the time required for loading XCOFF data.

Tests:
 * AIX: Build: SUCCESS
   - build made by means of gmake on AIX.

ChangeLog:
  * xcoff.c: Optimize loading of XCOFF data.
 
 
Cordialement,
 
 Tony Reix
 
 tony.r...@atos.net
 
 ATOS / Bull SAS
 ATOS Expert
 IBM Coop Architect & Technical Leader
  
Office : +33 (0) 4 76 29 72 67 
1 rue de Provence - 38432 Échirolles - France 
www.atos.net Index: libbacktrace/xcoff.c
===
--- ./libbacktrace/xcoff.c	(revision 262803)
+++ ./libbacktrace/xcoff.c	(working copy)
@@ -338,27 +338,32 @@ struct xcoff_incl_vector
   size_t count;
 };
 
-/* Map a single PC value to a file/function/line.  */
+/* A growable vector of functions information.  */
 
-struct xcoff_line
+struct xcoff_func
 {
   /* PC.  */
   uintptr_t pc;
-  /* File name.  Many entries in the array are expected to point to
- the same file name.  */
+  /* The size of the function.  */
+  size_t size;
+  /* Function name.  */
+  const char *name;
+  /* File name.  */
   const char *filename;
-  /* Function name.  */
-  const char *function;
-  /* Line number.  */
-  int lineno;
+  /* Pointer to first lnno entry.  */
+  uintptr_t lnnoptr;
+  /* Base address of containing section.  */
+  uintptr_t sect_base;
+  /* Starting source line number.  */
+  int lnno;
 };
 
-/* A growable vector of line number information.  This is used while
-   reading the line numbers.  */
+/* A growable vector of function information.  This is used while
+   reading the function symbols.  */
 
-struct xcoff_line_vector
+struct xcoff_func_vector
 {
-  /* Memory.  This is an array of struct xcoff_line.  */
+  /* Memory.  This is an array of struct xcoff_func.  */
   struct backtrace_vector vec;
   /* Number of valid mappings.  */
   size_t count;
@@ -370,8 +375,16 @@ struct xcoff_fileline_data
 {
   /* The data for the next file we know about.  */
   struct xcoff_fileline_data *next;
-  /* Line number information.  */
-  struct xcoff_line_vector vec;
+  /* Functions information.  */
+  struct xcoff_func_vector func_vec;
+  /* Include files information.  */
+  struct xcoff_incl_vector incl_vec;
+  /* Line numbers information.  */
+  const unsigned char *linenos;
+  size_t linenos_size;
+  uint64_t lnnoptr0;
+  /* Loader address.  */
+  uintptr_t base_address;
 };
 
 /* An index of DWARF sections we care about.  */
@@ -509,6 +522,7 @@ xcoff_syminfo (struct backtrace_state *state ATTRI
 {
   struct xcoff_syminfo_data *edata;
   struct xcoff_symbol *sym = NULL;
+  const char *name;
 
   if (!state->threaded)
 {
@@ -547,7 +561,13 @@ xcoff_syminfo (struct backtrace_state *state ATTRI
   if (sym == NULL)
 callback (data, addr, NULL, 0, 0);
   else
-callback (data, addr, sym->name, sym->address, sym->size);
+{
+  name = sym->name;
+  /* AIX prepends a '.' to function entry points, remove it.  */
+  if (name && *name == '.')
+	++name;
+  callback (data, addr, name, sym->address, sym->size);
+}
 }
 
 /* Return the name of an XCOFF symbol.  */
@@ -640,43 +660,76 @@ xcoff_initialize_syminfo (struct backtrace_state *
   return 1;
 }
 
-/* Compare struct xcoff_line for qsort.  */
+/* Compare struct xcoff_func for qsort.  */
 
 static int
-xcoff_line_compare (const void *v1, const void *v2)
+xcoff_func_compare (const void *v1, const void *v2)
 {
-  const struct xcoff_line *ln1 = (const struct xcoff_line *) v1;
-  const struct xcoff_line *ln2 = (const struct xcoff_line *) v2;
+  const struct xcoff_func *fn1 = (const struct xcoff_func *) v1;
+  const struct xcoff_func *fn2 = (const struct xcoff_func *) v2;
 
-  if (ln1->pc < ln2->pc)
+  if (fn1->pc < fn2->pc)
 return -1;
-  else if (ln1->pc > ln2->pc)
+  else if (fn1->pc > fn2->pc)
 return 1;
   else
 return 0;
 }
 
-/* Find a PC in a line vector.  We always allocate an extra entry at
-   the end of the lines vector, so that this routine can safely look
-   at the next entry.  */
+/* Compare a PC against an xcoff_func for bsearch.  */
 
 static int
-xcoff_line_search (const void *vkey, const void *ventry)
+xcoff_func_search (const void *vkey, const void *ventry)
 {
   const uintptr_t *key = (const uintptr_t *) vkey;
-  const struct xcoff_line *entry = (const struct xcoff_line *) ventry;
+  const struct xcoff_func *entry = (const struct xcoff_func *) ventry;
   uintptr_t pc;
 
   pc = *key;
   if (pc < entry->pc)
 return -1;
-  else if ((entry + 1)->pc == (uintptr_t) -1 || pc >= (entry + 1)->pc)
+  else if ((entry->size == 0 && pc > entry->pc)
+	   || (entry->size > 0 && pc >= entry->pc + entry->size))
 return 1;
   else
 return 0;
 }
 
-/* Look for a PC in the line vector for one module.  On success,
+/* Compare struct xcoff_incl for qsort.  */
+
+static int
+xcoff_incl_compare (const void *v1, const void *v2)
+{
+  const struct xcoff_incl *in1 = (const struct xcoff_incl *) v1;
+  const struct xcoff_incl *in2 = (const struct 

[PATCH,AIX] Fix -static-libgcc & -static-libgo issues for AIX

2018-06-15 Thread REIX, Tony
Description:
 * This patch fixes the crash issues faced when using -static-libgcc & 
-static-libgo on AIX
On AIX, do not call shared library initializers when linking statically.
This fixes a bug where frame tables are registered twice at runtime, one 
time by the shared library initializer and one time by the main program 
initializer, because when linking statically frame tables from the shared 
library end up in the main program after the first collect2 pass. This breaks 
_Unwind_Find_FDE’s non-overlapping objects assumption.

Tests:
 * AIX: Build: SUCCESS
   - build made by means of gmake in trunk.
   - patch generated by: 
cd gcc-svn-trunk/
svn diff gcc/ChangeLog gcc/collect2.c 

ChangeLog:
   +   gcc/collect2.c: manage static link
   +   gcc/ChangeLog: Description
   

Regards,

Tony Reix


ATOS / Bull SAS
ATOS Expert
IBM Coop Architect & Technical Leader

Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net

--- ./gcc/ChangeLog	(revision 261620)
+++ ./gcc/ChangeLog	(working copy)
@@ -1,3 +1,13 @@
+2018-06-15  Tony Reix  
+
+	* collect2.c: On AIX, do not call shared library initializers
+	when linking statically.  This fixes a bug where frame tables
+	are registered twice at runtime, one time by the shared library
+	initializer and one time by the main program initializer,
+	because when linking statically frame tables from the shared
+	library end up in the main program after the first collect2 pass.
+	This breaks _Unwind_Find_FDE's non-overlapping objects assumption.
+
 2018-06-15  Richard Biener  
 
 	PR middle-end/86076
--- ./gcc/collect2.c	(revision 261597)
+++ ./gcc/collect2.c	(working copy)
@@ -201,6 +201,7 @@ static enum lto_mode_d lto_mode = LTO_MODE_NONE;
 bool helpflag;			/* true if --help */
 
 static int shared_obj;			/* true if -shared */
+static int static_obj;			/* true if -static */
 
 static const char *c_file;		/* .c for constructor/destructor list.  */
 static const char *o_file;		/* .o for constructor/destructor list.  */
@@ -255,6 +256,7 @@ bool may_unlink_output_file = false;
 #ifdef COLLECT_EXPORT_LIST
 /* Lists to keep libraries to be scanned for global constructors/destructors.  */
 static struct head libs;/* list of libraries */
+static struct head static_libs; /* list of statically linked libraries */
 static struct path_prefix cmdline_lib_dirs; /* directories specified with -L */
 static struct path_prefix libpath_lib_dirs; /* directories in LIBPATH */
 static struct path_prefix *libpaths[3] = {_lib_dirs,
@@ -320,9 +322,7 @@ static void write_c_file_glob (FILE *, const char
 static void scan_libraries (const char *);
 #endif
 #ifdef COLLECT_EXPORT_LIST
-#if 0
 static int is_in_list (const char *, struct id *);
-#endif
 static void write_aix_file (FILE *, struct id *);
 static char *resolve_lib_name (const char *);
 #endif
@@ -911,6 +911,7 @@ main (int argc, char **argv)
   int first_file;
   int num_c_args;
   char **old_argv;
+  bool is_static = false;
   int i;
 
   for (i = 0; i < USE_LD_MAX; i++)
@@ -1241,6 +1242,8 @@ main (int argc, char **argv)
 	*c_ptr++ = xstrdup (q);
   if (strcmp (q, "-shared") == 0)
 	shared_obj = 1;
+  if (strcmp (q, "-static") == 0)
+	static_obj = 1;
   if (*q == '-' && q[1] == 'B')
 	{
 	  *c_ptr++ = xstrdup (q);
@@ -1269,6 +1272,7 @@ main (int argc, char **argv)
   /* Parse arguments.  Remember output file spec, pass the rest to ld.  */
   /* After the first file, put in the c++ rt0.  */
 
+  is_static = static_obj;
   first_file = 1;
   while ((arg = *++argv) != (char *) 0)
 {
@@ -1374,6 +1378,14 @@ main (int argc, char **argv)
 #endif
   break;
 
+#ifdef COLLECT_EXPORT_LIST
+	case 'b':
+	  if (!strcmp (arg, "-bstatic"))
+		is_static = true;
+	  else if (!strcmp (arg, "-bdynamic") || !strcmp (arg, "-bshared"))
+		is_static = false;
+	  break;
+#endif
 	case 'l':
 	  if (first_file)
 		{
@@ -1390,6 +1402,8 @@ main (int argc, char **argv)
 
 		/* Saving a full library name.  */
 		add_to_list (, s);
+		if (is_static)
+		add_to_list (_libs, s);
 	  }
 #endif
 	  break;
@@ -1490,6 +1504,8 @@ main (int argc, char **argv)
 	{
 	  /* Saving a full library name.  */
 	  add_to_list (, arg);
+	  if (is_static)
+		add_to_list (_libs, arg);
 	}
 #endif
 	}
@@ -1501,6 +1517,8 @@ main (int argc, char **argv)
 {
   fprintf (stderr, "List of libraries:\n");
   dump_list (stderr, "\t", libs.first);
+  fprintf (stderr, "List of statically linked libraries:\n");
+  dump_list (stderr, "\t", static_libs.first);
 }
 
   /* The AIX linker will discard static constructors in object files if
@@ -1525,9 +1543,11 @@ main (int argc, char **argv)
   this_filter &= ~SCAN_DWEH;
 #endif
 
+/* Scan object files.  */
 while (export_object_lst < object)
   scan_prog_file (*export_object_lst++, PASS_OBJ, this_filter);
 
+/* Scan libraries.  */
 

RE:[PATCH,AIX] Optimize parsing of include files.

2018-01-19 Thread REIX, Tony
Thanks David,

I've saved you comments in our Wiki so I hope I'll remember and do better next 
time.

Regards,

Cordialement,

Tony Reix

ATOS / Bull SAS
ATOS Expert
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : David Edelsohn [dje@gmail.com]
Envoyé : vendredi 19 janvier 2018 17:36
À : REIX, Tony
Cc : gcc-patches@gcc.gnu.org; Ian Lance Taylor; BERGAMINI, DAMIEN
Objet : Re: [PATCH,AIX] Optimize parsing of include files.

On Thu, Jan 18, 2018 at 9:56 AM, REIX, Tony <tony.r...@atos.net> wrote:
>
> Description:
>  * This patch optimizes the time required for parsing the include files.
>
> Tests:
>  * AIX: Build: SUCCESS
>- build made by means of gmake on AIX.
>
> ChangeLog:
>   * xcoff.c: Optimize parsing of include files.

Hi, Tony

The ChangeLog should be more detailed.

* xcoff.c (xcoff_incl_compare): New function.
(xcoff_incl_search): New function.
(xcoff_process_linenos): Use bsearch to find include file.
(xcoff_initialize_fileline): Sort include file information.


The rest is okay, although the calls to bsearch and backtrace_qsort
don't follow the style of other files.

This is okay.

Thanks, David


[PATCH,AIX] Optimize parsing of include files.

2018-01-18 Thread REIX, Tony

Description:
 * This patch optimizes the time required for parsing the include files.

Tests:
 * AIX: Build: SUCCESS
   - build made by means of gmake on AIX.

ChangeLog:
  * xcoff.c: Optimize parsing of include files.



Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader

Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net
Index: libbacktrace/xcoff.c
===
--- libbacktrace/xcoff.c	(revision 256837)
+++ libbacktrace/xcoff.c	(working copy)
@@ -760,6 +760,40 @@ xcoff_fileline (struct backtrace_state *state, uin
   return callback (data, pc, NULL, 0, NULL);
 }
 
+/* Compare struct xcoff_incl for qsort.  */
+
+static int
+xcoff_incl_compare (const void *v1, const void *v2)
+{
+  const struct xcoff_incl *in1 = (const struct xcoff_incl *) v1;
+  const struct xcoff_incl *in2 = (const struct xcoff_incl *) v2;
+
+  if (in1->begin < in2->begin)
+return -1;
+  else if (in1->begin > in2->begin)
+return 1;
+  else
+return 0;
+}
+
+/* Find a lnnoptr in an include file.  */
+
+static int
+xcoff_incl_search (const void *vkey, const void *ventry)
+{
+  const uintptr_t *key = (const uintptr_t *) vkey;
+  const struct xcoff_incl *entry = (const struct xcoff_incl *) ventry;
+  uintptr_t lnno;
+
+  lnno = *key;
+  if (lnno < entry->begin)
+return -1;
+  else if (lnno > entry->end)
+return 1;
+  else
+return 0;
+}
+
 /* Add a new mapping to the vector of line mappings that we are
building.  Returns 1 on success, 0 on failure.  */
 
@@ -809,7 +843,6 @@ xcoff_process_linenos (struct backtrace_state *sta
   uintptr_t pc;
   uint32_t lnno;
   int begincl;
-  size_t i;
 
   aux = (const b_xcoff_auxent *) (fsym + 1);
   lnnoptr = aux->x_fcn.x_lnnoptr;
@@ -839,15 +872,13 @@ xcoff_process_linenos (struct backtrace_state *sta
   /* If part of a function other than the beginning comes from an
 	 include file, the line numbers are absolute, rather than
 	 relative to the beginning of the function.  */
-  for (i = 0; i < vec->count; ++i)
-	{
-	  incl = (struct xcoff_incl *) vec->vec.base + i;
-	  if (incl->begin <= lnnoptr && lnnoptr <= incl->end)
-	break;
-	}
+  incl = (struct xcoff_incl *) bsearch (, vec->vec.base,
+	vec->count,
+	sizeof (struct xcoff_incl),
+	xcoff_incl_search);
   if (begincl == -1)
-	begincl = (i < vec->count);
-  if (i < vec->count)
+	begincl = incl != NULL;
+  if (incl != NULL)
 	{
 	  filename = incl->filename;
 	  if (begincl == 1)
@@ -935,6 +966,9 @@ xcoff_initialize_fileline (struct backtrace_state
   i += asym->n_numaux;
 }
 
+  backtrace_qsort (vec.vec.base, vec.count,
+		   sizeof (struct xcoff_incl), xcoff_incl_compare);
+
   filename = NULL;
   fsym = NULL;
   for (i = 0; i < nsyms; ++i)


[PATCH,AIX] Nil check size threshold control for AIX

2017-12-12 Thread REIX, Tony
Description:
 * This patch tells the Go frontend to insert explicit guards (check for nil -> 
panic) for AIX since relying on a fault does not work on AIX for page 0.

Tests:
 * AIX: Build: SUCCESS
   - build made by means of gmake.

ChangeLog:
  * go-lang.c (go_langhook_init): Handle AIX case for nil_check_size_threshold.


Cordialement,

Tony Reix

ATOS / Bull SAS
ATOS Expert
IBM Coop Architect & Technical Leader

Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.netIndex: gcc/go/go-lang.c
===
--- ./gcc/go/go-lang.c	(revision 255466)
+++ ./gcc/go/go-lang.c	(working copy)
@@ -112,7 +112,11 @@ go_langhook_init (void)
   args.check_divide_overflow = go_check_divide_overflow;
   args.compiling_runtime = go_compiling_runtime;
   args.debug_escape_level = go_debug_escape_level;
+#ifdef TARGET_AIX
+  args.nil_check_size_threshold = -1;
+#else
   args.nil_check_size_threshold = 4096;
+#endif
   args.linemap = go_get_linemap();
   args.backend = go_get_backend();
   go_create_gogo ();


RE:[PATCH,AIX] Fix issue with PRI*64 on AIX.

2017-10-10 Thread REIX, Tony
Hi David,

Since the file ./gcc/go/go-system.h in GCC source code starts by:

// go-system.h -- Go frontend inclusion of gcc header files   -*- C++ -*-
// Copyright (C) 2009-2017 Free Software Foundation, Inc.

// This file is part of GCC.
...

I think it is SFS and not Google.

Moreover, this file does not appear in my Google Git environment I use for 
PolyGerrit (GCCGo/GITgofrontend/gofrontend directory on my PC).

Unless I do not understand something...

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : David Edelsohn [dje@gmail.com]
Envoyé : mardi 10 octobre 2017 15:46
À : REIX, Tony
Cc : gcc-patches@gcc.gnu.org
Objet : Re: [PATCH,AIX] Fix issue with PRI*64 on AIX.

On Tue, Oct 10, 2017 at 5:09 AM, REIX, Tony <tony.r...@atos.net> wrote:
> Description:
>  * This patch enables to build on AIX.
>
> Tests:
>  * AIX: Build: SUCCESS
>- build made by means of gmake within GCC 8 trunk.
>
> ChangeLog:
>   * go-system.h : Enable to build on AIX.
>   (fix issue with PRIx64 and PRIu64)

Tony,

This is the wrong forum to propose the patch.  The Go frontend is
imported from Golang upstream.  The patch must be proposed in
PolyGerrit, merged into the main repository, and then imported to GCC
Gofrontend.

Thanks, David


[PATCH,AIX] Fix issue with PRI*64 on AIX.

2017-10-10 Thread REIX, Tony
Description:
 * This patch enables to build on AIX.

Tests:
 * AIX: Build: SUCCESS
   - build made by means of gmake within GCC 8 trunk.

ChangeLog:
  * go-system.h : Enable to build on AIX.
  (fix issue with PRIx64 and PRIu64)

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader

Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net--- ./gcc/go/go-system.h.ORIGIN	2017-10-06 09:36:56 -0500
+++ ./gcc/go/go-system.h	2017-10-06 15:51:26 -0500
@@ -22,6 +22,12 @@
 
 #include "config.h"
 
+// Define this so that inttypes.h defines the PRI?64 macros even
+// when compiling with a C++ compiler. Define it here so in the
+// event inttypes.h gets pulled in by another header it is already
+// defined.
+#define __STDC_FORMAT_MACROS
+
 // These must be included before the #poison declarations in system.h.
 
 #include 
--- ./gcc/go/ChangeLog.ORIGIN	2017-10-10 10:59:01 -0500
+++ ./gcc/go/ChangeLog	2017-10-10 10:59:16 -0500
@@ -1,3 +1,8 @@
+2017-10-09  Tony Reix  
+
+* go-system.h : Enable to build on AIX.
+(fix issue with PRIx64 and PRIu64)
+
 2017-08-30  Richard Sandiford  
 	Alan Hayward  
 	David Sherwood  


[PATCH,AIX] Manage Go Closure in libffi for AIX

2017-10-03 Thread REIX, Tony
Description:
 * This patch provides changes in libffi for providing the Go closure on AIX.

Tests:
 * AIX: Build of GCC 8 trunk: SUCCESS
   - build made by means of gmake.

ChangeLog:
  * src/powerpc/aix.S (ffi_call_AIX): Add debugging pseudo-op and labels 
for EH.
(ffi_call_go_AIX): New function.
(_GLOBAL__F_libffi_src_powerpc_aix): EH frame.
  * src/powerpc/aix_closure.S (ffi_closure_ASM): Add debugging pseudo-op 
and labels for EH.
(ffi_go_closure_ASM): New function.
(_GLOBAL__F_libffi_src_powerpc_aix_closure): EH frame.
  * src/powrpc/ffi_darwin.c (ffi_call_go): New function.
(ffi_prep_go_closure): New function.
(ffi_closure_helper_common): Rename from ffi_closure_helper_DARWIN.
(ffi_closure_helper_DARWIN): Call ffi_closure_helper_common.
(ffi_go_closure_helper_DARWIN): Call ffi_closure_helper_common.
  * src/powerpc/ffitarget.h (FFI_GO_CLOSURES): Define.


Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader

Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.netIndex: libffi/ChangeLog
===
--- ./libffi/ChangeLog	(revision 253377)
+++ ./libffi/ChangeLog	(working copy)
@@ -1,3 +1,18 @@
+2017-08-31  Tony Reix  
+
+	* src/powerpc/aix.S (ffi_call_AIX): Add debugging pseudo-op and labels for EH.
+	(ffi_call_go_AIX): New function.
+	(_GLOBAL__F_libffi_src_powerpc_aix): EH frame.
+	* src/powerpc/aix_closure.S (ffi_closure_ASM): Add debugging pseudo-op and labels for EH.
+	(ffi_go_closure_ASM): New function.
+	(_GLOBAL__F_libffi_src_powerpc_aix_closure): EH frame.
+	* src/powrpc/ffi_darwin.c (ffi_call_go): New function.
+	(ffi_prep_go_closure): New function.
+	(ffi_closure_helper_common): Rename from ffi_closure_helper_DARWIN.
+	(ffi_closure_helper_DARWIN): Call ffi_closure_helper_common.
+	(ffi_go_closure_helper_DARWIN): Call ffi_closure_helper_common.
+	* src/powerpc/ffitarget.h (FFI_GO_CLOSURES): Define.
+
 2017-01-21  Jakub Jelinek  
 
 	PR other/79046
Index: libffi/src/powerpc/aix.S
===
--- ./libffi/src/powerpc/aix.S	(revision 253377)
+++ ./libffi/src/powerpc/aix.S	(working copy)
@@ -106,6 +106,10 @@ ffi_call_AIX:
 	.llong .ffi_call_AIX, TOC[tc0], 0
 	.csect .text[PR]
 .ffi_call_AIX:
+	.function .ffi_call_AIX,.ffi_call_AIX,16,044,LFE..0-LFB..0
+	.bf __LINE__
+	.line 1
+LFB..0:
 	/* Save registers we use.  */
 	mflr	r0
 
@@ -115,8 +119,10 @@ ffi_call_AIX:
 	std	r31, -8(r1)
 
 	std	r0, 16(r1)
+LCFI..0:
 	mr	r28, r1		/* our AP.  */
 	stdux	r1, r1, r4
+LCFI..1:
 
 	/* Save arguments over call...  */
 	mr	r31, r5	/* flags, */
@@ -202,12 +208,16 @@ L(fp_return_value):
 L(float_return_value):
 	stfs	f1, 0(r30)
 	b	L(done_return_value)
-
+LFE..0:
 #else /* ! __64BIT__ */
 	
 	.long .ffi_call_AIX, TOC[tc0], 0
 	.csect .text[PR]
 .ffi_call_AIX:
+	.function .ffi_call_AIX,.ffi_call_AIX,16,044,LFE..0-LFB..0
+	.bf __LINE__
+	.line 1
+LFB..0:
 	/* Save registers we use.  */
 	mflr	r0
 
@@ -217,8 +227,10 @@ L(float_return_value):
 	stw	r31, -4(r1)
 
 	stw	r0, 8(r1)
+LCFI..0:
 	mr	r28, r1		/* out AP.  */
 	stwux	r1, r1, r4
+LCFI..1:
 
 	/* Save arguments over call...  */
 	mr	r31, r5	/* flags, */
@@ -304,13 +316,146 @@ L(fp_return_value):
 L(float_return_value):
 	stfs	f1, 0(r30)
 	b	L(done_return_value)
+LFE..0:
 #endif
+	.ef __LINE__
 	.long 0
 	.byte 0,0,0,1,128,4,0,0
 /* END(ffi_call_AIX) */
 
+	/* void ffi_call_go_AIX(extended_cif *ecif, unsigned long bytes,
+	 *		unsigned int flags, unsigned int *rvalue,
+	 *		void (*fn)(),
+	 *		void (*prep_args)(extended_cif*, unsigned *const),
+	 *  void *closure);
+	 * r3=ecif, r4=bytes, r5=flags, r6=rvalue, r7=fn, r8=prep_args, r9=closure
+	 */
+
 .csect .text[PR]
 	.align 2
+	.globl ffi_call_go_AIX
+	.globl .ffi_call_go_AIX
+.csect ffi_call_go_AIX[DS]
+ffi_call_go_AIX:
+#ifdef __64BIT__
+	.llong .ffi_call_go_AIX, TOC[tc0], 0
+	.csect .text[PR]
+.ffi_call_go_AIX:
+	.function .ffi_call_go_AIX,.ffi_call_go_AIX,16,044,LFE..1-LFB..1
+	.bf __LINE__
+	.line 1
+LFB..1:
+	/* Save registers we use.  */
+	mflr	r0
+
+	std	r28,-32(r1)
+	std	r29,-24(r1)
+	std	r30,-16(r1)
+	std	r31, -8(r1)
+
+	std	r9, 8(r1)	/* closure, saved in cr field. */
+	std	r0, 16(r1)
+LCFI..2:
+	mr	r28, r1		/* our AP.  */
+	stdux	r1, r1, r4
+LCFI..3:
+
+	/* Save arguments over call...  */
+	mr	r31, r5	/* flags, */
+	mr	r30, r6	/* rvalue, */
+	mr	r29, r7	/* function address,  */
+	std	r2, 40(r1)
+
+	/* Call ffi_prep_args.  */
+	mr	r4, r1
+	bl	.ffi_prep_args
+	nop
+
+	/* Now do the call.  */
+	ld	r0, 0(r29)
+	ld	r2, 8(r29)
+	ld  r11, 8(r28)	/* closure */
+	/* Set up cr1 with bits 4-7 of the flags.  */
+	mtcrf	0x40, r31
+	mtctr	r0
+	/* Load all those argument registers.  */
+	/* We have set up a nice stack frame, just load it into registers. */
+	ld	r3, 40+(1*8)(r1)
+	ld	r4, 

RE:[PATCH,AIX] Cleanup in libiberty for AIX.

2017-08-29 Thread REIX, Tony
Description:
 * This patch does some cleanup in libiberty for AIX.

Tests:
 * AIX: Build: SUCCESS
   - build made by means of gmake in trunk.
   - patch generated by: 
cd gcc-svn-trunk/
svn diff libiberty/ChangeLog libiberty/simple-object-xcoff.c

ChangeLog:
   +   * simple-object-xcoff.c (simple_object_xcoff_find_sections):
   +   Improve .go_export csect handling.  Don't make assumptions
   +   on containing section or number of auxiliary entries.

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader

Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net
Index: ./libiberty/ChangeLog
===
--- ./libiberty/ChangeLog	(revision 251399)
+++ ./libiberty/ChangeLog	(working copy)
@@ -1,3 +1,9 @@
+2017-08-29  Tony Reix  
+
+	* simple-object-xcoff.c (simple_object_xcoff_find_sections):
+	Improve .go_export csect handling.  Don't make assumptions
+	on containing section or number of auxiliary entries.
+
 2017-08-28  Richard Biener  
 
 	PR lto/81968
Index: libiberty/simple-object-xcoff.c
===
--- libiberty/simple-object-xcoff.c	(revision 251399)
+++ libiberty/simple-object-xcoff.c	(working copy)
@@ -255,11 +255,15 @@ union external_auxent
 #define IMAGE_SYM_TYPE \
   ((IMAGE_SYM_DTYPE_NULL << 4) | IMAGE_SYM_TYPE_NULL)
 
+#define C_EXT		(2)
 #define C_STAT		(3)
 #define C_FILE		(103)
+#define C_HIDEXT	(107)
 
-#define DBXMASK		0x80
+#define XTY_SD		(1)	/* section definition */
 
+#define XMC_XO		(7)	/* extended operation */
+
 /* Private data for an simple_object_read.  */
 
 struct simple_object_xcoff_read
@@ -400,6 +404,7 @@ simple_object_xcoff_find_sections (simple_object_r
   size_t scnhdr_size;
   unsigned char *scnbuf;
   const char *errmsg;
+  unsigned short (*fetch_16) (const unsigned char *);
   unsigned int (*fetch_32) (const unsigned char *);
   ulong_type (*fetch_64) (const unsigned char *);
   unsigned int nscns;
@@ -407,7 +412,6 @@ simple_object_xcoff_find_sections (simple_object_r
   size_t strtab_size;
   struct external_syment *symtab = NULL;
   unsigned int i;
-  off_t textptr = 0;
 
   scnhdr_size = u64 ? SCNHSZ64 : SCNHSZ32;
   scnbuf = XNEWVEC (unsigned char, scnhdr_size * ocr->nscns);
@@ -420,6 +424,7 @@ simple_object_xcoff_find_sections (simple_object_r
   return errmsg;
 }
 
+  fetch_16 = simple_object_fetch_big_16;
   fetch_32 = simple_object_fetch_big_32;
   fetch_64 = simple_object_fetch_big_64;
 
@@ -433,7 +438,7 @@ simple_object_xcoff_find_sections (simple_object_r
   char namebuf[SCNNMLEN + 1];
   char *name;
   off_t scnptr;
-  unsigned int size;
+  off_t size;
 
   scnhdr = scnbuf + i * scnhdr_size;
   scnname = scnhdr + offsetof (struct external_scnhdr, s_name);
@@ -489,24 +494,24 @@ simple_object_xcoff_find_sections (simple_object_r
 	  u.xcoff32.s_size));
 	}
 
-  if (strcmp (name, ".text") == 0)
-	textptr = scnptr;
   if (!(*pfn) (data, name, scnptr, size))
 	break;
 }
 
-  /* Special handling for .go_export CSECT. */
-  if (textptr != 0 && ocr->nsyms > 0)
+  /* Special handling for .go_export csect.  */
+  if (ocr->nsyms > 0)
 {
-  unsigned char *sym, *aux;
+  unsigned char *sym;
   const char *n_name;
-  unsigned long n_value, n_offset, n_zeroes, x_scnlen;
+  off_t size, n_value;
+  unsigned int n_numaux, n_offset, n_zeroes;
+  short n_scnum;
 
-  /* Read symbol table. */
+  /* Read symbol table.  */
   symtab = XNEWVEC (struct external_syment, ocr->nsyms * SYMESZ);
   if (!simple_object_internal_read (sobj->descriptor,
 	sobj->offset + ocr->symptr,
-	(unsigned char *)symtab,
+	(unsigned char *) symtab,
 	ocr->nsyms * SYMESZ,
 	, err))
 	{
@@ -515,17 +520,25 @@ simple_object_xcoff_find_sections (simple_object_r
 	  return NULL;
 	}
 
-  /* Search in symbol table if we have a ".go_export" symbol. */
-  for (i = 0; i < ocr->nsyms; ++i)
+  /* Search in symbol table if we have a ".go_export" symbol.  */
+  for (i = 0; i < ocr->nsyms; i += n_numaux + 1)
 	{
-	  sym = (unsigned char *)[i];
+	  sym = (unsigned char *) [i];
+	  n_numaux = symtab[i].n_numaux[0];
 
-	  if (symtab[i].n_sclass[0] & DBXMASK)
-	{
-	  /* Skip debug symbols whose names are in stabs. */
-	  i += symtab[i].n_numaux[0];
-	  continue;
-	}
+	  if (symtab[i].n_sclass[0] != C_EXT
+	  && symtab[i].n_sclass[0] != C_HIDEXT)
+	continue;
+
+	  /* Must have at least one csect auxiliary entry.  */
+	  if (n_numaux < 1 || i + n_numaux >= ocr->nsyms)
+	continue;
+
+	  n_scnum = fetch_16 (sym + offsetof (struct external_syment,
+	  n_scnum));
+	  if (n_scnum < 1 || (unsigned int) n_scnum > nscns)
+	continue;
+
 	  if (u64)
 	{
 	  n_value = fetch_64 (sym + offsetof (struct external_syment,
@@ 

[PATCH,AIX] 2nd part of support for DWARF debug sections in XCOFF.

2017-08-03 Thread REIX, Tony
Description:
 * This patch provides the 2nd part of the support for DWARF debug sections in 
XCOFF.
 ImportedSymbols() and ImportedLibraries() functions are not implemented.

Tests:
 * AIX: Build: SUCCESS
   - build made by means of gmake in trunk.
   - patch generated by: 
cd gcc-svn-trunk/
svn diff libgo

ChangeLog:
  * libgo/Makefile.am
  * libgo/Makefile.in
  * libgo/go/cmd/cgo/gcc.go
  * libgo/go/cmd/cgo/out.go
  * libgo/go/debug/dwarf/open.go
  * libgo/go/debug/xcoff/file.go
  * libgo/go/debug/xcoff/xcoff.go
  * libgo/go/go/build/deps_test.go


Cordialement,

Tony Reix
Bull - ATOS
IBM Coop Architect & Technical Leader

Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.netIndex: libgo/Makefile.am
===
--- ./libgo/Makefile.am	(revision 250630)
+++ ./libgo/Makefile.am	(working copy)
@@ -215,7 +215,8 @@ toolexeclibgodebug_DATA = \
 	debug/gosym.gox \
 	debug/macho.gox \
 	debug/pe.gox \
-	debug/plan9obj.gox
+	debug/plan9obj.gox \
+	debug/xcoff.gox
 
 toolexeclibgoencodingdir = $(toolexeclibgodir)/encoding
 
@@ -698,6 +699,7 @@ PACKAGES = \
 	debug/macho \
 	debug/pe \
 	debug/plan9obj \
+	debug/xcoff \
 	encoding \
 	encoding/ascii85 \
 	encoding/asn1 \
@@ -1209,6 +1211,7 @@ TEST_PACKAGES = \
 	debug/macho/check \
 	debug/pe/check \
 	debug/plan9obj/check \
+	debug/xcoff/check \
 	encoding/ascii85/check \
 	encoding/asn1/check \
 	encoding/base32/check \
Index: libgo/Makefile.in
===
--- ./libgo/Makefile.in	(revision 250630)
+++ ./libgo/Makefile.in	(working copy)
@@ -608,7 +608,8 @@ toolexeclibgodebug_DATA = \
 	debug/gosym.gox \
 	debug/macho.gox \
 	debug/pe.gox \
-	debug/plan9obj.gox
+	debug/plan9obj.gox \
+	debug/xcoff.gox
 
 toolexeclibgoencodingdir = $(toolexeclibgodir)/encoding
 toolexeclibgoencoding_DATA = \
@@ -861,6 +862,7 @@ PACKAGES = \
 	debug/macho \
 	debug/pe \
 	debug/plan9obj \
+	debug/xcoff \
 	encoding \
 	encoding/ascii85 \
 	encoding/asn1 \
@@ -1239,6 +1241,7 @@ TEST_PACKAGES = \
 	debug/macho/check \
 	debug/pe/check \
 	debug/plan9obj/check \
+	debug/xcoff/check \
 	encoding/ascii85/check \
 	encoding/asn1/check \
 	encoding/base32/check \
Index: libgo/go/cmd/cgo/gcc.go
===
--- ./libgo/go/cmd/cgo/gcc.go	(revision 250630)
+++ ./libgo/go/cmd/cgo/gcc.go	(working copy)
@@ -13,6 +13,7 @@ import (
 	"debug/elf"
 	"debug/macho"
 	"debug/pe"
+	"debug/xcoff"
 	"encoding/binary"
 	"errors"
 	"flag"
@@ -1230,6 +1231,10 @@ func (p *Package) gccMachine() []string {
 		return []string{"-mabi=64"}
 	case "mips", "mipsle":
 		return []string{"-mabi=32"}
+	case "ppc64":
+		if goos == "aix" {
+			return []string{"-maix64"}
+		}
 	}
 	return nil
 }
@@ -1360,7 +1365,29 @@ func (p *Package) gccDebug(stdin []byte) (*dwarf.D
 		return d, binary.LittleEndian, data
 	}
 
-	fatalf("cannot parse gcc output %s as ELF, Mach-O, PE object", gccTmp())
+	if f, err := xcoff.Open(gccTmp()); err == nil {
+		defer f.Close()
+		d, err := f.DWARF()
+		if err != nil {
+			fatalf("cannot load DWARF output from %s: %v", gccTmp(), err)
+		}
+		var data []byte
+		for _, s := range f.Symbols {
+			if isDebugData(s.Name) {
+if i := int(s.SectionNumber) - 1; 0 <= i && i < len(f.Sections) {
+	sect := f.Sections[i]
+	if s.Value < sect.Size {
+		if sdat, err := sect.Data(); err == nil {
+			data = sdat[s.Value:]
+		}
+	}
+}
+			}
+		}
+		return d, binary.BigEndian, data
+	}
+
+	fatalf("cannot parse gcc output %s as ELF, Mach-O, PE, XCOFF object", gccTmp())
 	panic("not reached")
 }
 
Index: libgo/go/cmd/cgo/out.go
===
--- ./libgo/go/cmd/cgo/out.go	(revision 250630)
+++ ./libgo/go/cmd/cgo/out.go	(working copy)
@@ -9,6 +9,7 @@ import (
 	"debug/elf"
 	"debug/macho"
 	"debug/pe"
+	"debug/xcoff"
 	"fmt"
 	"go/ast"
 	"go/printer"
@@ -324,7 +325,28 @@ func dynimport(obj string) {
 		return
 	}
 
-	fatalf("cannot parse %s as ELF, Mach-O or PE", obj)
+	if f, err := xcoff.Open(obj); err == nil {
+		sym, err := f.ImportedSymbols()
+		if err != nil {
+			fatalf("cannot load imported symbols from XCOFF file %s: %v", obj, err)
+		}
+		for _, s := range sym {
+			if len(s) > 0 && s[0] == '.' {
+s = s[1:]
+			}
+			fmt.Fprintf(stdout, "//go:cgo_import_dynamic %s %s %q\n", s, s, "")
+		}
+		lib, err := f.ImportedLibraries()
+		if err != nil {
+			fatalf("cannot load imported libraries from XCOFF file %s: %v", obj, err)
+		}
+		for _, l := range lib {
+			fmt.Fprintf(stdout, "//go:cgo_import_dynamic _ _ %q\n", l)
+		}
+		return
+	}
+
+	fatalf("cannot parse %s as ELF, Mach-O, PE or XCOFF", obj)
 }
 
 // Construct a gcc struct matching the gc argument frame.
Index: libgo/go/debug/dwarf/open.go
===
--- ./libgo/go/debug/dwarf/open.go	(revision 

[PATCH,AIX] Initial support for DWARF debug sections in XCOFF.

2017-08-01 Thread REIX, Tony
Description:
 * This patch provides an initial support for DWARF debug sections in XCOFF.

Tests:
 * AIX: Build: SUCCESS
   - build made by means of gmake.

ChangeLog:
  * xcoff.c: Initial support for DWARF debug sections in XCOFF.

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader

Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.netIndex: libbacktrace/ChangeLog
===
--- libbacktrace/ChangeLog	(revision 250777)
+++ libbacktrace/ChangeLog	(working copy)
@@ -1,3 +1,7 @@
+2017-08-01  Tony Reix  
+
+	* xcoff.c: Initial support for DWARF debug sections in XCOFF.
+
 2017-07-28  Tony Reix  
 
 	* xcoff.c: Don't leak a file descriptor if an archive is malformed.
Index: libbacktrace/xcoff.c
===
--- libbacktrace/xcoff.c	(revision 250777)
+++ libbacktrace/xcoff.c	(working copy)
@@ -124,9 +124,16 @@ typedef struct {
 
 #endif /* BACKTRACE_XCOFF_SIZE != 32 */
 
+#define STYP_DWARF	0x10	/* DWARF debugging section.  */
 #define STYP_TEXT	0x20	/* Executable text (code) section.  */
 #define STYP_OVRFLO	0x8000	/* Line-number field overflow section.  */
 
+#define SSUBTYP_DWINFO	0x1	/* DWARF info section.  */
+#define SSUBTYP_DWLINE	0x2	/* DWARF line-number section.  */
+#define SSUBTYP_DWARNGE	0x5	/* DWARF aranges section.  */
+#define SSUBTYP_DWABREV	0x6	/* DWARF abbreviation section.  */
+#define SSUBTYP_DWSTR	0x7	/* DWARF strings section.  */
+
 /* XCOFF symbol.  */
 
 #define SYMNMLEN	8
@@ -367,7 +374,30 @@ struct xcoff_fileline_data
   struct xcoff_line_vector vec;
 };
 
+/* An index of DWARF sections we care about.  */
 
+enum dwarf_section
+{
+  DWSECT_INFO,
+  DWSECT_LINE,
+  DWSECT_ABBREV,
+  DWSECT_RANGES,
+  DWSECT_STR,
+  DWSECT_MAX
+};
+
+/* Information we gather for the DWARF sections we care about.  */
+
+struct dwsect_info
+{
+  /* Section file offset.  */
+  off_t offset;
+  /* Section size.  */
+  size_t size;
+  /* Section contents, after read from file.  */
+  const unsigned char *data;
+};
+
 /* A dummy callback function used when we can't find any debug info.  */
 
 static int
@@ -1056,6 +1086,7 @@ xcoff_add (struct backtrace_state *state, int desc
   struct backtrace_view linenos_view;
   struct backtrace_view syms_view;
   struct backtrace_view str_view;
+  struct backtrace_view dwarf_view;
   b_xcoff_filhdr fhdr;
   const b_xcoff_scnhdr *sects;
   const b_xcoff_scnhdr *stext;
@@ -1062,6 +1093,9 @@ xcoff_add (struct backtrace_state *state, int desc
   uint64_t lnnoptr;
   uint32_t nlnno;
   off_t str_off;
+  off_t min_offset;
+  off_t max_offset;
+  struct dwsect_info dwsect[DWSECT_MAX];
   size_t sects_size;
   size_t syms_size;
   int32_t str_size;
@@ -1069,6 +1103,7 @@ xcoff_add (struct backtrace_state *state, int desc
   int linenos_view_valid;
   int syms_view_valid;
   int str_view_valid;
+  int dwarf_view_valid;
   int magic_ok;
   int i;
 
@@ -1078,7 +1113,10 @@ xcoff_add (struct backtrace_state *state, int desc
   linenos_view_valid = 0;
   syms_view_valid = 0;
   str_view_valid = 0;
+  dwarf_view_valid = 0;
 
+  str_size = 0;
+
   /* Map the XCOFF file header.  */
   if (!backtrace_get_view (state, descriptor, offset, sizeof (b_xcoff_filhdr),
 			   error_callback, data, _view))
@@ -1092,7 +1130,7 @@ xcoff_add (struct backtrace_state *state, int desc
   if (!magic_ok)
 {
   if (exe)
-error_callback (data, "executable file is not XCOFF", 0);
+	error_callback (data, "executable file is not XCOFF", 0);
   goto fail;
 }
 
@@ -1114,8 +1152,8 @@ xcoff_add (struct backtrace_state *state, int desc
 
   /* FIXME: assumes only one .text section.  */
   for (i = 0; i < fhdr.f_nscns; ++i)
-  if ((sects[i].s_flags & 0x) == STYP_TEXT)
-	  break;
+if ((sects[i].s_flags & 0x) == STYP_TEXT)
+  break;
   if (i == fhdr.f_nscns)
 goto fail;
 
@@ -1134,12 +1172,12 @@ xcoff_add (struct backtrace_state *state, int desc
   /* Find the matching .ovrflo section.  */
   for (i = 0; i < fhdr.f_nscns; ++i)
 	{
-	if (((sects[i].s_flags & 0x) == STYP_OVRFLO)
-		&& sects[i].s_nlnno == sntext)
-	  {
-		nlnno = sects[i].s_vaddr;
-		break;
-	  }
+	  if (((sects[i].s_flags & 0x) == STYP_OVRFLO)
+	  && sects[i].s_nlnno == sntext)
+	{
+	  nlnno = sects[i].s_vaddr;
+	  break;
+	}
 	}
 }
 #endif
@@ -1194,10 +1232,92 @@ xcoff_add (struct backtrace_state *state, int desc
   xcoff_add_syminfo_data (state, sdata);
 }
 
-  /* Read the line number entries.  */
+  /* Read all the DWARF sections in a single view, since they are
+ probably adjacent in the file.  We never release this view.  */
 
-  if (fhdr.f_symptr != 0 && lnnoptr != 0)
+  min_offset = 0;
+  max_offset = 0;
+  memset (dwsect, 0, sizeof dwsect);
+  for (i = 0; i < fhdr.f_nscns; ++i)
 {
+  off_t end;
+  

RE:[PATCH,AIX] Changes for linking gotools on AIX.

2017-07-27 Thread REIX, Tony
Hi Ian, David,

On AIX, that is more complicated...

We have to use -static-libgo when building the libgo tests. Because AIX does 
not work like Linux does and because the Go libgo tests are done by duplicating 
several .go files of libgo packages that already appear in the libgo.a 
(libgo.so) library.
On AIX, without -static-libgo, when building/running the libgo tests, we have 
Go variables defined somewhere and used elsewhere, BUT with different memory 
addresses... leading to bad issues...

However, when building/linking real Go application code outside of Gcc Go 
compiler, and thus with NO 2-times compiled libgo internal code, we have 
another issue and we need to load libgo.a at first, otherwise we have other 
issues.

In short, this patch is the first step of a global fix we have found for AIX 
for covering the 2 cases: build/run libgo internal tests, and build real 
NO-libgo internal customer code. And it works fine.
I'll provide the second step later.


Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : Ian Lance Taylor [i...@golang.org]
Envoyé : mercredi 26 juillet 2017 20:06
À : David Edelsohn
Cc : REIX, Tony; gcc-patches@gcc.gnu.org
Objet : Re: [PATCH,AIX] Changes for linking gotools on AIX.

On Wed, Jul 26, 2017 at 9:58 AM, David Edelsohn <dje@gmail.com> wrote:
> On Wed, Jul 26, 2017 at 12:41 PM, REIX, Tony <tony.r...@atos.net> wrote:
>> Description:
>>  * This patch adds linker options for gotools for AIX.
>>
>> Tests:
>>  * Fedora25/x86_64 + GCC trunk : Configure/Build: SUCCESS
>>- build remade by means of gmake.
>>- some test redone in libgo (gmake check)
>>  * AIX + GCC 7.1.0 :
>>- build remade by means of gmake.
>>- some test redone in libgo (gmake check)
>>
>> ChangeLog:
>>  * Makefile.am (AM_LDFLAGS & GOLINK): Changes for linking on AIX.
>>  * Makefile.in: Rebuild.
>
> If this is trying to fix AIX search paths, a better solution would
> seem to be the equivalent of -static-libstdc++ -static-libgcc.  The Go
> tools should be linked statically and not depend on Go shared
> libraries.

On GNU/Linux I used to use -static-libgo, but I changed it because of
https://gcc.gnu.org/PR64738.  Of course on AIX we can do as you
prefer.

Ian


RE:[PATCH,AIX] Don't leak a file descriptor if an archive is malformed.

2017-07-27 Thread REIX, Tony
Better with the patch file...
Sorry. The Resend did not add the joint file I added with first message (in 
HTML format, refused).
Hope it's OK now.
Tony
Index: libbacktrace/ChangeLog
===
--- libbacktrace/ChangeLog	(revision 250609)
+++ libbacktrace/ChangeLog	(working copy)
@@ -1,3 +1,7 @@
+2017-07-27  Tony Reix  
+
+	* xcoff.c: Don't leak a file descriptor if an archive is malformed.
+
 2017-07-26  Tony Reix  
 
 	* configure.ac: Check for XCOFF32/XCOFF64.  Check for loadquery.
Index: libbacktrace/xcoff.c
===
--- libbacktrace/xcoff.c	(revision 250609)
+++ libbacktrace/xcoff.c	(working copy)
@@ -1288,7 +1288,7 @@ xcoff_armem_add (struct backtrace_state *state, in
 
   if (!backtrace_get_view (state, descriptor, 0, sizeof (b_ar_fl_hdr),
 			   error_callback, data, ))
-return 0;
+goto fail;
 
   memcpy (_hdr, view.data, sizeof (b_ar_fl_hdr));
 
@@ -1295,13 +1295,13 @@ xcoff_armem_add (struct backtrace_state *state, in
   backtrace_release_view (state, , error_callback, data);
 
   if (memcmp (fl_hdr.fl_magic, AIAMAGBIG, 8) != 0)
-return 0;
+goto fail;
 
   memlen = strlen (member);
 
   /* Read offset of first archive member.  */
   if (!xcoff_parse_decimal (fl_hdr.fl_fstmoff, sizeof fl_hdr.fl_fstmoff, ))
-return 0;
+goto fail;
   while (off != 0)
 {
   /* Map archive member header and member name.  */
@@ -1309,7 +1309,7 @@ xcoff_armem_add (struct backtrace_state *state, in
   if (!backtrace_get_view (state, descriptor, off,
 			   sizeof (b_ar_hdr) + memlen,
 			   error_callback, data, ))
-	return 0;
+	break;
 
   ar_hdr = (const b_ar_hdr *) view.data;
 
@@ -1345,6 +1345,7 @@ xcoff_armem_add (struct backtrace_state *state, in
   backtrace_release_view (state, , error_callback, data);
 }
 
+ fail:
   /* No matching member found.  */
   backtrace_close (descriptor, error_callback, data);
   return 0;


[PATCH,AIX] Don't leak a file descriptor if an archive is malformed.

2017-07-27 Thread REIX, Tony
(Damned ! Brut text format required !!)

Description:
 * This patch fixes a possible leak of a file descriptor if an archive is 
malformed.

Tests:
 * Fedora25/x86_64 + GCC trunk : SUCCESS
   - gmake in libbacktrace directory
 * AIX :
   - gmake in libbacktrace directory

ChangeLog:
 * xcoff.c: Don't leak a file descriptor if an archive is malformed.

Cordialement,

Tony Reix


Bull - ATOS
IBM Coop Architect & Technical Leader

Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


[PATCH,AIX] Changes for linking gotools on AIX.

2017-07-26 Thread REIX, Tony
Description:
 * This patch adds linker options for gotools for AIX.

Tests:
 * Fedora25/x86_64 + GCC trunk : Configure/Build: SUCCESS
   - build remade by means of gmake.
   - some test redone in libgo (gmake check)
 * AIX + GCC 7.1.0 :
   - build remade by means of gmake.
   - some test redone in libgo (gmake check)
 
ChangeLog:
 * Makefile.am (AM_LDFLAGS & GOLINK): Changes for linking on AIX.
 * Makefile.in: Rebuild.

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.netIndex: gotools/ChangeLog
===
--- gotools/ChangeLog	(révision 250563)
+++ gotools/ChangeLog	(copie de travail)
@@ -1,3 +1,8 @@
+2017-07-26  Tony Reix  
+
+	* Makefile.am (AM_LDFLAGS & GOLINK): Changes for linking on AIX.
+	* Makefile.in: Rebuild.
+
 2017-07-15  Ian Lance Taylor  
 
 	* Makefile.am (CHECK_ENV): Set GOROOT.
Index: gotools/Makefile.am
===
--- gotools/Makefile.am	(révision 250563)
+++ gotools/Makefile.am	(copie de travail)
@@ -40,7 +40,11 @@ GOCOMPILE = $(GOCOMPILER) $(GOCFLAGS)
 
 AM_GOCFLAGS = -I $(libgodir)
 AM_LDFLAGS = -L $(libgodir) -L $(libgodir)/.libs
-GOLINK = $(GOCOMPILER) $(GOCFLAGS) $(AM_GOCFLAGS) $(LDFLAGS) $(AM_LDFLAGS) -o $@
+ifeq ($(shell uname), AIX)
+AM_LDFLAGS += -Wl,-blibpath:$(libdir):/usr/lib:/lib
+GOLINK = LIBRARY_PATH=$(libgodir)/.libs
+endif
+GOLINK += $(GOCOMPILER) $(GOCFLAGS) $(AM_GOCFLAGS) $(LDFLAGS) $(AM_LDFLAGS) -o $@
 
 libgosrcdir = $(srcdir)/../libgo/go
 cmdsrcdir = $(libgosrcdir)/cmd
Index: gotools/Makefile.in
===
--- gotools/Makefile.in	(révision 250563)
+++ gotools/Makefile.in	(copie de travail)
@@ -260,7 +260,11 @@ LIBGODEP = $(libgodir)/libgo.la
 GOCOMPILE = $(GOCOMPILER) $(GOCFLAGS)
 AM_GOCFLAGS = -I $(libgodir)
 AM_LDFLAGS = -L $(libgodir) -L $(libgodir)/.libs
-GOLINK = $(GOCOMPILER) $(GOCFLAGS) $(AM_GOCFLAGS) $(LDFLAGS) $(AM_LDFLAGS) -o $@
+ifeq ($(shell uname), AIX)
+AM_LDFLAGS += -Wl,-blibpath:$(libdir):/usr/lib:/lib
+GOLINK = LIBRARY_PATH=$(libgodir)/.libs
+endif
+GOLINK += $(GOCOMPILER) $(GOCFLAGS) $(AM_GOCFLAGS) $(LDFLAGS) $(AM_LDFLAGS) -o $@
 libgosrcdir = $(srcdir)/../libgo/go
 cmdsrcdir = $(libgosrcdir)/cmd
 libgomiscdir = $(srcdir)/../libgo/misc


[PATCH,AIX] Enable libffi for AIX

2017-07-26 Thread REIX, Tony
Description:
 * This patch enables libffi on AIX.

Tests:
 * Fedora25/x86_64 + GCC trunk : Configure/Build: SUCCESS
   - build made by means of gmake.

ChangeLog:
 * configure.ac, configure: Enable libffi for AIX

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.netIndex: ChangeLog
===
--- ChangeLog	(révision 250563)
+++ ChangeLog	(copie de travail)
@@ -1,3 +1,8 @@
+2017-07-26  Tony Reix  
+
+	* configure.ac, configure: Enable Go for AIX
+	* configure.ac, configure: Enable libffi for AIX
+
 2017-07-19  Yury Gribov  
 
 	* MAINTAINERS: Add myself.
Index: configure
===
--- configure	(révision 250563)
+++ configure	(copie de travail)
@@ -3463,11 +3463,8 @@ case "${target}" in
 noconfigdirs="$noconfigdirs target-libffi"
 ;;
   powerpc-*-aix*)
-# copied from rs6000-*-* entry
-noconfigdirs="$noconfigdirs target-libffi"
 ;;
   rs6000-*-aix*)
-noconfigdirs="$noconfigdirs target-libffi"
 ;;
   ft32-*-*)
 noconfigdirs="$noconfigdirs target-libffi"
Index: configure.ac
===
--- configure.ac	(révision 250563)
+++ configure.ac	(copie de travail)
@@ -791,11 +791,8 @@ case "${target}" in
 noconfigdirs="$noconfigdirs target-libffi"
 ;;
   powerpc-*-aix*)
-# copied from rs6000-*-* entry
-noconfigdirs="$noconfigdirs target-libffi"
 ;;
   rs6000-*-aix*)
-noconfigdirs="$noconfigdirs target-libffi"
 ;;
   ft32-*-*)
 noconfigdirs="$noconfigdirs target-libffi"


[PATCH,AIX] Enable Go for AIX

2017-07-26 Thread REIX, Tony
Description:
 * This patch enables Go on AIX.

Tests:
 * Fedora25/x86_64 + GCC trunk : Configure/Build: SUCCESS
   - build made by means of gmake.

ChangeLog:
 * configure.ac, configure: Enable Go for AIX
 * contrib/config-list.mk: Enable Go for AIX


Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader

Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net






Index: ChangeLog
===
--- ChangeLog	(révision 250563)
+++ ChangeLog	(copie de travail)
@@ -1,3 +1,7 @@
+2017-07-26  Tony Reix  
+
+	* configure.ac, configure: Enable Go for AIX
+
 2017-07-19  Yury Gribov  
 
 	* MAINTAINERS: Add myself.
Index: configure
===
--- configure	(révision 250563)
+++ configure	(copie de travail)
@@ -3480,7 +3480,7 @@ esac
 # Disable the go frontend on systems where it is known to not work. Please keep
 # this in sync with contrib/config-list.mk.
 case "${target}" in
-*-*-darwin* | *-*-cygwin* | *-*-mingw* | *-*-aix*)
+*-*-darwin* | *-*-cygwin* | *-*-mingw*)
 unsupported_languages="$unsupported_languages go"
 ;;
 esac
@@ -3496,9 +3496,6 @@ if test x$enable_libgo = x; then
 *-*-cygwin* | *-*-mingw*)
 	noconfigdirs="$noconfigdirs target-libgo"
 	;;
-*-*-aix*)
-	noconfigdirs="$noconfigdirs target-libgo"
-	;;
 esac
 fi
 
Index: configure.ac
===
--- configure.ac	(révision 250563)
+++ configure.ac	(copie de travail)
@@ -808,7 +808,7 @@ esac
 # Disable the go frontend on systems where it is known to not work. Please keep
 # this in sync with contrib/config-list.mk.
 case "${target}" in
-*-*-darwin* | *-*-cygwin* | *-*-mingw* | *-*-aix*)
+*-*-darwin* | *-*-cygwin* | *-*-mingw*)
 unsupported_languages="$unsupported_languages go"
 ;;
 esac
@@ -824,9 +824,6 @@ if test x$enable_libgo = x; then
 *-*-cygwin* | *-*-mingw*)
 	noconfigdirs="$noconfigdirs target-libgo"
 	;;
-*-*-aix*)
-	noconfigdirs="$noconfigdirs target-libgo"
-	;;
 esac
 fi
 
Index: contrib/ChangeLog
===
--- contrib/ChangeLog	(révision 250563)
+++ contrib/ChangeLog	(copie de travail)
@@ -1,3 +1,7 @@
+2017-07-26  Tony Reix  
+
+	* config-list.mk: Enable Go for AIX
+
 2017-07-17  Yury Gribov  
 
 	* mklog: Fix extraction of changed file name.
Index: contrib/config-list.mk
===
--- contrib/config-list.mk	(révision 250563)
+++ contrib/config-list.mk	(copie de travail)
@@ -121,7 +121,7 @@ $(LIST): make-log-dir
 		TGT=`echo $@ | awk 'BEGIN { FS = "OPT" }; { print $$1 }'` &&			\
 		TGT=`$(GCC_SRC_DIR)/config.sub $$TGT` &&	\
 		case $$TGT in	\
-			*-*-darwin* | *-*-cygwin* | *-*-mingw* | *-*-aix*)			\
+			*-*-darwin* | *-*-cygwin* | *-*-mingw*)	\
 ADDITIONAL_LANGUAGES="";	\
 ;;\
 			*)	\


[PATCH,AIX] Manage .go_export section for AIX

2017-07-26 Thread REIX, Tony
Description:
 * This patch manages the .go_export section as an EXCLUDE section on AIX.

Tests:
 * Fedora25/x86_64 + GCC trunk : Configure/Build: SUCCESS
   - build made by means of gmake.

ChangeLog:
 * go-backend.c (go_write_export_data): Use EXCLUDE section for AIX.


Cordialement,

Tony Reix
Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.netIndex: gcc/go/ChangeLog
===
--- gcc/go/ChangeLog	(révision 250528)
+++ gcc/go/ChangeLog	(copie de travail)
@@ -1,3 +1,7 @@
+2017-07-26  Tony Reix  
+
+	* go-backend.c (go_write_export_data): Use EXCLUDE section for AIX.
+
 2017-06-09  Ian Lance Taylor  
 
 	* go-lang.c (go_langhook_post_options): If -fsplit-stack is turned
Index: gcc/go/go-backend.c
===
--- gcc/go/go-backend.c	(révision 250528)
+++ gcc/go/go-backend.c	(copie de travail)
@@ -101,7 +101,11 @@ go_write_export_data (const char *bytes, unsigned
   if (sec == NULL)
 {
   gcc_assert (targetm_common.have_named_sections);
+#ifndef _AIX
   sec = get_section (GO_EXPORT_SECTION_NAME, SECTION_DEBUG, NULL);
+#else
+  sec = get_section (GO_EXPORT_SECTION_NAME, SECTION_EXCLUDE, NULL);
+#endif
 }
 
   switch_to_section (sec);


[PATCH,AIX] Fully enable XCOFF in libbacktrace on AIX

2017-07-26 Thread REIX, Tony
Description:
 * This patch fully enables XCOFF in libbacktrace on AIX.

Tests:
 * Fedora25/x86_64 + GCC v7.1.0 : Configure/Build: SUCCESS
   - build made by means of gmake.

ChangeLog:
  * configure.ac, filetype.awk: Separate AIX XCOFF32 and XCOFF64.
  * xcoff.c: Add support for AIX XCOFF32 and XCOFF64 formats.
  * configure, config.h.in: Regenerate.

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net









Index: libbacktrace/ChangeLog
===
--- libbacktrace/ChangeLog	(revision 250514)
+++ libbacktrace/ChangeLog	(working copy)
@@ -1,3 +1,9 @@
+2017-07-25  Tony Reix  
+
+	* configure.ac, filetype.awk: Separate AIX XCOFF32 and XCOFF64.
+	* xcoff.c: Add support for AIX XCOFF32 and XCOFF64 formats.
+	* configure, config.h.in: Regenerate.
+
 2017-07-21  Tony Reix  
 
 	* filetype.awk: Add AIX XCOFF type detection.
Index: libbacktrace/config.h.in
===
--- libbacktrace/config.h.in	(revision 250514)
+++ libbacktrace/config.h.in	(working copy)
@@ -3,6 +3,9 @@
 /* ELF size: 32 or 64 */
 #undef BACKTRACE_ELF_SIZE
 
+/* XCOFF size: 32 or 64 */
+#undef BACKTRACE_XCOFF_SIZE
+
 /* Define to 1 if you have the __atomic functions */
 #undef HAVE_ATOMIC_FUNCTIONS
 
Index: libbacktrace/configure
===
--- libbacktrace/configure	(revision 250514)
+++ libbacktrace/configure	(working copy)
@@ -12048,9 +12048,9 @@ elf*) FORMAT_FILE="elf.lo" ;;
 pecoff) FORMAT_FILE="pecoff.lo"
 backtrace_supports_data=no
 	;;
-xcoff) FORMAT_FILE="xcoff.lo"
-   backtrace_supports_data=no
-   ;;
+xcoff*) FORMAT_FILE="xcoff.lo"
+backtrace_supports_data=no
+;;
 *) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: could not determine output file type" >&5
 $as_echo "$as_me: WARNING: could not determine output file type" >&2;}
FORMAT_FILE="unknown.lo"
@@ -12072,6 +12072,19 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+# XCOFF defines.
+xcoffsize=
+case "$libbacktrace_cv_sys_filetype" in
+xcoff32) xcoffsize=32 ;;
+xcoff64) xcoffsize=64 ;;
+*)   xcoffsize=unused
+esac
+
+cat >>confdefs.h <<_ACEOF
+#define BACKTRACE_XCOFF_SIZE $xcoffsize
+_ACEOF
+
+
 BACKTRACE_SUPPORTED=0
 if test "$backtrace_supported" = "yes"; then
   BACKTRACE_SUPPORTED=1
Index: libbacktrace/configure.ac
===
--- libbacktrace/configure.ac	(revision 250514)
+++ libbacktrace/configure.ac	(working copy)
@@ -233,9 +233,9 @@ elf*) FORMAT_FILE="elf.lo" ;;
 pecoff) FORMAT_FILE="pecoff.lo"
 backtrace_supports_data=no
 	;;
-xcoff) FORMAT_FILE="xcoff.lo"
-   backtrace_supports_data=no
-   ;;
+xcoff*) FORMAT_FILE="xcoff.lo"
+backtrace_supports_data=no
+;;
 *) AC_MSG_WARN([could not determine output file type])
FORMAT_FILE="unknown.lo"
backtrace_supported=no
@@ -252,6 +252,15 @@ elf64) elfsize=64 ;;
 esac
 AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
 
+# XCOFF defines.
+xcoffsize=
+case "$libbacktrace_cv_sys_filetype" in
+xcoff32) xcoffsize=32 ;;
+xcoff64) xcoffsize=64 ;;
+*)   xcoffsize=unused
+esac
+AC_DEFINE_UNQUOTED([BACKTRACE_XCOFF_SIZE], [$xcoffsize], [XCOFF size: 32 or 64])
+
 BACKTRACE_SUPPORTED=0
 if test "$backtrace_supported" = "yes"; then
   BACKTRACE_SUPPORTED=1
Index: libbacktrace/filetype.awk
===
--- libbacktrace/filetype.awk	(revision 250514)
+++ libbacktrace/filetype.awk	(working copy)
@@ -3,6 +3,6 @@
 /\177ELF\002/ { if (NR == 1) { print "elf64"; exit } }
 /\114\001/{ if (NR == 1) { print "pecoff"; exit } }
 /\144\206/{ if (NR == 1) { print "pecoff"; exit } }
-/\001\337/{ if (NR == 1) { print "xcoff"; exit } }
-/\001\367/{ if (NR == 1) { print "xcoff"; exit } }
+/\001\337/{ if (NR == 1) { print "xcoff32"; exit } }
+/\001\367/{ if (NR == 1) { print "xcoff64"; exit } }
 
Index: libbacktrace/xcoff.c
===
--- libbacktrace/xcoff.c	(revision 250514)
+++ libbacktrace/xcoff.c	(working copy)
@@ -1,5 +1,6 @@
-/* xcoff.c -- Get debug data from a XCOFFF file for backtraces.
-   Copyright (C) 2017 Free Software Foundation, Inc.
+/* xcoff.c -- Get debug data from an XCOFF file for backtraces.
+   Copyright (C) 2012-2017 Free Software Foundation, Inc.
+   Adapted from elf.c.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
@@ -31,46 +32,1460 @@ POSSIBILITY OF SUCH DAMAGE.  */
 
 #include "config.h"
 
+#include 
+#include 
 #include 
+#ifdef _AIX
+/* AIX loadquery.  */
+#include 
+#include 
+#endif
 
 #include "backtrace.h"
 #include "internal.h"

RE:[PATCH,AIX] Enable libiberty to read AIX XCOFF

2017-06-07 Thread REIX, Tony
Hi David,

I'll fix the code incorrectly indented.

About your comment about our code looking for TEXT section by looking at string 
".text"  , please note that our patch fixes a file called 
"simple-object-xcoff.c" : SIMPLE.
Do not expect us to handle more than required.

However, are you sure that  -ffunction-sections  is implemented on AIX ? 

Moreover, if it is not implemented on AIX, don't you think that such an option 
which is documented as:
" Place each function or data item into its own section in the output file if 
the
target supports arbitrary sections. The name of the function or the name of
the data item determines the section’s name in the output file.
Use these options on systems where the linker can perform optimizations to
improve locality of reference in the instruction space. Most systems using the
ELF object format and SPARC processors running Solaris 2 have linkers with
such optimizations. AIX may have these optimizations in the future.
Only use these options when there are significant benefits from doing so. When
you specify these options, the assembler and linker create larger object and
executable files and are also slower."
is not compatible with the already existing high complexity of GCC Go 
implementation ?and should be forbidden with Go on AIX ?


We have tried another approach:
127a128
> #define STYP_TEXT 0x20
408a410
>   unsigned int flags;
482a485,486
> flags = fetch_32 (scnhdr + offsetof (struct external_scnhdr,
>  u.xcoff64.s_flags));
489a494,495
> flags = fetch_32 (scnhdr + offsetof (struct external_scnhdr,
>  u.xcoff32.s_flags));
492c498
<   if (strcmp (name, ".text") == 0)
---
>   if ((flags & 0x) == STYP_TEXT)

However, that makes never-seen-before errors to appear when running libgo tests 
in always-succeeding libgo tests, like: bufio & bytes.


Since we have many other GCC Go stuff on AIX to handle, wouldn't it be possible 
to start with this implementation and to improve it later if it needs to be 
hardened ?
Document it as a limitation.


Regards,

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : David Edelsohn [dje@gmail.com]
Envoyé : mercredi 7 juin 2017 01:25
À : REIX, Tony; Ian Taylor
Cc : SARTER, MATTHIEU (ext); GCC Patches
Objet : Re: [PATCH,AIX] Enable libiberty to read AIX XCOFF

Tony,

This patch generally looks good to me -- it clearly is an incremental
improvement.  One of the libiberty maintainers, such as Ian, needs to
approve the patch.

https://gcc.gnu.org/ml/gcc-patches/2017-05/msg01181.html

+  if (strcmp (name, ".text") == 0)
+textptr = scnptr;

The above code does not seem very robust.  What if the application is
compiled with -ffunction-sections so the text section is not named
".text"?

+  if (strtab == NULL)
+{
+ XDELETEVEC (symtab);
+  XDELETEVEC (scnbuf);
+  return errmsg;

The first XDELETEVEC (symtab) is indented incorrectly and should be fixed.

Thanks, David


RE:[PATCH,AIX] Enable libiberty to read AIX XCOFF

2017-06-07 Thread REIX, Tony
Hi DJ

A) XNEWVEC

1) ./include/libiberty.h:

It appears that XNEWVEC() calls xmalloc which prints a message and calls xexit 
if malloc fails.

#define XNEWVEC(T, N) ((T *) xmalloc (sizeof (T) * (N)))

/* Allocate memory without fail.  If malloc fails, this will print a
   message to stderr (using the name set by xmalloc_set_program_name,
   if any) and then call xexit.  */
extern void *xmalloc (size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;


2)  ./libiberty/simple-object-xcoff.c :

It appears that  XNEWVEC() was already called 2 times before we added a third 
use of it, and still with NO check of return.

simple_object_xcoff_read_strtab (...)
{
...
  strtab = XNEWVEC (char, strsize);
  if (!simple_object_internal_read (sobj->descriptor, strtab_offset,
(unsigned char *) strtab, strsize, errmsg,
err))
...

simple_object_xcoff_find_sections (...)
{
 ...
  scnbuf = XNEWVEC (unsigned char, scnhdr_size * ocr->nscns);
  if (!simple_object_internal_read (sobj->descriptor,
sobj->offset + ocr->scnhdr_offset,
scnbuf, scnhdr_size * ocr->nscns, ,
err))


Thus, I think that we should continue to do what we did and do NOT check the 
return of XNEWVEC() .



B) XDELETEVEC

1) ./include/libiberty.h:

#define XDELETEVEC(P) free ((void*) (P))


2) free() documentation : The free subroutine deallocates a  ... If the Pointer 
parameter is NULL, no action occurs.


So, yes, we check   if (strtab == NULL)   though there is no way that 
XDELETEVEC(NULL) breaks something.
However, it is a classic programming style.

And the same programming style was used before we added our patch in 
simple_object_xcoff_find_sections () :
  /* The real section name is found in the string
 table.  */
  if (strtab == NULL)
{
  strtab = simple_object_xcoff_read_strtab (sobj,
   _size,
   , err);
  if (strtab == NULL)
{
  XDELETEVEC (scnbuf);
  return errmsg;
}
}

So our new code seems coherent with previous existing code.


Regards,

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : DJ Delorie [d...@redhat.com]
Envoyé : mercredi 7 juin 2017 01:52
À : David Edelsohn
Cc : REIX, Tony; i...@golang.org; SARTER, MATTHIEU (ext); 
gcc-patches@gcc.gnu.org
Objet : Re: [PATCH,AIX] Enable libiberty to read AIX XCOFF

David Edelsohn <dje@gmail.com> writes:
> This patch generally looks good to me -- it clearly is an incremental
> improvement.  One of the libiberty maintainers, such as Ian, needs to
> approve the patch.

As AIX maintainer, I think you have the authority to approve patches
like this, which only affect your OS.  I see no reason to reject the
patch myself, other than:

+  symtab = XNEWVEC (struct external_syment, ocr->nsyms * SYMESZ);
+  if (!simple_object_internal_read (sobj->descriptor,

There's no check to see if XNEWVEC succeeded.


Also, the use of XDELETEVEC is inconsistently protected with a "if (foo
!= NULL)" throughout, but passing NULL to XDELETEVEC (essentially,
free()) is allowed anyway, so this is only a stylistic issue, which I'm
not particularly worried about.



RE:[PATCH,AIX] Enable FFI Go Closure on AIX

2017-05-17 Thread REIX, Tony
Patch has been submitted to libffi github : 
https://github.com/libffi/libffi/pull/308 .

Regards,

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : REIX, Tony
Envoyé : mercredi 17 mai 2017 14:53
À : David Edelsohn
Cc : GCC Patches; SARTER, MATTHIEU (ext)
Objet : RE:[PATCH,AIX] Enable FFI Go Closure on AIX

Hi,

We have built and installed the libffi master of yesterday on a AIX 6.1 machine 
and we have rebuilt and tested Python3 (3.5.2) with this libffi. And that is 
OK. 32bit and 64bit.

5 more tests were run and succeeded.
And 1 test (test_ssl) which was skipped before is now run but failed due to no 
access to Web (Resource 'sha256.tbs-internet.com' is not available).

So. our patch does not break libffi build and tests, nor Python3 build and 
tests.

That looks OK.

We'll submit the patch to the libffi project now.

Regards,

Tony


With New libffi:

369 tests OK.
12 tests failed:
test_asyncio test_distutils test_eintr test_httpservers
test_locale test_posix test_socket test_ssl test_tools
test_urllib2 test_urllib2_localnet test_urllib2net
1 test altered the execution environment:
test_io
16 tests skipped:
test_devpoll test_epoll test_gdb test_kqueue test_msilib
test_ossaudiodev test_pep277 test_spwd test_startfile test_tix
test_tk test_ttk_guionly test_unicode_file test_winreg
test_winsound test_zipfile64


With previous libffi:

364 tests OK.
11 tests failed:
test_asyncio test_distutils test_eintr test_httpservers
test_locale test_posix test_socket test_tools test_urllib2
test_urllib2_localnet test_urllib2net
1 test altered the execution environment:
test_io
22 tests skipped:
test_devpoll test_epoll test_gdb test_idle test_kqueue test_msilib
test_ossaudiodev test_pep277 test_smtpnet test_spwd test_ssl
test_startfile test_tcl test_tix test_tk test_ttk_guionly
test_ttk_textonly test_turtle test_unicode_file test_winreg
test_winsound test_zipfile64


# rpm -qa | grep python3
python3-3.5.2-3
# rpm -qa | grep ffi
libffi-devel-20170516-1
libffi-20170516-1


# ldd python
python needs:
 /usr/lib/threads/libc.a(shr.o)
 /usr/lib/libpthreads.a(shr_xpg5.o)
 /opt/freeware/src/packages/BUILD/Python-3.5.2/64bit/libpython3.5m.so
 /opt/freeware/lib/libffi.a(libffi.so.7)
 /unix
 /usr/lib/libcrypt.a(shr.o)
 /usr/lib/libpthreads.a(shr_comm.o)
 /opt/freeware/lib/libgcc_s.a(shr.o)
 /usr/lib/threads/libc.a(shr_64.o)
 /usr/lib/libpthreads.a(shr_xpg5_64.o)
 /opt/freeware/lib/libintl.a(libintl.so.9)
 /usr/lib/libcrypt.a(shr_64.o)
 /opt/freeware/lib/libiconv.a(libiconv.so.2)



Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : David Edelsohn [dje@gmail.com]
Envoyé : mardi 16 mai 2017 17:11
À : REIX, Tony
Cc : GCC Patches; SARTER, MATTHIEU (ext)
Objet : Re: [PATCH,AIX] Enable FFI Go Closure on AIX

On Tue, May 16, 2017 at 10:44 AM, REIX, Tony <tony.r...@atos.net> wrote:
> Hi David,
>
> We'll submit the patch to the libffi project asap.
>
> We have tested this patch on AIX 6.1 with libffi (master from github) in 
> 32bit and 64bit with same results (same exact failures) when testing with and 
> without our patch, using libffi testsuite.
>
> Without patch:
> === libffi Summary === 64bit & 32bit
> # of expected passes1870
> # of unexpected failures38
> # of unresolved testcases  2
> # of unsupported tests 30
>
> With patch:
> === libffi Summary === 64bit & 32bit
> # of expected passes1890
> # of unexpected failures   38
> # of unresolved testcases 2
> # of unsupported tests28
>
> We'll test with Python asap, probably this week.

Libffi project now is on Github

https://github.com/libffi/libffi

I think that Anthony now uses pull requests.

Once the patches are in the upstream project, we can backport them to GCC.

Thanks, David


RE:[PATCH,AIX] Enable FFI Go Closure on AIX

2017-05-17 Thread REIX, Tony
Hi,

We have built and installed the libffi master of yesterday on a AIX 6.1 machine 
and we have rebuilt and tested Python3 (3.5.2) with this libffi. And that is 
OK. 32bit and 64bit.

5 more tests were run and succeeded.
And 1 test (test_ssl) which was skipped before is now run but failed due to no 
access to Web (Resource 'sha256.tbs-internet.com' is not available).

So. our patch does not break libffi build and tests, nor Python3 build and 
tests.

That looks OK.

We'll submit the patch to the libffi project now.

Regards,

Tony


With New libffi:

369 tests OK.
12 tests failed:
test_asyncio test_distutils test_eintr test_httpservers
test_locale test_posix test_socket test_ssl test_tools
test_urllib2 test_urllib2_localnet test_urllib2net
1 test altered the execution environment:
test_io
16 tests skipped:
test_devpoll test_epoll test_gdb test_kqueue test_msilib
test_ossaudiodev test_pep277 test_spwd test_startfile test_tix
test_tk test_ttk_guionly test_unicode_file test_winreg
test_winsound test_zipfile64


With previous libffi:

364 tests OK.
11 tests failed:
test_asyncio test_distutils test_eintr test_httpservers
test_locale test_posix test_socket test_tools test_urllib2
test_urllib2_localnet test_urllib2net
1 test altered the execution environment:
test_io
22 tests skipped:
test_devpoll test_epoll test_gdb test_idle test_kqueue test_msilib
test_ossaudiodev test_pep277 test_smtpnet test_spwd test_ssl
test_startfile test_tcl test_tix test_tk test_ttk_guionly
test_ttk_textonly test_turtle test_unicode_file test_winreg
test_winsound test_zipfile64


# rpm -qa | grep python3
python3-3.5.2-3
# rpm -qa | grep ffi
libffi-devel-20170516-1
libffi-20170516-1


# ldd python
python needs:
 /usr/lib/threads/libc.a(shr.o)
 /usr/lib/libpthreads.a(shr_xpg5.o)
 /opt/freeware/src/packages/BUILD/Python-3.5.2/64bit/libpython3.5m.so
 /opt/freeware/lib/libffi.a(libffi.so.7)
 /unix
 /usr/lib/libcrypt.a(shr.o)
 /usr/lib/libpthreads.a(shr_comm.o)
 /opt/freeware/lib/libgcc_s.a(shr.o)
 /usr/lib/threads/libc.a(shr_64.o)
 /usr/lib/libpthreads.a(shr_xpg5_64.o)
 /opt/freeware/lib/libintl.a(libintl.so.9)
 /usr/lib/libcrypt.a(shr_64.o)
 /opt/freeware/lib/libiconv.a(libiconv.so.2)



Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : David Edelsohn [dje@gmail.com]
Envoyé : mardi 16 mai 2017 17:11
À : REIX, Tony
Cc : GCC Patches; SARTER, MATTHIEU (ext)
Objet : Re: [PATCH,AIX] Enable FFI Go Closure on AIX

On Tue, May 16, 2017 at 10:44 AM, REIX, Tony <tony.r...@atos.net> wrote:
> Hi David,
>
> We'll submit the patch to the libffi project asap.
>
> We have tested this patch on AIX 6.1 with libffi (master from github) in 
> 32bit and 64bit with same results (same exact failures) when testing with and 
> without our patch, using libffi testsuite.
>
> Without patch:
> === libffi Summary === 64bit & 32bit
> # of expected passes1870
> # of unexpected failures38
> # of unresolved testcases  2
> # of unsupported tests 30
>
> With patch:
> === libffi Summary === 64bit & 32bit
> # of expected passes1890
> # of unexpected failures   38
> # of unresolved testcases 2
> # of unsupported tests28
>
> We'll test with Python asap, probably this week.

Libffi project now is on Github

https://github.com/libffi/libffi

I think that Anthony now uses pull requests.

Once the patches are in the upstream project, we can backport them to GCC.

Thanks, David


RE:[PATCH,AIX] Enable FFI Go Closure on AIX

2017-05-16 Thread REIX, Tony
Hi David,

We'll submit the patch to the libffi project asap.

We have tested this patch on AIX 6.1 with libffi (master from github) in 32bit 
and 64bit with same results (same exact failures) when testing with and without 
our patch, using libffi testsuite.

Without patch:
=== libffi Summary === 64bit & 32bit
# of expected passes1870
# of unexpected failures38
# of unresolved testcases  2
# of unsupported tests 30

With patch:
=== libffi Summary === 64bit & 32bit
# of expected passes1890
# of unexpected failures   38
# of unresolved testcases 2
# of unsupported tests28

We'll test with Python asap, probably this week.

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : David Edelsohn [dje@gmail.com]
Envoyé : lundi 15 mai 2017 22:36
À : REIX, Tony
Cc : GCC Patches; SARTER, MATTHIEU (ext)
Objet : Re: [PATCH,AIX] Enable FFI Go Closure on AIX

This patch needs to be submitted to the libffi project.

Also, the ChangeLog needs to specify exactly what is being changed not
"Implement Go Closures".  The patch clearly touches existing parts of
the files that affect more than simply Go closures.

How was this tested?  libffi is used in many more places than Go, so
any changes need to be tested very carefully and thoroughly.  What are
the results for the libffi testsuite?  Have you tried building Python
with a version of libffi built with this patch?

Thanks, David


RE:[PATCH,AIX] Enable Stack Unwinding on AIX

2017-05-16 Thread REIX, Tony
Tests:

The change has been tested in 32bit and 64bit on AIX 6.1, 7.1 & 7.2 by using 
the libbacktrace (with XCOFF support) within a signal handler context (we used 
a specific back.c program).
And it has been tested with Go tests on AIX for sure (recover tests on SIGSEGV 
do not work without this change).

ChangeLog:

* config/rs6000/aix-unwind.h (ppc_aix_fallback_frame_state): Add 64 bit support 
for AIX 6.1 and 7.X and 32 bit support for AIX 7.2.


Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net


De : David Edelsohn [dje@gmail.com]
Envoyé : lundi 15 mai 2017 22:31
À : REIX, Tony
Cc : GCC Patches; SARTER, MATTHIEU (ext)
Objet : Re: [PATCH,AIX] Enable Stack Unwinding on AIX

Please do not email my IBM Notes address with patches.  Please copy
this Gmail address for patch submissions.

>   * libgcc/config/rs6000/aix-unwind.h : Implements stack unwinding on AIX.

This ChangeLog entry clearly is wrong because aix-unwind.h already
implements ppc_aix_fallback_frame_state.  The ChangeLog entry should
reference the exact function being modified and a useful comment about
how it is modified, e.g.,

* config/rs6000/aix-unwind.h (ppc_aix_fallback_frame_state): Add 64
bit support Add 32 bit support for AIX 6.1 and 7.2.

The ChangeLog file is in libgcc, so the file reference is wrong
because it should not use libgcc in the path.

How was this tested?

Thanks, David


[PATCH,AIX] Enable Stack Unwinding on AIX

2017-05-15 Thread REIX, Tony
Description:
 * This patch enables the stack unwinding on AIX.

Tests:
 * Fedora25/x86_64 + GCC v7.1.0 : Configure/Build: SUCCESS
   - build made by means of a .spec file based on Fedora gcc-7.0.1-0.12 .spec 
file
 ../configure --enable-bootstrap 
--enable-languages=c,c++,objc,obj-c++,fortran,go,lto --prefix=/usr 
--mandir=/usr/share/man --infodir=/usr/share/info 
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared 
--enable-threads=posix --enable-checking=release --enable-multilib 
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions 
--enable-gnu-unique-object --enable-linker-build-id 
--with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin 
--enable-initfini-array --with-isl --enable-libmpx 
--enable-offload-targets=nvptx-none --without-cuda-driver 
--enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 
--build=x86_64-redhat-linux

ChangeLog:
  * libgcc/config/rs6000/aix-unwind.h : Implements stack unwinding on AIX.

Regards,

Tony Reix
Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net--- ./libgcc/config/rs6000/aix-unwind.h 2017-01-02 01:20:05 -0600
+++ ./libgcc/config/rs6000/aix-unwind.h 2017-04-28 10:03:16 -0500
@@ -64,7 +64,8 @@
 #endif
 
 /* Now on to MD_FALLBACK_FRAME_STATE_FOR.
-   32bit AIX 5.2, 5.3 and 7.1 only at this stage.  */
+   32bit AIX 5.2, 5.3, 6.1, 7.X and
+   64bit AIX 6.1, 7.X only at this stage.  */
 
 #include 
 #include 
@@ -73,10 +74,10 @@
 
 #ifdef __64BIT__
 
-/* 64bit fallback not implemented yet, so MD_FALLBACK_FRAME_STATE_FOR not
-   defined.  Arrange just for the code below to compile.  */
 typedef struct __context64 mstate_t;
 
+#define MD_FALLBACK_FRAME_STATE_FOR ppc_aix_fallback_frame_state
+
 #else
 
 typedef struct mstsave mstate_t;
@@ -128,10 +129,26 @@ ucontext_for (struct _Unwind_Context *co
 {
   const unsigned int * ra = context->ra;
 
-  /* AIX 5.2, 5.3 and 7.1, threaded or not, share common patterns
+  /* AIX 5.2, 5.3, 6.1 and 7.X, threaded or not, share common patterns
  and feature variants depending on the configured kernel (unix_mp
  or unix_64).  */
 
+#ifdef __64BIT__
+  if (*(ra - 5) == 0x4c00012c /* isync */
+  && *(ra - 4) == 0xe8ec  /* ld  r7,0(r12) */
+  && *(ra - 3) == 0xe84c0008  /* ld  r2,8(r12) */
+  && *(ra - 2) == 0x7ce903a6  /* mtctr   r7*/
+  && *(ra - 1) == 0x4e800421  /* bctrl */
+  && *(ra - 0) == 0x7de27b78) /* mr  r2,r15   <-- context->ra */
+{
+  /* unix_64 */
+  if (*(ra - 6) == 0x7d000164)  /* mtmsrd  r8 */
+{
+  /* AIX 6.1, 7.1 and 7.2 */
+  return (ucontext_t *)(context->cfa + 0x70);
+}
+}
+#else
   if (*(ra - 5) == 0x4c00012c /* isync */
   && *(ra - 4) == 0x80ec  /* lwz r7,0(r12) */
   && *(ra - 3) == 0x804c0004  /* lwz r2,4(r12) */
@@ -152,10 +169,14 @@ ucontext_for (struct _Unwind_Context *co
case 0x835a0570:  /* lwz r26,1392(r26) */
  return (ucontext_t *)(context->cfa + 0x40);
 
- /* AIX 7.1 */
+ /* AIX 6.1 and 7.1 */
case 0x2c1a:  /* cmpwi   r26,0 */
  return (ucontext_t *)(context->cfa + 0x40);
-   
+
+ /* AIX 7.2 */
+   case 0x380a:  /* li   r0,A */
+ return (ucontext_t *)(context->cfa + 0x40);
+
default:
  return 0;
}
@@ -174,7 +195,7 @@ ucontext_for (struct _Unwind_Context *co
  return >ucontext;
}
 }
-
+#endif
   return 0;
 }
 


[PATCH,AIX] Enable FFI Go Closure on AIX

2017-05-15 Thread REIX, Tony
Description:
 * This patch enables FFI Go Closure on AIX.

Tests:
 * Fedora25/x86_64 + GCC v7.1.0 : Configure/Build: SUCCESS
   - build made by means of a .spec file based on Fedora gcc-7.0.1-0.12 .spec 
file
  ../configure --enable-bootstrap 
--enable-languages=c,c++,objc,obj-c++,fortran,go,lto --prefix=/usr 
--mandir=/usr/share/man --infodir=/usr/share/info 
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared 
--enable-threads=posix --enable-checking=release --enable-multilib 
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions 
--enable-gnu-unique-object --enable-linker-build-id 
--with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin 
--enable-initfini-array --with-isl --enable-libmpx 
--enable-offload-targets=nvptx-none --without-cuda-driver 
--enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 
--build=x86_64-redhat-linux

ChangeLog:
  * libffi/src/powerpc/aix.S : Implements Go Closure on AIX.
  * libffi/src/powerpc/aix_closure.S : Idem.
  * libffi/src/powerpc/ffi_darwin.c : Idem.
  * libffi/src/powerpc/ffitarget.h : Enables Go Closure on AIX.

Regards

Tony Reix
Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net






--- ./libffi/src/powerpc/aix.S  2016-11-16 22:25:34 -0600
+++ ./libffi/src/powerpc/aix.S  2017-04-24 13:58:19 -0500
@@ -106,6 +106,10 @@
.llong .ffi_call_AIX, TOC[tc0], 0
.csect .text[PR]
 .ffi_call_AIX:
+   .function .ffi_call_AIX,.ffi_call_AIX,16,044,LFE..0-LFB..0
+   .bf __LINE__
+   .line 1
+LFB..0:
/* Save registers we use.  */
mflrr0
 
@@ -115,8 +119,10 @@
std r31, -8(r1)
 
std r0, 16(r1)
+LCFI..0:
mr  r28, r1 /* our AP.  */
stdux   r1, r1, r4
+LCFI..1:
 
/* Save arguments over call...  */
mr  r31, r5 /* flags, */
@@ -202,12 +208,16 @@
 L(float_return_value):
stfsf1, 0(r30)
b   L(done_return_value)
-
+LFE..0:
 #else /* ! __64BIT__ */

.long .ffi_call_AIX, TOC[tc0], 0
.csect .text[PR]
 .ffi_call_AIX:
+   .function .ffi_call_AIX,.ffi_call_AIX,16,044,LFE..0-LFB..0
+   .bf __LINE__
+   .line 1
+LFB..0:
/* Save registers we use.  */
mflrr0
 
@@ -217,8 +227,10 @@
stw r31, -4(r1)
 
stw r0, 8(r1)
+LCFI..0:
mr  r28, r1 /* out AP.  */
stwux   r1, r1, r4
+LCFI..1:
 
/* Save arguments over call...  */
mr  r31, r5 /* flags, */
@@ -304,11 +316,144 @@
 L(float_return_value):
stfsf1, 0(r30)
b   L(done_return_value)
+LFE..0:
 #endif
+   .ef __LINE__
.long 0
.byte 0,0,0,1,128,4,0,0
 /* END(ffi_call_AIX) */
 
+   /* void ffi_call_go_AIX(extended_cif *ecif, unsigned long bytes,
+*  unsigned int flags, unsigned int *rvalue,
+*  void (*fn)(),
+*  void (*prep_args)(extended_cif*, unsigned 
*const),
+*  void *closure);
+* r3=ecif, r4=bytes, r5=flags, r6=rvalue, r7=fn, r8=prep_args, 
r9=closure
+*/
+
+.csect .text[PR]
+   .align 2
+   .globl ffi_call_go_AIX
+   .globl .ffi_call_go_AIX
+.csect ffi_call_go_AIX[DS]
+ffi_call_go_AIX:
+#ifdef __64BIT__
+   .llong .ffi_call_go_AIX, TOC[tc0], 0
+   .csect .text[PR]
+.ffi_call_go_AIX:
+   .function .ffi_call_go_AIX,.ffi_call_go_AIX,16,044,LFE..1-LFB..1
+   .bf __LINE__
+   .line 1
+LFB..1:
+   /* Save registers we use.  */
+   mflrr0
+
+   std r28,-32(r1)
+   std r29,-24(r1)
+   std r30,-16(r1)
+   std r31, -8(r1)
+
+   std r9, 8(r1)   /* closure, saved in cr field. */
+   std r0, 16(r1)
+LCFI..2:
+   mr  r28, r1 /* our AP.  */
+   stdux   r1, r1, r4
+LCFI..3:
+
+   /* Save arguments over call...  */
+   mr  r31, r5 /* flags, */
+   mr  r30, r6 /* rvalue, */
+   mr  r29, r7 /* function address,  */
+   std r2, 40(r1)
+
+   /* Call ffi_prep_args.  */
+   mr  r4, r1
+   bl  .ffi_prep_args
+   nop
+
+   /* Now do the call.  */
+   ld  r0, 0(r29)
+   ld  r2, 8(r29)
+   ld  r11, 8(r28) /* closure */
+   /* Set up cr1 with bits 4-7 of the flags.  */
+   mtcrf   0x40, r31
+   mtctr   r0
+   /* Load all those argument registers.  */
+   /* We have set up a nice stack frame, just load it into registers. */
+   ld  r3, 40+(1*8)(r1)
+   ld  r4, 40+(2*8)(r1)
+   ld  r5, 40+(3*8)(r1)
+   ld  r6, 40+(4*8)(r1)
+   nop
+   ld  r7, 40+(5*8)(r1)
+   ld  r8, 40+(6*8)(r1)
+   ld  r9, 40+(7*8)(r1)
+   ld  r10,40+(8*8)(r1)
+
+   b   L1
+LFE..1:
+#else /* ! __64BIT__ */
+   
+   

[PATCH,AIX] Enable XCOFF in libbacktrace on AIX

2017-05-15 Thread REIX, Tony
Description:
 * This patch enables libbacktrace to handle XCOFF on AIX.

Tests:
 * Fedora25/x86_64 + GCC v7.1.0 : Configure/Build: SUCCESS
   - build made by means of a .spec file based on Fedora gcc-7.0.1-0.12 .spec 
file
 ../configure --enable-bootstrap 
--enable-languages=c,c++,objc,obj-c++,fortran,go,lto --prefix=/usr 
--mandir=/usr/share/man --infodir=/usr/share/info 
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared 
--enable-threads=posix --enable-checking=release --enable-multilib 
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions 
--enable-gnu-unique-object --enable-linker-build-id 
--with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin 
--enable-initfini-array --with-isl --enable-libmpx 
--enable-offload-targets=nvptx-none --without-cuda-driver 
--enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 
--build=x86_64-redhat-linux

ChangeLog:
  * libbacktrace/Makefile.am : Add xcoff.c
  * libbacktrace/Makefile.in : Regenerated
  * libbacktrace/configure.ac : Add XCOFF output file type
  * libbacktrace/configure : Regenerated
  * libbacktrace/fileline.c : Handle AIX procfs tree
  * libbacktrace/filetype.awk : Add AIX XCOFF type detection
  * libbacktrace/xcoff.c : New file for handling XCOFF format

Regards,

Tony Reix
Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.netdiff -Nur gcc-7-20170203.orig/libbacktrace/Makefile.am 
gcc-7-20170203/libbacktrace/Makefile.am
--- gcc-7-20170203.orig/libbacktrace/Makefile.am2017-01-02 01:19:31 
-0600
+++ gcc-7-20170203/libbacktrace/Makefile.am 2017-03-22 14:09:40 -0500
@@ -57,7 +57,8 @@
 FORMAT_FILES = \
elf.c \
pecoff.c \
-   unknown.c
+   unknown.c \
+   xcoff.c
 
 VIEW_FILES = \
read.c \
@@ -134,3 +135,5 @@
 stest.lo: config.h backtrace.h internal.h
 state.lo: config.h backtrace.h backtrace-supported.h internal.h
 unknown.lo: config.h backtrace.h internal.h
+xcoff.lo: config.h backtrace.h internal.h
+
diff -Nur gcc-7-20170203.orig/libbacktrace/Makefile.in 
gcc-7-20170203/libbacktrace/Makefile.in
--- gcc-7-20170203.orig/libbacktrace/Makefile.in2016-11-16 16:36:10 
-0600
+++ gcc-7-20170203/libbacktrace/Makefile.in 2017-03-22 14:06:51 -0500
@@ -301,7 +301,8 @@
 FORMAT_FILES = \
elf.c \
pecoff.c \
-   unknown.c
+   unknown.c \
+   xcoff.c
 
 VIEW_FILES = \
read.c \
@@ -764,6 +765,7 @@
 stest.lo: config.h backtrace.h internal.h
 state.lo: config.h backtrace.h backtrace-supported.h internal.h
 unknown.lo: config.h backtrace.h internal.h
+xcoff.lo: config.h backtrace.h internal.h
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
diff -Nur gcc-7-20170203.orig/libbacktrace/configure 
gcc-7-20170203/libbacktrace/configure
--- gcc-7-20170203.orig/libbacktrace/configure  2016-11-16 16:36:13 -0600
+++ gcc-7-20170203/libbacktrace/configure   2017-03-22 14:13:40 -0500
@@ -11844,6 +11844,9 @@
 pecoff) FORMAT_FILE="pecoff.lo"
 backtrace_supports_data=no
;;
+xcoff) FORMAT_FILE="xcoff.lo"
+   backtrace_supports_data=no
+   ;;
 *) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: could not determine 
output file type" >&5
 $as_echo "$as_me: WARNING: could not determine output file type" >&2;}
FORMAT_FILE="unknown.lo"
diff -Nur gcc-7-20170203.orig/libbacktrace/configure.ac 
gcc-7-20170203/libbacktrace/configure.ac
--- gcc-7-20170203.orig/libbacktrace/configure.ac   2017-01-02 01:19:31 
-0600
+++ gcc-7-20170203/libbacktrace/configure.ac2017-03-22 13:59:23 -0500
@@ -231,6 +231,9 @@
 pecoff) FORMAT_FILE="pecoff.lo"
 backtrace_supports_data=no
;;
+xcoff) FORMAT_FILE="xcoff.lo"
+   backtrace_supports_data=no
+   ;;
 *) AC_MSG_WARN([could not determine output file type])
FORMAT_FILE="unknown.lo"
backtrace_supported=no
diff -Nur gcc-7-20170203.orig/libbacktrace/fileline.c 
gcc-7-20170203/libbacktrace/fileline.c
--- gcc-7-20170203.orig/libbacktrace/fileline.c 2017-01-02 01:19:54 -0600
+++ gcc-7-20170203/libbacktrace/fileline.c  2017-02-27 13:46:50 -0600
@@ -37,6 +37,9 @@
 #include 
 #include 
 #include 
+#ifdef _AIX
+#include  /* getpid */
+#endif
 
 #include "backtrace.h"
 #include "internal.h"
@@ -83,6 +86,9 @@
   for (pass = 0; pass < 4; ++pass)
 {
   const char *filename;
+#ifdef _AIX
+  char buf[64];
+#endif
   int does_not_exist;
 
   switch (pass)
@@ -94,7 +100,12 @@
  filename = getexecname ();
  break;
case 2:
+#ifdef _AIX
+ snprintf(buf, sizeof(buf), "/proc/%d/object/a.out", getpid());
+ filename = buf;
+#else
  filename = "/proc/self/exe";
+#endif
  break;
case 3:
  filename = "/proc/curproc/file";
diff -Nur gcc-7-20170203.orig/libbacktrace/filetype.awk 

[PATCH,AIX] Enable libiberty to read AIX XCOFF

2017-05-15 Thread REIX, Tony
Description:
 * This patch enables libiberty to read AIX XCOFF.

Tests:
 * Fedora25/x86_64 + GCC v7.1.0 : Configure/Build: SUCCESS
   - build made by means of a .spec file based on Fedora gcc-7.0.1-0.12 .spec 
file
 ../configure --enable-bootstrap 
--enable-languages=c,c++,objc,obj-c++,fortran,go,lto --prefix=/usr 
--mandir=/usr/share/man --infodir=/usr/share/info 
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared 
--enable-threads=posix --enable-checking=release
 --enable-multilib --with-system-zlib --enable-__cxa_atexit 
--disable-libunwind-exceptions --enable-gnu-unique-object 
--enable-linker-build-id --with-gcc-major-version-only 
--with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl 
--enable-libmpx
 --enable-offload-targets=nvptx-none --without-cuda-driver 
--enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 
--build=x86_64-redhat-linux

ChangeLog:
  * libiberty/simple-object-xcoff.c: Enable libiberty to read AIX XCOFF


Regards,

Tony Reix
Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net
--- ./libiberty/simple-object-xcoff.c.ORIGIN2017-03-21 17:08:59 -0500
+++ ./libiberty/simple-object-xcoff.c   2017-03-21 16:45:43 -0500
@@ -258,6 +258,8 @@
 #define C_STAT (3)
 #define C_FILE (103)
 
+#define DBXMASK0x80
+
 /* Private data for an simple_object_read.  */
 
 struct simple_object_xcoff_read
@@ -403,7 +405,9 @@
   unsigned int nscns;
   char *strtab;
   size_t strtab_size;
+  struct external_syment *symtab = NULL;
   unsigned int i;
+  off_t textptr = 0;
 
   scnhdr_size = u64 ? SCNHSZ64 : SCNHSZ32;
   scnbuf = XNEWVEC (unsigned char, scnhdr_size * ocr->nscns);
@@ -485,10 +489,116 @@
  u.xcoff32.s_size));
}
 
+  if (strcmp (name, ".text") == 0)
+textptr = scnptr;
   if (!(*pfn) (data, name, scnptr, size))
break;
 }
 
+  /* Special handling for .go_export CSECT. */
+  if (textptr != 0 && ocr->nsyms > 0)
+{
+  unsigned char *sym, *aux;
+  const char *n_name;
+  unsigned long n_value, n_offset, n_zeroes, x_scnlen;
+
+  /* Read symbol table. */
+  symtab = XNEWVEC (struct external_syment, ocr->nsyms * SYMESZ);
+  if (!simple_object_internal_read (sobj->descriptor,
+sobj->offset + ocr->symptr,
+(unsigned char *)symtab,
+ocr->nsyms * SYMESZ,
+, err))
+{
+  XDELETEVEC (symtab);
+ XDELETEVEC (scnbuf);
+  return NULL;
+}
+  /* Search in symbol table if we have a ".go_export" symbol. */
+  for (i = 0; i < ocr->nsyms; ++i)
+{
+  sym = (unsigned char *)[i];
+
+  if (symtab[i].n_sclass[0] & DBXMASK)
+{
+  /* Skip debug symbols whose names are in stabs. */
+  i += symtab[i].n_numaux[0];
+  continue;
+}
+  if (u64)
+{
+  n_value = fetch_64 (sym + offsetof (struct external_syment,
+  u.xcoff64.n_value));
+  n_offset = fetch_32 (sym + offsetof (struct external_syment,
+   u.xcoff64.n_offset));
+}
+  else
+{
+  /* ".go_export" is longer than N_SYMNMLEN */
+  n_zeroes = fetch_32 (sym + offsetof (struct external_syment,
+   u.xcoff32.n.n.n_zeroes));
+  if (n_zeroes != 0)
+{
+  /* Skip auxiliary entries. */
+  i += symtab[i].n_numaux[0];
+  continue;
+}
+  n_value = fetch_32 (sym + offsetof (struct external_syment,
+  u.xcoff32.n_value));
+  n_offset = fetch_32 (sym + offsetof (struct external_syment,
+   u.xcoff32.n.n.n_offset));
+}
+ /* The real section name is found in the string
+table.  */
+ if (strtab == NULL)
+   {
+ strtab = simple_object_xcoff_read_strtab (sobj,
+   _size,
+   , err);
+ if (strtab == NULL)
+   {
+  XDELETEVEC (symtab);
+ XDELETEVEC (scnbuf);
+ return errmsg;
+   }
+   }
+
+ if (n_offset >= strtab_size)
+{
+ XDELETEVEC (strtab);
+ XDELETEVEC (symtab);
+ XDELETEVEC (scnbuf);
+ *err = 0;
+ return "section string index out of range";
+ 

Enable Go for AIX

2017-04-25 Thread REIX, Tony
Description:
This patch enables libffi, libgo, and Go to be built on AIX.
It is the first patch of a series of patches for Go on AIX.
Do not use --enable-languages=go on AIX till all patches (FSF and Google) are 
available.

Tests (done with a .spec file):
 * AIX 7.2/PowerPC:
   - ./configure --enable-languages=go ... ; gmake : failed while building Go, 
as expected.
   - ./configure (without go language) ; gmake : SUCCESS.
 * Ubuntu/x86_64 :
   - ./configure --disable-multilib --enable-languages=go ... ; make :
   Build broke at 74%, after libgo has been successfully built, due to a lack 
of disk space.

ChangeLog:
* configure.ac: Enable Go for AIX.
* contrib/config-list.mk: Enable Go for AIX.

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net
--- ./configure.ac.ORIGIN   2017-04-19 15:31:23 -0500
+++ ./configure.ac  2017-04-19 15:38:59 -0500
@@ -790,10 +790,6 @@ case "${target}" in
   mmix-*-*)
 noconfigdirs="$noconfigdirs target-libffi"
 ;;
-  powerpc-*-aix*)
-# copied from rs6000-*-* entry
-noconfigdirs="$noconfigdirs target-libffi"
-;;
   rs6000-*-aix*)
 noconfigdirs="$noconfigdirs target-libffi"
 ;;
@@ -808,7 +804,7 @@ esac
 # Disable the go frontend on systems where it is known to not work. Please keep
 # this in sync with contrib/config-list.mk.
 case "${target}" in
-*-*-darwin* | *-*-cygwin* | *-*-mingw* | *-*-aix*)
+*-*-darwin* | *-*-cygwin* | *-*-mingw* | rs6000-*-aix*)
 unsupported_languages="$unsupported_languages go"
 ;;
 esac
@@ -824,7 +820,7 @@ if test x$enable_libgo = x; then
 *-*-cygwin* | *-*-mingw*)
noconfigdirs="$noconfigdirs target-libgo"
;;
-*-*-aix*)
+rs6000-*-aix*)
noconfigdirs="$noconfigdirs target-libgo"
;;
 esac
--- ./contrib/config-list.mk.ORIGIN 2017-04-19 15:39:40 -0500
+++ ./contrib/config-list.mk2017-04-19 15:42:10 -0500
@@ -121,7 +121,7 @@ $(LIST): make-log-dir
TGT=`echo $@ | awk 'BEGIN { FS = "OPT" }; { print $$1 }'` &&
\
TGT=`$(GCC_SRC_DIR)/config.sub $$TGT` &&
\
case $$TGT in   
\
-   *-*-darwin* | *-*-cygwin* | *-*-mingw* | *-*-aix*)  
\
+   *-*-darwin* | *-*-cygwin* | *-*-mingw* | rs6000-*-aix*) 
\
ADDITIONAL_LANGUAGES="";
\
;;  
\
*)  
\