--- ./Lib/distutils/tests/test_config_cmd.py.save	Fri Jan  3 17:11:02 2020
+++ ./Lib/distutils/tests/test_config_cmd.py	Sun Jan  5 16:49:35 2020
@@ -38,6 +38,7 @@
         self.assertEqual(len(self._logs), numlines+1)
 
     @unittest.skipIf(sys.platform == 'win32', "can't test on Windows")
+    @unittest.skipIf(sys.platform.startswith('irix6'), 'issue #11191: IRIX also affected')
     def test_search_cpp(self):
         pkg_dir, dist = self.create_dist()
         cmd = config(dist)
--- ./Lib/distutils/sysconfig.py.save	Tue Sep  3 15:44:04 2019
+++ ./Lib/distutils/sysconfig.py	Fri Sep 13 01:13:00 2019
@@ -192,16 +192,14 @@
         if 'CPP' in os.environ:
             cpp = os.environ['CPP']
         else:
-            cpp = cc + " -E"           # not always
+            cpp = cc + " -P"           # not always
         if 'LDFLAGS' in os.environ:
             ldshared = ldshared + ' ' + os.environ['LDFLAGS']
         if 'CFLAGS' in os.environ:
             cflags = opt + ' ' + os.environ['CFLAGS']
-            ldshared = ldshared + ' ' + os.environ['CFLAGS']
         if 'CPPFLAGS' in os.environ:
             cpp = cpp + ' ' + os.environ['CPPFLAGS']
             cflags = cflags + ' ' + os.environ['CPPFLAGS']
-            ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
         if 'AR' in os.environ:
             ar = os.environ['AR']
         if 'ARFLAGS' in os.environ:
--- ./Lib/distutils/unixccompiler.py.save	Tue Sep  3 15:53:47 2019
+++ ./Lib/distutils/unixccompiler.py	Sun Jan  5 16:56:44 2020
@@ -57,10 +57,10 @@
     # Python extensions).
     executables = {'preprocessor' : None,
                    'compiler'     : ["cc"],
-                   'compiler_so'  : ["cc"],
-                   'compiler_cxx' : ["cc"],
-                   'linker_so'    : ["cc", "-shared"],
-                   'linker_exe'   : ["cc"],
+                   'compiler_so'  : ["cc -KPIC"],
+                   'compiler_cxx' : ["CC"],
+                   'linker_so'    : ["ld", "-shared"],
+                   'linker_exe'   : ["ld"],
                    'archiver'     : ["ar", "-cr"],
                    'ranlib'       : None,
                   }
@@ -236,7 +236,7 @@
             if self._is_gcc(compiler):
                 return ["-Wl,+s", "-L" + dir]
             return ["+s", "-L" + dir]
-        elif sys.platform[:7] == "irix646" or sys.platform[:6] == "osf1V5":
+        elif sys.platform[:5] == "irix6" or sys.platform[:6] == "osf1V5":
             return ["-rpath", dir]
         elif self._is_gcc(compiler):
             return "-Wl,-R" + dir
--- ./Lib/test/test_posix.py.save	Sun Sep  8 19:23:00 2019
+++ ./Lib/test/test_posix.py	Sun Sep  8 19:26:07 2019
@@ -208,7 +208,8 @@
         self.assertEqual(cm.exception.errno, errno.EISDIR)
 
     @unittest.skipUnless(hasattr(posix, 'fdopen') and
-                         not sys.platform.startswith("sunos"),
+                         not (sys.platform.startswith('sunos')
+                         or sys.platform.startswith('irix6')),
                          'test needs posix.fdopen()')
     def test_fdopen_keeps_fd_open_on_errors(self):
         fd = os.open(test_support.TESTFN, os.O_RDONLY)
--- ./Lib/test/test_fileio.py.save	Sun Sep  8 15:34:30 2019
+++ ./Lib/test/test_fileio.py	Sun Sep  8 15:34:45 2019
@@ -312,7 +312,7 @@
             self.assertEqual(f.writable(), True)
             if sys.platform != "darwin" and \
                'bsd' not in sys.platform and \
-               not sys.platform.startswith(('sunos', 'aix')):
+               not sys.platform.startswith(('sunos', 'aix', 'irix6')):
                 # Somehow /dev/tty appears seekable on some BSDs
                 self.assertEqual(f.seekable(), False)
             self.assertEqual(f.isatty(), True)
--- ./Lib/test/test_io.py.save	Thu Sep 12 23:49:15 2019
+++ ./Lib/test/test_io.py	Fri Sep 13 00:43:55 2019
@@ -3171,6 +3171,7 @@
     @unittest.skipUnless(threading, 'Threading required for this test.')
     @unittest.skipIf(sys.platform in ('freebsd5', 'freebsd6', 'freebsd7'),
                      'issue #12429: skip test on FreeBSD <= 7')
+    @unittest.skipIf(sys.platform.startswith('irix6'), 'issue #12429: IRIX affected')
     def check_interrupted_write(self, item, bytes, **fdopen_kwargs):
         """Check that a partial write, when it gets interrupted, properly
         invokes the signal handler, and bubbles up the exception raised
--- ./Lib/multiprocessing/__init__.py.save	Tue Sep  3 08:56:01 2019
+++ ./Lib/multiprocessing/__init__.py	Tue Sep  3 08:58:16 2019
@@ -124,6 +124,12 @@
                 num = int(p.read())
         except ValueError:
             num = 0
+    elif 'irix' in sys.platform:
+        try:
+            with os.popen('/usr/sbin/sysconf NPROC_ONLN') as p:
+                num = int(p.read())
+        except (ValueError, OSError, AttributeError):
+            num = 0
     else:
         try:
             num = os.sysconf('SC_NPROCESSORS_ONLN')
--- ./Objects/fileobject.c.save	Fri Sep 20 02:09:08 2019
+++ ./Objects/fileobject.c	Fri Sep 20 02:18:59 2019
@@ -702,6 +702,18 @@
 static int
 _portable_fseek(FILE *fp, Py_off_t offset, int whence)
 {
+/* Turns out that IRIX' fseeko() and fseek64() functions are both broken.
+ * The test_gzip.py check sometimes fail if the gzip filename was 13
+ * characters long, resulting in seeks with an additional -8 offset,
+ * causing the crc32 check to fail.
+ * This bug was not immediately noticable because the filename was
+ * randomly generated with a length depending on the uptime of the machine,
+ * and one had to wait about an our or so for the test to fail... */
+#if defined(__sgi)
+#undef HAVE_FSEEKO
+#undef HAVE_FSEEK64
+#endif
+
 #if !defined(HAVE_LARGEFILE_SUPPORT)
     return fseek(fp, offset, whence);
 #elif defined(HAVE_FSEEKO) && SIZEOF_OFF_T >= 8
--- ./Modules/_ctypes/_ctypes.c.save	Thu Aug 29 03:04:27 2019
+++ ./Modules/_ctypes/_ctypes.c	Tue Sep  3 11:04:21 2019
@@ -4092,7 +4092,7 @@
         }
     }
 
-    result = _ctypes_callproc(pProc,
+    result = _ctypes_callproc((PPROC)pProc,
                        callargs,
 #ifdef MS_WIN32
                        piunk,
--- ./Modules/_ctypes/callproc.c.save	Tue Sep  3 10:43:04 2019
+++ ./Modules/_ctypes/callproc.c	Thu Sep 19 16:32:17 2019
@@ -834,7 +834,7 @@
 #endif
         delta =
 #endif
-                ffi_call(&cif, (void *)pProc, resmem, avalues);
+                ffi_call(&cif, FFI_FN(pProc), resmem, avalues);
 #ifdef MS_WIN32
 #ifndef DONT_USE_SEH
     }
@@ -934,7 +934,7 @@
            O_get), we have to call Py_DECREF because O_get has already
            called Py_INCREF.
         */
-        if (dict->getfunc == _ctypes_get_fielddesc("O")->getfunc) {
+        if (retval && dict->getfunc == _ctypes_get_fielddesc("O")->getfunc) {
             Py_DECREF(retval);
         }
     } else
--- ./Modules/_multiprocessing/semaphore.c.save	Sat Sep 14 13:24:47 2019
+++ ./Modules/_multiprocessing/semaphore.c	Sat Sep 14 13:53:04 2019
@@ -446,7 +446,7 @@
     do {
         unsigned long suffix;
         _PyOS_URandom((char *)&suffix, sizeof(suffix));
-        PyOS_snprintf(buffer, sizeof(buffer), "/mp%ld-%lu", (long)getpid(),
+        PyOS_snprintf(buffer, sizeof(buffer), "/tmp/mp%ld-%lu", (long)getpid(),
                       suffix);
         SEM_CLEAR_ERROR();
         handle = SEM_CREATE(buffer, value, maxvalue);
--- Modules/makesetup      Sat Mar  2 19:17:42 2019
+++ Modules/makesetup   Tue Jan  7 00:45:46 2020
@@ -211,7 +211,6 @@
                        obj="$srcdir/$obj"
                        objs="$objs $obj"
                        case $src in
-                       glmodule.c) ;;
                        /*) ;;
                        \$*) ;;
                        *) src='$(srcdir)/'"$srcdir/$src";;
@@ -231,7 +230,7 @@
                do
                        case $objs in
                        *$mod.o*)       base=$mod;;
-                       *)              base=${mod}module;;
+                       *)              base=${mod};;
                        esac
                        file="$srcdir/$base\$(SO)"
                        case $doconfig in
--- ./Modules/timemodule.c.save	Sun Sep  8 00:04:49 2019
+++ ./Modules/timemodule.c	Sun Sep  8 20:45:06 2019
@@ -91,6 +91,10 @@
 extern int riscos_sleep(double);
 #endif
 
+#ifdef __sgi
+#include "my_mktime.c"
+#endif
+
 /* Forward declarations */
 static int floatsleep(double);
 static double floattime(void);
@@ -731,7 +735,7 @@
     if (!gettmarg(tup, &buf))
         return NULL;
     buf.tm_wday = -1;  /* sentinel; original value ignored */
-    tt = mktime(&buf);
+    tt = my_mktime(&buf);
     /* Return value of -1 does not necessarily mean an error, but tm_wday
      * cannot remain set to -1 if mktime succeeded. */
     if (tt == (time_t)(-1) && buf.tm_wday == -1) {
--- ./Modules/posixmodule.c.save	Sat Sep 14 22:28:52 2019
+++ ./Modules/posixmodule.c	Fri Sep 20 13:42:08 2019
@@ -173,6 +173,8 @@
 /* declare ctermid_r if compiling with MIPSPro 7.x in ANSI C mode
    (default) */
 extern char        *ctermid_r(char *);
+#define HAVE_UNSETENV 1
+#include "setenv.c"
 #endif
 
 #ifndef HAVE_UNISTD_H
--- ./Modules/fmmodule.c.save	Sat Sep 21 00:57:47 2019
+++ ./Modules/fmmodule.c	Sat Sep 21 00:59:25 2019
@@ -257,11 +257,12 @@
 void
 initfm(void)
 {
+    PyObject *m;
     if (PyErr_WarnPy3k("the fm module has been removed in "
                        "Python 3.0", 2) < 0)
         return;
 
-    Py_InitModule("fm", fm_methods);
+    m = Py_InitModule("fm", fm_methods);
     if (m == NULL)
         return;
     fminit();
--- ./Modules/flmodule.c.save	Sat Sep 21 01:00:37 2019
+++ ./Modules/flmodule.c	Sat Sep 21 01:02:33 2019
@@ -716,17 +716,17 @@
     {"load_browser",                    (PyCFunction)load_browser,
      METH_OLDARGS},
     {"get_browser_maxline",             (PyCFunction)get_browser_maxline,
-     METH_NOARGS,}
+     METH_NOARGS,},
     {"select_browser_line",             (PyCFunction)select_browser_line,
      METH_OLDARGS},
     {"deselect_browser_line",           (PyCFunction)deselect_browser_line,
      METH_OLDARGS},
     {"deselect_browser",                (PyCFunction)deselect_browser,
-     METH_NOARGS,}
+     METH_NOARGS,},
     {"isselected_browser_line",         (PyCFunction)isselected_browser_line,
      METH_OLDARGS},
     {"get_browser",                     (PyCFunction)get_browser,
-     METH_NOARGS,}
+     METH_NOARGS,},
     {"set_browser_fontsize",            (PyCFunction)set_browser_fontsize,
      METH_OLDARGS},
     {"set_browser_fontstyle",           (PyCFunction)set_browser_fontstyle,
@@ -2124,11 +2124,12 @@
 PyMODINIT_FUNC
 initfl(void)
 {
+    PyObject *m;
     if (PyErr_WarnPy3k("the fl module has been removed in "
                        "Python 3.0", 2) < 0)
         return;
 
-    Py_InitModule("fl", forms_methods);
+    m = Py_InitModule("fl", forms_methods);
     if (m == NULL)
         return;
     foreground();
--- ./configure.save	Thu Sep 12 13:08:47 2019
+++ ./configure	Sat Sep 14 15:30:37 2019
@@ -3313,7 +3313,7 @@
 	cygwin*) MACHDEP="cygwin";;
 	darwin*) MACHDEP="darwin";;
 	atheos*) MACHDEP="atheos";;
-        irix646) MACHDEP="irix6";;
+        irix6*) MACHDEP="irix6";;
 	'')	MACHDEP="unknown";;
     esac
 fi
@@ -3459,7 +3459,7 @@
 
 if test ! -z "$SGI_ABI"
 then
-        CC="cc $SGI_ABI"
+        CC="$CC $SGI_ABI"
         LDFLAGS="$SGI_ABI $LDFLAGS"
         MACHDEP=`echo "${MACHDEP}${SGI_ABI}" | sed 's/ *//g'`
 fi
@@ -5492,6 +5492,12 @@
 	  esac
 	  INSTSONAME="$LDLIBRARY".$SOVERSION
 	  ;;
+    IRIX*)
+	  LDLIBRARY='libpython$(VERSION).so'
+	  BLDLIBRARY='-Wl,-rpath -Wl,$(LIBDIR) -L. -lpython$(VERSION)'
+	  RUNSHARED=LD_LIBRARYN32_PATH=`pwd`${LD_LIBRARYN32_PATH:+:${LD_LIBRARYN32_PATH}}
+	  INSTSONAME="$LDLIBRARY".$SOVERSION
+	  ;;
     hp*|HP*)
 	  case `uname -m` in
 		ia64)
@@ -8747,10 +8753,11 @@
 		then CCSHARED="-fPIC"
 		else CCSHARED="-Kpic -belf"
 		fi;;
-	IRIX*/6*)  case $CC in
-		   *gcc*) CCSHARED="-shared";;
-		   *) CCSHARED="";;
-		   esac;;
+	IRIX*/6*)
+		if test "$GCC" = "yes"
+		then CCSHARED="-fPIC"
+		else CCSHARED="-KPIC"
+		fi;;
 	atheos*) CCSHARED="-fPIC";;
 	esac
 fi
@@ -13302,13 +13309,13 @@
 #include <sys/stat.h>
 
 int main(void) {
-  sem_t *a = sem_open("/autoconf", O_CREAT, S_IRUSR|S_IWUSR, 0);
+  sem_t *a = sem_open("/tmp/autoconf", O_CREAT, S_IRUSR|S_IWUSR, 0);
   if (a == SEM_FAILED) {
     perror("sem_open");
     return 1;
   }
   sem_close(a);
-  sem_unlink("/autoconf");
+  sem_unlink("/tmp/autoconf");
   return 0;
 }
 
@@ -13353,7 +13360,7 @@
 #include <sys/stat.h>
 
 int main(void){
-  sem_t *a = sem_open("/autocftw", O_CREAT, S_IRUSR|S_IWUSR, 0);
+  sem_t *a = sem_open("/tmp/autocftw", O_CREAT, S_IRUSR|S_IWUSR, 0);
   int count;
   int res;
   if(a==SEM_FAILED){
@@ -13363,7 +13370,7 @@
   }
   res = sem_getvalue(a, &count);
   sem_close(a);
-  sem_unlink("/autocftw");
+  sem_unlink("/tmp/autocftw");
   return res==-1 ? 1 : 0;
 }
 
--- ./Makefile.pre.in.save	Thu Sep 12 21:18:17 2019
+++ ./Makefile.pre.in	Fri Sep 13 18:34:55 2019
@@ -541,8 +541,8 @@
 
 libpython$(VERSION).so: $(LIBRARY_OBJS)
 	if test $(INSTSONAME) != $(LDLIBRARY); then \
-		$(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
-		$(LN) -f $(INSTSONAME) $@; \
+		$(BLDSHARED) -soname $(INSTSONAME) -set_version sgi1.0 -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
+		$(LN) -sf $(INSTSONAME) $@; \
 	else \
 		$(BLDSHARED) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
 	fi
