code:
https://sources.debian.org/data/main/b/blender/2.79.b+dfsg0-4/debian/patches/0008-fix_building_with_latest_versions_of_FFmpeg.patch

From: Bastien Montagne <montagne29@wanadoo.fr>
Date: Tue, 8 May 2018 16:00:52 +0200
Subject: fix_building_with_latest_versions_of_FFmpeg

Some years-old deprecated stuff has now been removed.

Correct solution is probably to use valid defines etc. in own code, but
this is more FFMEPG maintainer task (since it also may change how old
FFMPEG we do support...).
---
 intern/ffmpeg/ffmpeg_compat.h                  | 39 ++++++++++++++++++++++++++
 source/blender/blenkernel/intern/writeffmpeg.c |  3 +-
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/intern/ffmpeg/ffmpeg_compat.h b/intern/ffmpeg/ffmpeg_compat.h
index 9c06c8a..f7f437c 100644
--- a/intern/ffmpeg/ffmpeg_compat.h
+++ b/intern/ffmpeg/ffmpeg_compat.h
@@ -109,6 +109,45 @@ int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)

 #endif

+/* XXX TODO Probably fix to correct modern flags in code? Not sure how old FFMPEG we want to support though,
+ * so for now this will do. */
+
+#ifndef FF_MIN_BUFFER_SIZE
+#  ifdef AV_INPUT_BUFFER_MIN_SIZE
+#    define FF_MIN_BUFFER_SIZE AV_INPUT_BUFFER_MIN_SIZE
+#  endif
+#endif
+
+#ifndef FF_INPUT_BUFFER_PADDING_SIZE
+#  ifdef AV_INPUT_BUFFER_PADDING_SIZE
+#    define FF_INPUT_BUFFER_PADDING_SIZE AV_INPUT_BUFFER_PADDING_SIZE
+#  endif
+#endif
+
+#ifndef CODEC_FLAG_GLOBAL_HEADER
+#  ifdef AV_CODEC_FLAG_GLOBAL_HEADER
+#    define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
+#  endif
+#endif
+
+#ifndef CODEC_FLAG_GLOBAL_HEADER
+#  ifdef AV_CODEC_FLAG_GLOBAL_HEADER
+#    define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
+#  endif
+#endif
+
+#ifndef CODEC_FLAG_INTERLACED_DCT
+#  ifdef AV_CODEC_FLAG_INTERLACED_DCT
+#    define CODEC_FLAG_INTERLACED_DCT AV_CODEC_FLAG_INTERLACED_DCT
+#  endif
+#endif
+
+#ifndef CODEC_FLAG_INTERLACED_ME
+#  ifdef AV_CODEC_FLAG_INTERLACED_ME
+#    define CODEC_FLAG_INTERLACED_ME AV_CODEC_FLAG_INTERLACED_ME
+#  endif
+#endif
+
 /* FFmpeg upstream 1.0 is the first who added AV_ prefix. */
 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 59, 100)
 #  define AV_CODEC_ID_NONE CODEC_ID_NONE
diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c
index a19e414..04d508a 100644
--- a/source/blender/blenkernel/intern/writeffmpeg.c
+++ b/source/blender/blenkernel/intern/writeffmpeg.c
@@ -605,7 +605,8 @@ static AVStream *alloc_video_stream(FFMpegContext *context, RenderData *rd, int
 	c->rc_buffer_aggressivity = 1.0;
 #endif

-	c->me_method = ME_EPZS;
+	/* Deprecated and not doing anything since July 2015, deleted in recent ffmpeg */
+	//c->me_method = ME_EPZS;

 	codec = avcodec_find_encoder(c->codec_id);
 	if (!codec)


code:
From: Sergey Sharybin <sergey@blender.org>
Date: Fri, 28 Dec 2018 11:25:35 +0100
Subject: adapt_build_against_OIIO2

---
 intern/cycles/blender/blender_python.cpp           |  2 +-
 intern/cycles/graph/node_xml.cpp                   |  2 +-
 intern/cycles/render/buffers.cpp                   |  4 ++--
 intern/cycles/render/image.cpp                     | 15 ++++--------
 intern/cycles/render/image.h                       |  3 ++-
 intern/cycles/util/util_unique_ptr.h               | 28 ++++++++++++++++++++++
 .../blender/imbuf/intern/oiio/openimageio_api.cpp  | 19 +++++++--------
 7 files changed, 48 insertions(+), 25 deletions(-)
 create mode 100644 intern/cycles/util/util_unique_ptr.h

diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp
index 54973fd..bee6dd1 100644
--- a/intern/cycles/blender/blender_python.cpp
+++ b/intern/cycles/blender/blender_python.cpp
@@ -493,7 +493,7 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args)
 				socket_type = "NodeSocketString";
 				data_type = BL::NodeSocket::type_STRING;
 				if(param->validdefault)
-					default_string = param->sdefault[0];
+					default_string = param->sdefault[0].string();
 			}
 			else
 				continue;
diff --git a/intern/cycles/graph/node_xml.cpp b/intern/cycles/graph/node_xml.cpp
index d26b3b2..2a24104 100644
--- a/intern/cycles/graph/node_xml.cpp
+++ b/intern/cycles/graph/node_xml.cpp
@@ -250,7 +250,7 @@ void xml_read_node(XMLReader& reader, Node *node, xml_node xml_node)
 		}
 	}

-	if(node->name)
+	if(!node->name.empty())
 		reader.node_map[node->name] = node;
 }

diff --git a/intern/cycles/render/buffers.cpp b/intern/cycles/render/buffers.cpp
index cf402c3..f84a37a 100644
--- a/intern/cycles/render/buffers.cpp
+++ b/intern/cycles/render/buffers.cpp
@@ -27,6 +27,7 @@
 #include "util/util_opengl.h"
 #include "util/util_time.h"
 #include "util/util_types.h"
+#include "util/util_unique_ptr.h"

 CCL_NAMESPACE_BEGIN

@@ -453,7 +454,7 @@ void DisplayBuffer::write(Device *device, const string& filename)
 	device->pixels_copy_from(rgba, 0, w, h);

 	/* write image */
-	ImageOutput *out = ImageOutput::create(filename);
+	unique_ptr<ImageOutput> out = unique_ptr<ImageOutput>(ImageOutput::create(filename));
 	ImageSpec spec(w, h, 4, TypeDesc::UINT8);
 	int scanlinesize = w*4*sizeof(uchar);

@@ -468,7 +469,6 @@ void DisplayBuffer::write(Device *device, const string& filename)

 	out->close();

-	delete out;
 }

 device_memory& DisplayBuffer::rgba_data()
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index 595eb46..a143b02 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -23,6 +23,7 @@
 #include "util/util_path.h"
 #include "util/util_progress.h"
 #include "util/util_texture.h"
+#include "util/util_unique_ptr.h"

 #ifdef WITH_OSL
 #include <OSL/oslexec.h>
@@ -148,7 +149,7 @@ ImageDataType ImageManager::get_image_metadata(const string& filename,
 		return IMAGE_DATA_TYPE_BYTE4;
 	}

-	ImageInput *in = ImageInput::create(filename);
+	unique_ptr<ImageInput> in(ImageInput::create(filename));

 	if(in) {
 		ImageSpec spec;
@@ -194,7 +195,6 @@ ImageDataType ImageManager::get_image_metadata(const string& filename,
 			in->close();
 		}

-		delete in;
 	}

 	if(is_half) {
@@ -449,7 +449,7 @@ void ImageManager::tag_reload_image(const string& filename,
 }

 bool ImageManager::file_load_image_generic(Image *img,
-                                           ImageInput **in,
+                                           unique_ptr<ImageInput> *in,
                                            int &width,
                                            int &height,
                                            int &depth,
@@ -465,7 +465,7 @@ bool ImageManager::file_load_image_generic(Image *img,
 		}

 		/* load image from file through OIIO */
-		*in = ImageInput::create(img->filename);
+		*in = unique_ptr<ImageInput>(ImageInput::create(img->filename));

 		if(!*in)
 			return false;
@@ -477,8 +477,6 @@ bool ImageManager::file_load_image_generic(Image *img,
 			config.attribute("oiio:UnassociatedAlpha", 1);

 		if(!(*in)->open(img->filename, spec, config)) {
-			delete *in;
-			*in = NULL;
 			return false;
 		}

@@ -500,8 +498,6 @@ bool ImageManager::file_load_image_generic(Image *img,
 	if(!(components >= 1 && components <= 4)) {
 		if(*in) {
 			(*in)->close();
-			delete *in;
-			*in = NULL;
 		}

 		return false;
@@ -519,7 +515,7 @@ bool ImageManager::file_load_image(Image *img,
                                    device_vector<DeviceType>& tex_img)
 {
 	const StorageType alpha_one = (FileFormat == TypeDesc::UINT8)? 255 : 1;
-	ImageInput *in = NULL;
+	unique_ptr<ImageInput> in = NULL;
 	int width, height, depth, components;
 	if(!file_load_image_generic(img, &in, width, height, depth, components)) {
 		return false;
@@ -575,7 +571,6 @@ bool ImageManager::file_load_image(Image *img,
 		}
 		cmyk = strcmp(in->format_name(), "jpeg") == 0 && components == 4;
 		in->close();
-		delete in;
 	}
 	else {
 		if(FileFormat == TypeDesc::FLOAT) {
diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h
index db7e28a..f4a14f4 100644
--- a/intern/cycles/render/image.h
+++ b/intern/cycles/render/image.h
@@ -23,6 +23,7 @@
 #include "util/util_image.h"
 #include "util/util_string.h"
 #include "util/util_thread.h"
+#include "util/util_unique_ptr.h"
 #include "util/util_vector.h"

 CCL_NAMESPACE_BEGIN
@@ -133,7 +134,7 @@ private:
 	bool pack_images;

 	bool file_load_image_generic(Image *img,
-	                             ImageInput **in,
+	                             unique_ptr<ImageInput> *in,
 	                             int &width,
 	                             int &height,
 	                             int &depth,
diff --git a/intern/cycles/util/util_unique_ptr.h b/intern/cycles/util/util_unique_ptr.h
new file mode 100644
index 0000000..1ceae73
--- /dev/null
+++ b/intern/cycles/util/util_unique_ptr.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2011-2013 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __UTIL_UNIQUE_PTR_H__
+#define __UTIL_UNIQUE_PTR_H__
+
+#include <memory>
+
+CCL_NAMESPACE_BEGIN
+
+using std::unique_ptr;
+
+CCL_NAMESPACE_END
+
+#endif  /* __UTIL_UNIQUE_PTR_H__ */
diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.cpp b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
index b123d50..7f2fac9 100644
--- a/source/blender/imbuf/intern/oiio/openimageio_api.cpp
+++ b/source/blender/imbuf/intern/oiio/openimageio_api.cpp
@@ -35,6 +35,11 @@
 #include "utfconv.h"
 #endif

+// NOTE: Keep first, BLI_path_util conflicts with OIIO's format.
+#include <memory>
+#include <openimageio_api.h>
+#include <OpenImageIO/imageio.h>
+
 extern "C"
 {
 #include "MEM_guardedalloc.h"
@@ -48,12 +53,10 @@ extern "C"
 #include "IMB_colormanagement_intern.h"
 }

-#include <openimageio_api.h>
-#include <OpenImageIO/imageio.h>
-
 OIIO_NAMESPACE_USING

 using std::string;
+using std::unique_ptr;

 typedef unsigned char uchar;

@@ -197,7 +200,6 @@ int imb_save_photoshop(struct ImBuf *ibuf, const char * /*name*/, int flags)

 struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspace[IM_MAX_SPACE])
 {
-	ImageInput *in = NULL;
 	struct ImBuf *ibuf = NULL;
 	int width, height, components;
 	bool is_float, is_alpha;
@@ -210,7 +212,7 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac

 	colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);

-	in = ImageInput::create(filename);
+	unique_ptr<ImageInput> in(ImageInput::create(filename));
 	if (!in) {
 		std::cerr << __func__ << ": ImageInput::create() failed:" << std::endl
 		          << OIIO_NAMESPACE::geterror() << std::endl;
@@ -223,7 +225,6 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
 	if (!in->open(filename, spec, config)) {
 		std::cerr << __func__ << ": ImageInput::open() failed:" << std::endl
 		          << in->geterror() << std::endl;
-		delete in;
 		return NULL;
 	}

@@ -249,19 +250,17 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac
 	if (!(components >= 1 && components <= 4)) {
 		if (in) {
 			in->close();
-			delete in;
 		}
 		return NULL;
 	}

 	if (is_float)
-		ibuf = imb_oiio_load_image_float(in, width, height, components, flags, is_alpha);
+		ibuf = imb_oiio_load_image_float(in.get(), width, height, components, flags, is_alpha);
 	else
-		ibuf = imb_oiio_load_image(in, width, height, components, flags, is_alpha);
+		ibuf = imb_oiio_load_image(in.get(), width, height, components, flags, is_alpha);

 	if (in) {
 		in->close();
-		delete in;
 	}

 	if (!ibuf)

license: mit


code:
Copied from https://git.blender.org/gitweb/gitweb.cgi/blender.git/patch/1db47a2ccd1e68994bf8140eba6cc2a26a2bc91f
Fixes <https://bugs.gnu.org/33608>.

From 1db47a2ccd1e68994bf8140eba6cc2a26a2bc91f Mon Sep 17 00:00:00 2001
From: Campbell Barton <ideasman42@gmail.com>
Date: Thu, 12 Jul 2018 08:28:06 +0200
Subject: [PATCH] Fix PyRNA class registration w/ Python 3.7

In Python3.7 this now raises an error.
---
 source/blender/python/intern/bpy_rna.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 9052b6f580a..80b0aa7a51b 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -7577,10 +7577,12 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v
 		if (!(flag & PROP_REGISTER))
 			continue;

+		/* TODO(campbell): Use Python3.7x _PyObject_LookupAttr(), also in the macro below. */
 		identifier = RNA_property_identifier(prop);
 		item = PyObject_GetAttrString(py_class, identifier);

 		if (item == NULL) {
+			PyErr_Clear();
 			/* Sneaky workaround to use the class name as the bl_idname */

 #define     BPY_REPLACEMENT_STRING(rna_attr, py_attr)                         \
@@ -7596,6 +7598,9 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v
 					}                                                         \
 					Py_DECREF(item);                                          \
 				}                                                             \
+				else {                                                        \
+					PyErr_Clear();                                            \
+				}                                                             \
 			}  /* intentionally allow else here */

 			if (false) {}  /* needed for macro */
--
2.20.1


code:
From 4b663ecf264020b1d7003a137ce84b06d7ec4ce6 Mon Sep 17 00:00:00 2001
From: bartus <szczepaniak.bartek+github@gmail.com>
Date: Sat, 16 Nov 2019 20:29:30 +0100
Subject: [PATCH] Add python 3.8 support.

---
 source/blender/python/generic/py_capi_utils.c | 27 +++++++++++++++----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c
index 545e0506f84..a7eab70600b 100644
--- a/source/blender/python/generic/py_capi_utils.c
+++ b/source/blender/python/generic/py_capi_utils.c
@@ -696,9 +696,16 @@ PyObject *PyC_UnicodeFromByte(const char *str)
  ****************************************************************************/
 PyObject *PyC_DefaultNameSpace(const char *filename)
 {
+	#if PY_VERSION_HEX >= 0x03080000
+	PyObject *modules = PyImport_GetModuleDict();
+	PyObject *builtins = PyEval_GetBuiltins();
+	#else
 	PyInterpreterState *interp = PyThreadState_GET()->interp;
+	PyObject *modules = interp->modules;
+	PyObject *builtins = interp->builtins;
+	#endif
 	PyObject *mod_main = PyModule_New("__main__");
-	PyDict_SetItemString(interp->modules, "__main__", mod_main);
+	PyDict_SetItemString(modules, "__main__", mod_main);
 	Py_DECREF(mod_main); /* sys.modules owns now */
 	PyModule_AddStringConstant(mod_main, "__name__", "__main__");
 	if (filename) {
@@ -706,8 +713,8 @@ PyObject *PyC_DefaultNameSpace(const char *filename)
 		 * note: this wont map to a real file when executing text-blocks and buttons. */
 		PyModule_AddObject(mod_main, "__file__", PyC_UnicodeFromByte(filename));
 	}
-	PyModule_AddObject(mod_main, "__builtins__", interp->builtins);
-	Py_INCREF(interp->builtins); /* AddObject steals a reference */
+	PyModule_AddObject(mod_main, "__builtins__", builtins);
+	Py_INCREF(builtins); /* AddObject steals a reference */
 	return PyModule_GetDict(mod_main);
 }

@@ -734,15 +741,25 @@ bool PyC_NameSpace_ImportArray(PyObject *py_dict, const char *imports[])
 /* restore MUST be called after this */
 void PyC_MainModule_Backup(PyObject **main_mod)
 {
+	#if PY_VERSION_HEX >= 0x03080000
+	PyObject *modules = PyImport_GetModuleDict();
+	#else
 	PyInterpreterState *interp = PyThreadState_GET()->interp;
-	*main_mod = PyDict_GetItemString(interp->modules, "__main__");
+	PyObject *modules = interp->modules;
+	#endif
+	*main_mod = PyDict_GetItemString(modules, "__main__");
 	Py_XINCREF(*main_mod); /* don't free */
 }

 void PyC_MainModule_Restore(PyObject *main_mod)
 {
+	#if PY_VERSION_HEX >= 0x03080000
+	PyObject *modules = PyImport_GetModuleDict();
+	#else
 	PyInterpreterState *interp = PyThreadState_GET()->interp;
-	PyDict_SetItemString(interp->modules, "__main__", main_mod);
+	PyObject *modules = interp->modules;
+	#endif
+	PyDict_SetItemString(modules, "__main__", main_mod);
 	Py_XDECREF(main_mod);
 }

--
2.24.0

From 44f719b63238503ef8f933f55383c6d4798995cc Mon Sep 17 00:00:00 2001
From: Campbell Barton <ideasman42@gmail.com>
Date: Thu, 13 Sep 2018 17:06:07 +1000
Subject: [PATCH] Cleanup: use PyImport_GetModuleDict

Replace direct access using PyThreadState_GET
---
 source/blender/python/bmesh/bmesh_py_api.c        | 2 +-
 source/blender/python/generic/idprop_py_api.c     | 2 +-
 source/blender/python/intern/bpy_interface.c      | 2 +-
 source/blender/python/intern/gpu.c                | 4 ++--
 source/blender/python/mathutils/mathutils.c       | 2 +-
 source/blender/python/mathutils/mathutils_noise.c | 5 +++--
 source/gameengine/Ketsji/KX_PythonInit.cpp        | 2 +-
 7 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c
index d5973baeadb..d7324eabb6c 100644
--- a/source/blender/python/bmesh/bmesh_py_api.c
+++ b/source/blender/python/bmesh/bmesh_py_api.c
@@ -196,7 +196,7 @@ PyObject *BPyInit_bmesh(void)
 {
 	PyObject *mod;
 	PyObject *submodule;
-	PyObject *sys_modules = PyThreadState_GET()->interp->modules;
+	PyObject *sys_modules = PyImport_GetModuleDict();

 	BPy_BM_init_types();
 	BPy_BM_init_types_select();
diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c
index 4d4d5232800..8bed0f28cba 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -1795,7 +1795,7 @@ PyObject *BPyInit_idprop(void)
 {
 	PyObject *mod;
 	PyObject *submodule;
-	PyObject *sys_modules = PyThreadState_GET()->interp->modules;
+	PyObject *sys_modules = PyImport_GetModuleDict();

 	mod = PyModule_Create(&IDProp_module_def);

diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 7ca087e4993..123c938b921 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -537,7 +537,7 @@ static bool python_script_exec(

 	if (py_dict) {
 #ifdef PYMODULE_CLEAR_WORKAROUND
-		PyModuleObject *mmod = (PyModuleObject *)PyDict_GetItemString(PyThreadState_GET()->interp->modules, "__main__");
+		PyModuleObject *mmod = (PyModuleObject *)PyDict_GetItemString(PyImport_GetModuleDict(), "__main__");
 		PyObject *dict_back = mmod->md_dict;
 		/* freeing the module will clear the namespace,
 		 * gives problems running classes defined in this namespace being used later. */
diff --git a/source/blender/python/intern/gpu.c b/source/blender/python/intern/gpu.c
index 43796dc9474..d902b6838f4 100644
--- a/source/blender/python/intern/gpu.c
+++ b/source/blender/python/intern/gpu.c
@@ -326,7 +326,7 @@ PyObject *GPU_initPython(void)
 {
 	PyObject *module;
 	PyObject *submodule;
-	PyObject *sys_modules = PyThreadState_GET()->interp->modules;
+	PyObject *sys_modules = PyImport_GetModuleDict();

 	module = PyInit_gpu();

@@ -337,6 +337,6 @@ PyObject *GPU_initPython(void)
 	PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
 	Py_INCREF(submodule);

-	PyDict_SetItem(PyImport_GetModuleDict(), PyModule_GetNameObject(module), module);
+	PyDict_SetItem(sys_modules, PyModule_GetNameObject(module), module);
 	return module;
 }
diff --git a/source/blender/python/mathutils/mathutils.c b/source/blender/python/mathutils/mathutils.c
index a3a4e7f313b..f021d456b3a 100644
--- a/source/blender/python/mathutils/mathutils.c
+++ b/source/blender/python/mathutils/mathutils.c
@@ -615,7 +615,7 @@ PyMODINIT_FUNC PyInit_mathutils(void)
 {
 	PyObject *mod;
 	PyObject *submodule;
-	PyObject *sys_modules = PyThreadState_GET()->interp->modules;
+	PyObject *sys_modules = PyImport_GetModuleDict();

 	if (PyType_Ready(&vector_Type) < 0)
 		return NULL;
diff --git a/source/blender/python/mathutils/mathutils_noise.c b/source/blender/python/mathutils/mathutils_noise.c
index 839d1ffc588..834322c0aed 100644
--- a/source/blender/python/mathutils/mathutils_noise.c
+++ b/source/blender/python/mathutils/mathutils_noise.c
@@ -845,6 +845,7 @@ static struct PyModuleDef M_Noise_module_def = {
 /*----------------------------MODULE INIT-------------------------*/
 PyMODINIT_FUNC PyInit_mathutils_noise(void)
 {
+	PyObject *sys_modules = PyImport_GetModuleDict();
 	PyObject *submodule = PyModule_Create(&M_Noise_module_def);
 	PyObject *item_types, *item_metrics;

@@ -852,11 +853,11 @@ PyMODINIT_FUNC PyInit_mathutils_noise(void)
 	setRndSeed(0);

 	PyModule_AddObject(submodule, "types", (item_types = PyInit_mathutils_noise_types()));
-	PyDict_SetItemString(PyThreadState_GET()->interp->modules, "noise.types", item_types);
+	PyDict_SetItemString(sys_modules, "noise.types", item_types);
 	Py_INCREF(item_types);

 	PyModule_AddObject(submodule, "distance_metrics", (item_metrics = PyInit_mathutils_noise_metrics()));
-	PyDict_SetItemString(PyThreadState_GET()->interp->modules, "noise.distance_metrics", item_metrics);
+	PyDict_SetItemString(sys_modules, "noise.distance_metrics", item_metrics);
 	Py_INCREF(item_metrics);

 	return submodule;
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 251273cf7a8..9611a4ea49b 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -2234,7 +2234,7 @@ PyMODINIT_FUNC initBGE(void)
 {
 	PyObject *mod;
 	PyObject *submodule;
-	PyObject *sys_modules = PyThreadState_GET()->interp->modules;
+	PyObject *sys_modules = PyImport_GetModuleDict();
 	const char *mod_full;

 	mod = PyModule_Create(&BGE_module_def);
--
2.25.0


code:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e89a6a9..a594786 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -126,10 +126,6 @@ find_package(LibBpf)
 find_package(LibBfd)
 find_package(LibOpcodes)

-if(${LIBBFD_FOUND} AND ${LIBOPCODES_FOUND})
-  set(HAVE_BFD_DISASM TRUE)
-endif()
-
 include(CheckIncludeFile)
 check_include_file("sys/sdt.h" HAVE_SYSTEMTAP_SYS_SDT_H)


code:
See: https://bugs.gentoo.org/708350
Author: Patrick McLean <patrick.mclean@sony.com>
Date: 2020-02-06 23:06:22 +0000
diff --git a/coreutils/date.c b/coreutils/date.c
index 3414d38ae..4ade6abb4 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -279,6 +279,9 @@ int date_main(int argc UNUSED_PARAM, char **argv)
 		time(&ts.tv_sec);
 #endif
 	}
+#if !ENABLE_FEATURE_DATE_NANO
+	ts.tv_nsec = 0;
+#endif
 	localtime_r(&ts.tv_sec, &tm_time);

 	/* If date string is given, update tm_time, and maybe set date */
@@ -301,9 +304,10 @@ int date_main(int argc UNUSED_PARAM, char **argv)
 		if (date_str[0] != '@')
 			tm_time.tm_isdst = -1;
 		ts.tv_sec = validate_tm_time(date_str, &tm_time);
+		ts.tv_nsec = 0;

 		/* if setting time, set it */
-		if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) {
+		if ((opt & OPT_SET) && clock_settime(CLOCK_REALTIME, &ts) < 0) {
 			bb_perror_msg("can't set date");
 		}
 	}
diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
index 87cf59b3d..dc40d9155 100644
--- a/libbb/missing_syscalls.c
+++ b/libbb/missing_syscalls.c
@@ -15,14 +15,6 @@ pid_t getsid(pid_t pid)
 	return syscall(__NR_getsid, pid);
 }

-int stime(const time_t *t)
-{
-	struct timeval tv;
-	tv.tv_sec = *t;
-	tv.tv_usec = 0;
-	return settimeofday(&tv, NULL);
-}
-
 int sethostname(const char *name, size_t len)
 {
 	return syscall(__NR_sethostname, name, len);
diff --git a/util-linux/rdate.c b/util-linux/rdate.c
index 70f829e7f..878375d78 100644
--- a/util-linux/rdate.c
+++ b/util-linux/rdate.c
@@ -95,9 +95,13 @@ int rdate_main(int argc UNUSED_PARAM, char **argv)
 	if (!(flags & 2)) { /* no -p (-s may be present) */
 		if (time(NULL) == remote_time)
 			bb_error_msg("current time matches remote time");
-		else
-			if (stime(&remote_time) < 0)
+		else {
+			struct timespec ts;
+			ts.tv_sec = remote_time;
+			ts.tv_nsec = 0;
+			if (clock_settime(CLOCK_REALTIME, &ts) < 0)
 				bb_perror_msg_and_die("can't set time of day");
+		}
 	}

 	if (flags != 1) /* not lone -s */


code:
Skeleton status files are installed read-only.  When copying to the config dir
upon initialization, make sure they end up writable.

--- byobu-5.127/usr/bin/byobu-janitor.in
+++ byobu-5.127/usr/bin/byobu-janitor.in
@@ -82,6 +82,7 @@
 	if [ ! -r "$BYOBU_CONFIG_DIR/$f" ]; then
 		# Copy from skeleton, if possible
 		cp -f "$BYOBU_PREFIX/share/$PKG/status/$f" "$BYOBU_CONFIG_DIR/$f"
+		chmod +w "$BYOBU_CONFIG_DIR/$f"
 	fi
 done


code:
Taken from debian.

# Description: Disable update check by default.
Index: calibre/src/calibre/gui2/main.py
===================================================================
--- calibre.orig/src/calibre/gui2/main.py	2014-02-02 10:41:28.470954623 +0100
+++ calibre/src/calibre/gui2/main.py	2014-02-02 10:41:56.546954247 +0100
@@ -37,8 +37,8 @@
                       help=_('Start minimized to system tray.'))
     parser.add_option('-v', '--verbose', default=0, action='count',
                       help=_('Ignored, do not use. Present only for legacy reasons'))
-    parser.add_option('--no-update-check', default=False, action='store_true',
-            help=_('Do not check for updates'))
+    parser.add_option('--update-check', dest='no_update_check', default=True, action='store_false',
+            help=_('Check for updates'))
     parser.add_option('--ignore-plugins', default=False, action='store_true',
             help=_('Ignore custom plugins, useful if you installed a plugin'
                 ' that is preventing calibre from starting'))


code:
From a92e26359bd07743ab105819ed0b619e27e14017 Mon Sep 17 00:00:00 2001
From: Brendan Tildesley <mail@brendan.scot>
Date: Sat, 27 Apr 2019 03:30:53 +1000
Subject: [PATCH] Disable test_sqlite.

---
 src/calibre/test_build.py | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py
index 07bdffd3e5..740588c95b 100644
--- a/src/calibre/test_build.py
+++ b/src/calibre/test_build.py
@@ -162,12 +162,6 @@ class BuildTest(unittest.TestCase):
             au(x, 'strftime')
             self.assertEqual(unicode_type(time.strftime(fmt.replace('%e', '%#d'), t)), x)

-    def test_sqlite(self):
-        import sqlite3
-        conn = sqlite3.connect(':memory:')
-        from calibre.library.sqlite import load_c_extensions
-        self.assertTrue(load_c_extensions(conn, True), 'Failed to load sqlite extension')
-
     def test_apsw(self):
         import apsw
         conn = apsw.Connection(':memory:')
--
2.21.0


code:
Unrar contains security vulnerabilities and has thus been removed from Guix.
From a16f97b02bd8afd0ec05c471e156f631f2cc6eec Mon Sep 17 00:00:00 2001
From: Brendan Tildesley <mail@brendan.scot>
Date: Tue, 26 Mar 2019 22:17:03 +1100
Subject: [PATCH] Remove test_unrar.

---
 src/calibre/test_build.py | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py
index d67afd20a6..709132ef17 100644
--- a/src/calibre/test_build.py
+++ b/src/calibre/test_build.py
@@ -220,10 +220,6 @@ class BuildTest(unittest.TestCase):
         from calibre.gui2.win_file_dialogs import test
         test()

-    def test_unrar(self):
-        from calibre.utils.unrar import test_basic
-        test_basic()
-
     @unittest.skipUnless(iswindows, 'WPD is windows only')
     def test_wpd(self):
         wpd = plugins['wpd'][0]
--
2.21.0


code:
Fix build failure on glibc 2.28 where 'renameat2' would end up being
declared twice: <https://github.com/systemd/casync/issues/166>.

From 625244ca47e8ee1375d2d0092271bfd13b0913ea Mon Sep 17 00:00:00 2001
From: Daniel Mack <daniel@zonque.org>
Date: Tue, 13 Nov 2018 17:52:48 +0100
Subject: [PATCH] meson.build: pass -D_GNU_SOURCE when checking for functions

As described in #166, -D_GNU_SOURCE needs to be passed to the meson function
availability checker. h/t to @tomeon for providing a link to the solution as
well.
---
 meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index f42ed16..c0f741e 100644
--- a/meson.build
+++ b/meson.build
@@ -78,6 +78,6 @@ foreach ident : [
         ['copy_file_range',   '''#include <sys/syscall.h>
                                  #include <unistd.h>'''],
 ]
-        have = cc.has_function(ident[0], prefix : ident[1])
+        have = cc.has_function(ident[0], args : '-D_GNU_SOURCE', prefix : ident[1])
         conf.set10('HAVE_' + ident[0].to_upper(), have)
 endforeach


code:
Fix CVE-2017-11110:

https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-11110
https://bugzilla.redhat.com/show_bug.cgi?id=1468471
https://security-tracker.debian.org/tracker/CVE-2017-11110

Patch copied from openSUSE:

https://build.opensuse.org/package/view_file/openSUSE:Maintenance:6985/catdoc.openSUSE_Leap_42.2_Update/CVE-2017-11110.patch?expand=1

From: Andreas Stieger <astieger@suse.com>
Date: Mon, 10 Jul 2017 15:37:58 +0000
References: CVE-2017-11110 http://bugzilla.suse.com/show_bug.cgi?id=1047877

All .doc I found had sectorSize 0x09 at offset 0x1e. Guarding it against <4.

---
 src/ole.c |    5 +++++
 1 file changed, 5 insertions(+)

Index: catdoc-0.95/src/ole.c
===================================================================
--- catdoc-0.95.orig/src/ole.c	2016-05-25 06:37:12.000000000 +0200
+++ catdoc-0.95/src/ole.c	2017-07-10 17:42:33.578308107 +0200
@@ -106,6 +106,11 @@ FILE* ole_init(FILE *f, void *buffer, si
 		return NULL;
 	}
  	sectorSize = 1<<getshort(oleBuf,0x1e);
+	/* CVE-2017-11110) */
+ 	if (sectorSize < 4) {
+		fprintf(stderr,"sectorSize < 4 not supported\n");
+		return NULL;
+	}
 	shortSectorSize=1<<getshort(oleBuf,0x20);

 /* Read BBD into memory */
@@ -147,7 +152,7 @@ FILE* ole_init(FILE *f, void *buffer, si
 		}

 		fseek(newfile, 512+mblock*sectorSize, SEEK_SET);
-		if(fread(tmpBuf+MSAT_ORIG_SIZE+(sectorSize-4)*i,
+		if(fread(tmpBuf+MSAT_ORIG_SIZE+(sectorSize-4)*i, /* >= 4 for CVE-2017-11110 */
 						 1, sectorSize, newfile) != sectorSize) {
 			fprintf(stderr, "Error read MSAT!\n");
 			ole_finish();


code:
diff -r -u cdparanoia-III-10.2.old/interface/Makefile.in cdparanoia-III-10.2.new/interface/Makefile.in
--- cdparanoia-III-10.2.old/interface/Makefile.in	2008-08-21 18:08:54.000000000 +0200
+++ cdparanoia-III-10.2.new/interface/Makefile.in	2013-08-07 18:48:32.000000000 +0200
@@ -7,7 +7,7 @@
 srcdir=@srcdir@

 @SET_MAKE@
-FLAGS=@SBPCD_H@ @UCDROM_H@ @TYPESIZES@ @CFLAGS@
+FLAGS=@SBPCD_H@ @UCDROM_H@ @TYPESIZES@ @CFLAGS@ -fPIC
 OPT=@OPT@ $(FLAGS)
 DEBUG=@DEBUG@ -DCDDA_TEST
 CC=@CC@
@@ -33,7 +33,7 @@

 slib:
 	$(MAKE) lessmessy
-	$(MAKE) libcdda_interface.so CFLAGS="$(OPT) -fpic"
+	$(MAKE) libcdda_interface.so CFLAGS="$(OPT)"
 	[ -e libcdda_interface.so.0 ] || ln -s libcdda_interface.so libcdda_interface.so.0

 test:
@@ -46,7 +46,7 @@
 	$(RANLIB) libcdda_interface.a

 libcdda_interface.so: 	$(OFILES)
-	$(CC) -fpic -shared -o libcdda_interface.so.0.$(VERSION) -Wl,-soname -Wl,libcdda_interface.so.0 $(OFILES) $(LIBS)
+	$(CC) -fPIC -shared -o libcdda_interface.so.0.$(VERSION) -Wl,-soname -Wl,libcdda_interface.so.0 $(OFILES) $(LIBS)
 	[ -e libcdda_interface.so.0 ] || ln -s libcdda_interface.so.0.$(VERSION) libcdda_interface.so.0
 	[ -e libcdda_interface.so ] || ln -s libcdda_interface.so.0.$(VERSION) libcdda_interface.so

diff -r -u cdparanoia-III-10.2.old/paranoia/Makefile.in cdparanoia-III-10.2.new/paranoia/Makefile.in
--- cdparanoia-III-10.2.old/paranoia/Makefile.in	2008-09-04 21:02:47.000000000 +0200
+++ cdparanoia-III-10.2.new/paranoia/Makefile.in	2013-08-07 18:49:54.000000000 +0200
@@ -9,7 +9,7 @@

 @SET_MAKE@
 FLAGS=@TYPESIZES@ @CFLAGS@
-OPT=@OPT@ $(FLAGS)
+OPT=@OPT@ $(FLAGS) -fPIC
 DEBUG=@DEBUG@
 CC=@CC@
 LD=@CC@
@@ -34,7 +34,7 @@

 slib:
 	$(MAKE) lessmessy
-	$(MAKE) libcdda_paranoia.so CFLAGS="$(OPT) -fpic"
+	$(MAKE) libcdda_paranoia.so CFLAGS="$(OPT)"

 #test:	$(TFILES)
 #
@@ -44,7 +44,7 @@
 	$(RANLIB) libcdda_paranoia.a

 libcdda_paranoia.so: 	$(OFILES)
-	$(CC) -fpic -shared -o libcdda_paranoia.so.0.$(VERSION) -Wl,-soname -Wl,libcdda_paranoia.so.0 $(OFILES) -L ../interface -lcdda_interface
+	$(CC) -fPIC -shared -o libcdda_paranoia.so.0.$(VERSION) -Wl,-soname -Wl,libcdda_paranoia.so.0 $(OFILES) -L ../interface -lcdda_interface
 	[ -e libcdda_paranoia.so.0 ] || ln -s libcdda_paranoia.so.0.$(VERSION) libcdda_paranoia.so.0
 	[ -e libcdda_paranoia.so ] || ln -s libcdda_paranoia.so.0.$(VERSION) libcdda_paranoia.so


code:
Patch for version 3.01, taken from upstream at
https://sourceforge.net/projects/cdrtools/files/cdrtools-3.01-fix-20151126-mkisofs-isoinfo.patch

--- cdrtools-3.01.orig/mkisofs/diag/isoinfo.c	2015-07-22 20:36:45.000000000 +0000
+++ cdrtools-3.01/mkisofs/diag/isoinfo.c	2015-11-17 19:35:40.000000000 +0000
@@ -1,8 +1,8 @@
-/* @(#)isoinfo.c	1.95 15/07/22 joerg */
+/* @(#)isoinfo.c	1.100 15/11/17 joerg */
 #include <schily/mconfig.h>
 #ifndef	lint
 static	UConst char sccsid[] =
-	"@(#)isoinfo.c	1.95 15/07/22 joerg";
+	"@(#)isoinfo.c	1.100 15/11/17 joerg";
 #endif
 /*
  * File isodump.c - dump iso9660 directory information.
@@ -148,8 +148,10 @@ LOCAL char	er_id[256];
 LOCAL int	su_version = 0;
 LOCAL int	rr_version = 0;
 LOCAL int	aa_version = 0;
+LOCAL int	cl_extent = 0;
 LOCAL int	ucs_level = 0;
 LOCAL BOOL	iso9660_inodes = FALSE;
+LOCAL uid_t	myuid;

 #ifdef	USE_FIND
 LOCAL findn_t	*find_node;		/* syntaxtree from find_parse()	*/
@@ -208,6 +210,9 @@ LOCAL	void	extract		__PR((char *rootname
 LOCAL	void	extract_file	__PR((int f,
 					struct iso_directory_record * idr,
 					char *fname));
+LOCAL	void	parse_cl_dir	__PR((struct iso_directory_record *idr,
+					int extent));
+LOCAL	BOOL	parse_de	__PR((struct iso_directory_record *idr));
 LOCAL	void	parse_dir	__PR((char * rootname, int extent, int len));
 LOCAL	void	usage		__PR((int excode));
 EXPORT	int	main		__PR((int argc, char *argv[]));
@@ -459,7 +464,6 @@ parse_rr(pnt, len, cont_flag)
 	int slen;
 	int xlen;
 	int ncount;
-	int cl_extent;
 	int pl_extent;
 	int cont_extent, cont_offset, cont_size;
 	int flag1, flag2;
@@ -469,7 +473,7 @@ parse_rr(pnt, len, cont_flag)

 	symlinkname[0] = 0;

-	cont_extent = cont_offset = cont_size = 0;
+	cl_extent = cont_extent = cont_offset = cont_size = 0;

 	ncount = 0;
 	flag1 = -1;
@@ -714,6 +718,7 @@ struct todo
 };

 LOCAL struct todo	*todo_idr = NULL;
+LOCAL struct todo	**todo_pp = &todo_idr;

 LOCAL char		*months[12] = {"Jan", "Feb", "Mar", "Apr",
 				"May", "Jun", "Jul",
@@ -962,8 +967,14 @@ static	BOOL		isfirst = TRUE;
 	close(f);
 	return;
 setmode:
-	fchmodat(AT_FDCWD, fname, fstat_buf.st_mode, AT_SYMLINK_NOFOLLOW);
 	fchownat(AT_FDCWD, fname, fstat_buf.st_uid, fstat_buf.st_gid, AT_SYMLINK_NOFOLLOW);
+	if (myuid != 0 && S_ISDIR(fstat_buf.st_mode)) {
+		/*
+		 * Temporary hack until we have a dirstack like star.
+		 */
+		fstat_buf.st_mode |= S_IWUSR;
+	}
+	fchmodat(AT_FDCWD, fname, fstat_buf.st_mode, AT_SYMLINK_NOFOLLOW);
 	times[0].tv_sec = fstat_buf.st_atime;
 	times[0].tv_nsec = stat_ansecs(&fstat_buf);
 	times[1].tv_sec = fstat_buf.st_mtime;
@@ -1001,6 +1012,143 @@ extract_file(f, idr, fname)
 	}
 }

+
+LOCAL void
+parse_cl_dir(idr, extent)
+	struct iso_directory_record	*idr;
+	int				extent;
+{
+	char				cl_name_buf[256*3];
+
+	strlcpy(cl_name_buf, name_buf, sizeof (cl_name_buf));
+#ifdef	USE_SCG
+	readsecs(extent - sector_offset, idr, 1);
+#else
+	lseek(fileno(infile), ((off_t)(extent - sector_offset)) << 11, SEEK_SET);
+	read(fileno(infile), idr, 2048);
+#endif
+
+	if (parse_de(idr) && use_rock)
+		dump_rr(idr);
+	strlcpy(name_buf, cl_name_buf, sizeof (name_buf));
+}
+
+LOCAL BOOL
+parse_de(idr)
+	struct iso_directory_record	*idr;
+{
+	unsigned char	uc;
+
+	if (idr->length[0] == 0)
+		return (FALSE);
+	memset(&fstat_buf, 0, sizeof (fstat_buf));
+	found_rr = 0;
+	name_buf[0] = xname[0] = 0;
+	fstat_buf.st_size = (off_t)(unsigned)isonum_733((unsigned char *)idr->size);
+	if (idr->flags[0] & 2)
+		fstat_buf.st_mode |= S_IFDIR;
+	else
+		fstat_buf.st_mode |= S_IFREG;
+	if (idr->name_len[0] == 1 && idr->name[0] == 0)
+		strcpy(name_buf, ".");
+	else if (idr->name_len[0] == 1 && idr->name[0] == 1)
+		strcpy(name_buf, "..");
+	else {
+		switch (ucs_level) {
+		case 3:
+		case 2:
+		case 1:
+			/*
+			 * Unicode name.  Convert as best we can.
+			 */
+			{
+			int	j;
+				name_buf[0] = '\0';
+#ifdef	USE_ICONV
+			if (use_iconv(unls)) {
+				int	u;
+				char	*to = name_buf;
+
+				for (j = 0, u = 0; j < (int)idr->name_len[0] / 2; j++) {
+					char	*ibuf = (char *)&idr->name[j*2];
+					size_t	isize = 2;		/* UCS-2 character size */
+					size_t	osize = 4;
+
+					if (iconv(unls->sic_uni2cd, (__IC_CONST char **)&ibuf, &isize,
+							(char **)&to, &osize) == -1) {
+						int	err = geterrno();
+
+						if ((err == EINVAL || err == EILSEQ) &&
+						    osize == 4) {
+							*to = '_';
+							u += 1;
+							to++;
+						}
+					} else {
+						u += 4 - osize;
+						to = &name_buf[u];
+					}
+				}
+				j = u;
+			} else
+#endif
+			for (j = 0; j < (int)idr->name_len[0] / 2; j++) {
+				UInt16_t	unichar;
+
+				unichar = (idr->name[j*2] & 0xFF) * 256 +
+					    (idr->name[j*2+1] & 0xFF);
+
+				/*
+				 * Get the backconverted char
+				 */
+				if (unls)
+					uc = sic_uni2c(unls, unichar);
+				else
+					uc = unichar > 255 ? '_' : unichar;
+
+				name_buf[j] = uc ? uc : '_';
+			}
+			name_buf[j] = '\0';
+			}
+			break;
+		case 0:
+			/*
+			 * Normal non-Unicode name.
+			 */
+			strncpy(name_buf, idr->name, idr->name_len[0]);
+			name_buf[idr->name_len[0]] = 0;
+			break;
+		default:
+			/*
+			 * Don't know how to do these yet.  Maybe they are the same
+			 * as one of the above.
+			 */
+			exit(1);
+		}
+	}
+	memcpy(date_buf, idr->date, 9);
+	/*
+	 * Always first set up time stamps and file modes from
+	 * ISO-9660. This is used as a fallback in case that
+	 * there is no related Rock Ridge based data.
+	 */
+	fstat_buf.st_atime =
+	fstat_buf.st_mtime =
+	fstat_buf.st_ctime = iso9660_time(date_buf, NULL, FALSE);
+	fstat_buf.st_mode |= S_IRUSR|S_IXUSR |
+		    S_IRGRP|S_IXGRP |
+		    S_IROTH|S_IXOTH;
+	fstat_buf.st_nlink = 1;
+	fstat_buf.st_ino = 0;
+	fstat_buf.st_uid = 0;
+	fstat_buf.st_gid = 0;
+	if (iso9660_inodes) {
+		fstat_buf.st_ino = (unsigned long)
+		    isonum_733((unsigned char *)idr->extent);
+	}
+	return (TRUE);
+}
+
 LOCAL void
 parse_dir(rootname, extent, len)
 	char	*rootname;
@@ -1012,12 +1160,13 @@ parse_dir(rootname, extent, len)
 	struct iso_directory_record * idr;
 	struct iso_directory_record	didr;
 	struct stat			dstat;
-	unsigned char	uc;
+	unsigned char	cl_buffer[2048];
 	unsigned char	flags = 0;
 	Llong		size = 0;
 	int		sextent = 0;
 	int	rlen;
 	int	blen;
+	int	rr_flags = 0;
 static	char	*n = 0;
 static	int	nlen = 0;

@@ -1039,115 +1188,23 @@ static	int	nlen = 0;
 		i = 0;
 		while (1 == 1) {
 			idr = (struct iso_directory_record *) &buffer[i];
-			if (idr->length[0] == 0) break;
-			memset(&fstat_buf, 0, sizeof (fstat_buf));
-			found_rr = 0;
-			name_buf[0] = xname[0] = 0;
-			fstat_buf.st_size = (off_t)(unsigned)isonum_733((unsigned char *)idr->size);
-			if (idr->flags[0] & 2)
-				fstat_buf.st_mode |= S_IFDIR;
-			else
-				fstat_buf.st_mode |= S_IFREG;
-			if (idr->name_len[0] == 1 && idr->name[0] == 0)
-				strcpy(name_buf, ".");
-			else if (idr->name_len[0] == 1 && idr->name[0] == 1)
-				strcpy(name_buf, "..");
-			else {
-				switch (ucs_level) {
-				case 3:
-				case 2:
-				case 1:
-					/*
-					 * Unicode name.  Convert as best we can.
-					 */
-					{
-					int	j;
-
-					name_buf[0] = '\0';
-#ifdef	USE_ICONV
-					if (use_iconv(unls)) {
-						int	u;
-						char	*to = name_buf;
-
-						for (j = 0, u = 0; j < (int)idr->name_len[0] / 2; j++) {
-							char	*ibuf = (char *)&idr->name[j*2];
-							size_t	isize = 2;		/* UCS-2 character size */
-							size_t	osize = 4;
-
-							if (iconv(unls->sic_uni2cd, (__IC_CONST char **)&ibuf, &isize,
-									(char **)&to, &osize) == -1) {
-								int	err = geterrno();
-
-								if ((err == EINVAL || err == EILSEQ) &&
-								    osize == 4) {
-									*to = '_';
-									u += 1;
-									to++;
-								}
-							} else {
-								u += 4 - osize;
-								to = &name_buf[u];
-							}
-						}
-						j = u;
-					} else
-#endif
-					for (j = 0; j < (int)idr->name_len[0] / 2; j++) {
-						UInt16_t	unichar;
-
-						unichar = (idr->name[j*2] & 0xFF) * 256 +
-							    (idr->name[j*2+1] & 0xFF);
-
-						/*
-						 * Get the backconverted char
-						 */
-						if (unls)
-							uc = sic_uni2c(unls, unichar);
-						else
-							uc = unichar > 255 ? '_' : unichar;
+			if (idr->length[0] == 0)
+				break;
+			parse_de(idr);
+			if (use_rock) {
+				rr_flags = dump_rr(idr);

-						name_buf[j] = uc ? uc : '_';
-					}
-					name_buf[j] = '\0';
-					}
-					break;
-				case 0:
+				if (rr_flags & RR_FLAG_CL) {
 					/*
-					 * Normal non-Unicode name.
+					 * Need to reparse the child link
+					 * but note that we parse "CL/."
+					 * so we get no usable file name.
 					 */
-					strncpy(name_buf, idr->name, idr->name_len[0]);
-					name_buf[idr->name_len[0]] = 0;
-					break;
-				default:
-					/*
-					 * Don't know how to do these yet.  Maybe they are the same
-					 * as one of the above.
-					 */
-					exit(1);
-				}
+					idr = (struct iso_directory_record *) cl_buffer;
+					parse_cl_dir(idr, cl_extent);
+				} else if (rr_flags & RR_FLAG_RE)
+					goto cont;	/* skip rr_moved */
 			}
-			memcpy(date_buf, idr->date, 9);
-			/*
-			 * Always first set up time stamps and file modes from
-			 * ISO-9660. This is used as a fallback in case that
-			 * there is no related Rock Ridge based data.
-			 */
-			fstat_buf.st_atime =
-			fstat_buf.st_mtime =
-			fstat_buf.st_ctime = iso9660_time(date_buf, NULL, FALSE);
-			fstat_buf.st_mode |= S_IRUSR|S_IXUSR |
-				    S_IRGRP|S_IXGRP |
-				    S_IROTH|S_IXOTH;
-			fstat_buf.st_nlink = 1;
-			fstat_buf.st_ino = 0;
-			fstat_buf.st_uid = 0;
-			fstat_buf.st_gid = 0;
-			if (iso9660_inodes) {
-				fstat_buf.st_ino = (unsigned long)
-				    isonum_733((unsigned char *)idr->extent);
-			}
-			if (use_rock)
-				dump_rr(idr);
 			if (Xtract &&
 			    (idr->flags[0] & 2) != 0 &&
 			    idr->name_len[0] == 1 &&
@@ -1170,30 +1227,30 @@ static	int	nlen = 0;
 				n[rlen] = '\0';

 			if ((idr->flags[0] & 2) != 0 &&
-			    (idr->name_len[0] != 1 ||
+			    ((rr_flags & RR_FLAG_CL) ||
+			    idr->name_len[0] != 1 ||
 			    (idr->name[0] != 0 && idr->name[0] != 1))) {
 				/*
 				 * This is a plain directory (neither "xxx/."
 				 * nor "xxx/..").
 				 * Add this directory to the todo list.
 				 */
-				td = todo_idr;
-				if (td != NULL) {
-					while (td->next != NULL)
-						td = td->next;
-					td->next = (struct todo *) malloc(sizeof (*td));
-					td = td->next;
-				} else {
-					todo_idr = td = (struct todo *) malloc(sizeof (*td));
-				}
+				td = (struct todo *) malloc(sizeof (*td));
+				if (td == NULL)
+					comerr(_("No memory.\n"));
 				td->next = NULL;
 				td->extent = isonum_733((unsigned char *)idr->extent);
 				td->length = isonum_733((unsigned char *)idr->size);
 				td->name = (char *) malloc(strlen(rootname)
 								+ strlen(name_buf) + 2);
+				if (td->name == NULL)
+					comerr(_("No memory.\n"));
 				strcpy(td->name, rootname);
 				strcat(td->name, name_buf);
 				strcat(td->name, "/");
+
+				*todo_pp = td;
+				todo_pp = &td->next;
 			} else {
 				if (xtract && strcmp(xtract, n) == 0) {
 					extract_file(STDOUT_FILENO, idr, "stdout");
@@ -1253,6 +1310,7 @@ static	int	nlen = 0;
 				if ((idr->flags[0] & ISO_MULTIEXTENT) == 0)
 					size = 0;
 			}
+		cont:
 			i += buffer[i];
 			if (i > 2048 - offsetof(struct iso_directory_record, name[0])) break;
 		}
@@ -1381,12 +1439,13 @@ main(argc, argv)
 		usage(0);
 	if (prvers) {
 		printf(_("isoinfo %s (%s-%s-%s) Copyright (C) 1993-1999 %s (C) 1999-2015 %s\n"),
-					VERSION,
+					"3.02a02",
 					HOST_CPU, HOST_VENDOR, HOST_OS,
 					_("Eric Youngdale"),
 					_("Joerg Schilling"));
 		exit(0);
 	}
+	myuid = getuid();
 #ifdef	USE_FIND
 	if (do_find) {
 		finda_t	fa;
--- cdrtools-3.01.orig/mkisofs/udf.c	2013-04-24 20:45:18.000000000 +0000
+++ cdrtools-3.01/mkisofs/udf.c	2015-11-25 22:07:30.000000000 +0000
@@ -1,15 +1,15 @@
-/* @(#)udf.c	1.42 13/04/24 Copyright 2001-2013 J. Schilling */
+/* @(#)udf.c	1.43 15/11/25 Copyright 2001-2015 J. Schilling */
 #include <schily/mconfig.h>
 #ifndef lint
 static	UConst char sccsid[] =
-	"@(#)udf.c	1.42 13/04/24 Copyright 2001-2013 J. Schilling";
+	"@(#)udf.c	1.43 15/11/25 Copyright 2001-2015 J. Schilling";
 #endif
 /*
  * udf.c - UDF support for mkisofs
  *
  * Written by Ben Rudiak-Gould (2001).
  *
- * Copyright 2001-2013 J. Schilling.
+ * Copyright 2001-2015 J. Schilling.
  */
 /*
  * This program is free software; you can redistribute it and/or modify
@@ -98,7 +98,7 @@ static	UConst char sccsid[] =
 extern	int	use_sparcboot;

 extern struct directory *root;
-extern time_t		begun;
+extern struct timeval	tv_begun;

 static unsigned lba_main_seq;
 static unsigned lba_main_seq_copy;
@@ -110,7 +110,7 @@ static unsigned lba_end_anchor_vol_desc;
 static unsigned num_udf_files;
 static unsigned num_udf_directories;

-static unsigned volume_set_id[2];
+static unsigned volume_set_id[2] = { 0, 0 };

 #define	UDF_MAIN_SEQ_LENGTH (16)
 #define	UDF_INTEG_SEQ_LENGTH (2)
@@ -723,7 +723,7 @@ set_primary_vol_desc(buf, lba)
 	/*pvd->volume_abstract;*/
 	/*pvd->volume_copyright_notice;*/
 	/*pvd->application_ident;*/
-	set_timestamp_from_time_t(&pvd->recording_date_and_time, begun);
+	set_timestamp_from_time_t(&pvd->recording_date_and_time, tv_begun.tv_sec);
 	set_impl_ident(&pvd->impl_ident);
 	set_tag(&pvd->desc_tag, UDF_TAGID_PRIMARY_VOLUME_DESC, lba, 512);
 }
@@ -831,7 +831,7 @@ set_logical_vol_integrity_desc(buf, lba)
 	udf_logical_volume_integrity_desc *lvid =
 				(udf_logical_volume_integrity_desc *)buf;

-	set_timestamp_from_time_t(&lvid->recording_date, begun);
+	set_timestamp_from_time_t(&lvid->recording_date, tv_begun.tv_sec);
 	set32(&lvid->integrity_type, UDF_INTEGRITY_TYPE_CLOSE);
 	/*lvid->next_integrity_extent;*/
 	set64(&lvid->logical_volume_contents_use.unique_id,
@@ -859,7 +859,7 @@ set_file_set_desc(buf, rba)
 {
 	udf_file_set_desc *fsd = (udf_file_set_desc *)buf;

-	set_timestamp_from_time_t(&fsd->recording_date_and_time, begun);
+	set_timestamp_from_time_t(&fsd->recording_date_and_time, tv_begun.tv_sec);
 	set16(&fsd->interchange_level, 3);
 	set16(&fsd->maximum_interchange_level, 3);
 	set32(&fsd->character_set_list, 1);
@@ -1986,8 +1986,10 @@ udf_main_seq_write(out)
 	 * volume_set_id needs to be set to a (64-bit) "unique" number.
 	 * This will have to do for now.
 	 */
-	volume_set_id[0] = begun;
-	volume_set_id[1] = (unsigned)clock();	/* XXX Maybe non-portable */
+	if (volume_set_id[0] == 0) {
+		volume_set_id[0] = tv_begun.tv_sec;
+		volume_set_id[1] = (unsigned)tv_begun.tv_usec;
+	}

 	memset(buf, 0, sizeof (buf));
 	set_primary_vol_desc(buf, last_extent_written++);
--- cdrtools-3.01.orig/mkisofs/mkisofs.c	2015-01-01 14:19:51.000000000 +0000
+++ cdrtools-3.01/mkisofs/mkisofs.c
@@ -69 +69 @@ int		path_ind;
-char	version_string[] = VERSION;
+char	version_string[] = "3.01-fix-20151126";


code:
Disable CPU optimizations not supported by all x86_64 systems.

--- a/cmake/modules/SIMDExt.cmake	2017-03-23 22:22:58.254071694 +0100
+++ b/cmake/modules/SIMDExt.cmake	2017-03-23 22:23:22.446848845 +0100
@@ -5,11 +5,6 @@
 # HAVE_ARM_NEON
 # HAVE_INTEL_SSE
 # HAVE_INTEL_SSE2
-# HAVE_INTEL_SSE3
-# HAVE_INTEL_SSSE3
-# HAVE_INTEL_PCLMUL
-# HAVE_INTEL_SSE4_1
-# HAVE_INTEL_SSE4_2
 #
 # SIMD_COMPILE_FLAGS
 #
@@ -85,26 +80,6 @@
       if(HAVE_INTEL_SSE2)
         set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -msse2")
       endif()
-      CHECK_C_COMPILER_FLAG(-msse3 HAVE_INTEL_SSE3)
-      if(HAVE_INTEL_SSE3)
-        set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -msse3")
-      endif()
-      CHECK_C_COMPILER_FLAG(-mssse3 HAVE_INTEL_SSSE3)
-      if(HAVE_INTEL_SSSE3)
-        set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -mssse3")
-      endif()
-      CHECK_C_COMPILER_FLAG(-mpclmul HAVE_INTEL_PCLMUL)
-      if(HAVE_INTEL_PCLMUL)
-        set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -mpclmul")
-      endif()
-      CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_INTEL_SSE4_1)
-      if(HAVE_INTEL_SSE4_1)
-        set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -msse4.1")
-      endif()
-      CHECK_C_COMPILER_FLAG(-msse4.2 HAVE_INTEL_SSE4_2)
-      if(HAVE_INTEL_SSE4_2)
-        set(SIMD_COMPILE_FLAGS "${SIMD_COMPILE_FLAGS} -msse4.2")
-      endif()
     endif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64")
   endif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686|amd64|x86_64|AMD64")
 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(powerpc|ppc)64le")


code:
Taken from Debian, necessary for compilation on mips.

Patch to fix integer types problem by Goswin von Brederlow
<brederlo@informatik.uni-tuebingen.de> (#258444)
--- chmlib-0.39.orig/src/chm_lib.c
+++ chmlib-0.39/src/chm_lib.c
@@ -56,6 +56,7 @@

 #include "lzx.h"

+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #ifdef CHM_DEBUG
@@ -149,22 +150,9 @@
 typedef __int64                 Int64;
 typedef unsigned __int64        UInt64;

-/* I386, 32-bit, non-Windows */
-/* Sparc        */
-/* MIPS         */
-/* PPC          */
-#elif __i386__ || __sun || __sgi || __ppc__
-typedef unsigned char           UChar;
-typedef short                   Int16;
-typedef unsigned short          UInt16;
-typedef long                    Int32;
-typedef unsigned long           UInt32;
-typedef long long               Int64;
-typedef unsigned long long      UInt64;
-
 /* x86-64 */
 /* Note that these may be appropriate for other 64-bit machines. */
-#elif __x86_64__ || __ia64__
+#elif defined(__LP64__)
 typedef unsigned char           UChar;
 typedef short                   Int16;
 typedef unsigned short          UInt16;
@@ -173,10 +161,18 @@
 typedef long                    Int64;
 typedef unsigned long           UInt64;

+/* I386, 32-bit, non-Windows */
+/* Sparc        */
+/* MIPS         */
+/* PPC          */
 #else
-
-/* yielding an error is preferable to yielding incorrect behavior */
-#error "Please define the sized types for your platform in chm_lib.c"
+typedef unsigned char           UChar;
+typedef short                   Int16;
+typedef unsigned short          UInt16;
+typedef long                    Int32;
+typedef unsigned long           UInt32;
+typedef long long               Int64;
+typedef unsigned long long      UInt64;
 #endif

 /* GCC */


code:
This patch was created by Roel Janssen <roel@gnu.org>.

Circos uses paths relative to the "circos" script to find its Perl modules.
This patch removes that mechanism, and instead expects the 'Circos' modules
to be available in the global Perl path.

diff -crB circos-0.69-6/bin/circos circos-0.69-6-new/bin/circos
*** circos-0.69-6/bin/circos	2016-02-19 01:42:59.000000000 +0100
--- circos-0.69-6-new/bin/circos	2018-01-12 09:59:25.662731269 +0100
***************
*** 474,486 ****

  use strict;
  use warnings;
- use FindBin;
  use Getopt::Long qw(:config pass_through posix_default auto_abbrev);
  use Pod::Usage;

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
  use Circos;

  use Cwd;
--- 474,482 ----
diff -crB circos-0.69-6/lib/Circos/Colors.pm circos-0.69-6-new/lib/Circos/Colors.pm
*** circos-0.69-6/lib/Circos/Colors.pm	2015-03-17 01:25:43.000000000 +0100
--- circos-0.69-6-new/lib/Circos/Colors.pm	2018-01-12 10:10:39.174797379 +0100
***************
*** 49,55 ****

  use Carp qw( carp confess croak );
  use Digest::MD5 qw(md5_hex);
- use FindBin;
  use File::Basename;
  use File::Spec::Functions;
  use File::Temp qw(tempdir);
--- 49,54 ----
***************
*** 65,74 ****
  #use Time::HiRes qw(gettimeofday tv_interval);
  #use List::Util qw( max min );

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use POSIX qw(pow);

  use Circos::Configuration;
--- 64,69 ----
diff -crB circos-0.69-6/lib/Circos/Configuration.pm circos-0.69-6-new/lib/Circos/Configuration.pm
*** circos-0.69-6/lib/Circos/Configuration.pm	2015-03-17 22:11:01.000000000 +0100
--- circos-0.69-6-new/lib/Circos/Configuration.pm	2018-01-12 10:11:41.064008273 +0100
***************
*** 59,68 ****
  use Params::Validate qw(:all);
  use List::MoreUtils qw(uniq);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Constants;
  use Circos::Debug;
  use Circos::Utils;
--- 59,64 ----
diff -crB circos-0.69-6/lib/Circos/DataPoint.pm circos-0.69-6-new/lib/Circos/DataPoint.pm
*** circos-0.69-6/lib/Circos/DataPoint.pm	2014-05-12 18:20:19.000000000 +0200
--- circos-0.69-6-new/lib/Circos/DataPoint.pm	2018-01-12 10:11:54.888270731 +0100
***************
*** 38,51 ****

  use Carp qw( carp confess croak );
  use Data::Dumper;
- use FindBin;
  use GD::Image;
  use Params::Validate qw(:all);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration; # qw(%CONF $DIMS);
  use Circos::Constants;
  use Circos::Debug;
--- 38,46 ----
diff -crB circos-0.69-6/lib/Circos/Debug.pm circos-0.69-6-new/lib/Circos/Debug.pm
*** circos-0.69-6/lib/Circos/Debug.pm	2015-03-24 01:26:13.000000000 +0100
--- circos-0.69-6-new/lib/Circos/Debug.pm	2018-01-12 10:12:07.192502006 +0100
***************
*** 63,75 ****

  use Carp qw( carp confess croak );
  use Data::Dumper;
- use FindBin;
  use Memoize;
  use List::MoreUtils qw(uniq);
  use Time::HiRes qw(gettimeofday tv_interval);
- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";

  use Circos::Constants;

--- 63,71 ----
diff -crB circos-0.69-6/lib/Circos/Division.pm circos-0.69-6-new/lib/Circos/Division.pm
*** circos-0.69-6/lib/Circos/Division.pm	2015-11-17 00:55:58.000000000 +0100
--- circos-0.69-6-new/lib/Circos/Division.pm	2018-01-12 10:12:21.544769084 +0100
***************
*** 37,52 ****
  our @EXPORT = qw();

  use Carp qw( carp confess croak );
- use FindBin;
  use GD;
  use Math::Round;
  use List::MoreUtils qw(uniq);
  use Params::Validate qw(:all);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration;
  use Circos::Constants;
  use Circos::Debug;
--- 37,47 ----
diff -crB circos-0.69-6/lib/Circos/Error.pm circos-0.69-6-new/lib/Circos/Error.pm
*** circos-0.69-6/lib/Circos/Error.pm	2015-03-17 22:46:36.000000000 +0100
--- circos-0.69-6-new/lib/Circos/Error.pm	2018-01-12 10:12:32.472970548 +0100
***************
*** 44,53 ****
  use Params::Validate;
  use Text::Format;

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Constants;
  use Circos::Debug;
  use Circos::Utils;
--- 44,49 ----
diff -crB circos-0.69-6/lib/Circos/Expression.pm circos-0.69-6-new/lib/Circos/Expression.pm
*** circos-0.69-6/lib/Circos/Expression.pm	2015-11-30 23:49:36.000000000 +0100
--- circos-0.69-6-new/lib/Circos/Expression.pm	2018-01-12 10:12:41.953144015 +0100
***************
*** 39,55 ****

  use Carp qw( carp confess croak );
  use Data::Dumper;
- use FindBin;
  use Params::Validate qw(:all);
  use Math::Round;
  use Math::VecStat qw(average);
  use List::Util qw(min max);
  use Text::Balanced qw(extract_bracketed);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration;
  use Circos::Constants;
  use Circos::Debug;
--- 39,50 ----
diff -crB circos-0.69-6/lib/Circos/Font.pm circos-0.69-6-new/lib/Circos/Font.pm
*** circos-0.69-6/lib/Circos/Font.pm	2014-05-12 18:20:19.000000000 +0200
--- circos-0.69-6-new/lib/Circos/Font.pm	2018-01-12 10:12:51.657320357 +0100
***************
*** 45,59 ****
  );

  use Carp qw( carp confess croak );
- use FindBin;
  use GD::Image;
  use Font::TTF::Font;
  use Params::Validate qw(:all);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration; # qw(%CONF $DIMS fetch_conf);
  use Circos::Constants;
  use Circos::Colors;
--- 45,54 ----
diff -crB circos-0.69-6/lib/Circos/Geometry.pm circos-0.69-6-new/lib/Circos/Geometry.pm
*** circos-0.69-6/lib/Circos/Geometry.pm	2014-05-12 18:20:19.000000000 +0200
--- circos-0.69-6-new/lib/Circos/Geometry.pm	2018-01-12 10:12:58.961452282 +0100
***************
*** 41,54 ****
  );

  use Carp qw( carp confess croak );
- use FindBin;
  use GD::Image;
  use Params::Validate qw(:all);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration; # qw(%CONF $DIMS fetch_conf);
  use Circos::Constants;
  use Circos::Debug;
--- 41,49 ----
diff -crB circos-0.69-6/lib/Circos/Heatmap.pm circos-0.69-6-new/lib/Circos/Heatmap.pm
*** circos-0.69-6/lib/Circos/Heatmap.pm	2016-03-30 22:08:12.000000000 +0200
--- circos-0.69-6-new/lib/Circos/Heatmap.pm	2018-01-12 10:13:09.953649538 +0100
***************
*** 24,40 ****
  use Carp qw( carp confess croak );
  use Clone;
  use Data::Dumper;
- use FindBin;
  use GD::Image;
  use Math::VecStat qw(min max);
  use Params::Validate qw(:all);
  use List::MoreUtils qw(uniq);
  use Regexp::Common qw(number);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration;
  use Circos::Constants;
  use Circos::Colors;
--- 24,35 ----
diff -crB circos-0.69-6/lib/Circos/Ideogram.pm circos-0.69-6-new/lib/Circos/Ideogram.pm
*** circos-0.69-6/lib/Circos/Ideogram.pm	2015-11-17 01:18:53.000000000 +0100
--- circos-0.69-6-new/lib/Circos/Ideogram.pm	2018-01-12 10:13:22.045864798 +0100
***************
*** 40,46 ****

  use Carp qw( carp confess croak );
  use Cwd;
- use FindBin;
  use File::Spec::Functions;
  use Math::Round;
  use Math::VecStat qw(max);
--- 40,45 ----
***************
*** 50,59 ****

  use POSIX qw(floor ceil);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration;
  use Circos::Constants;
  use Circos::Debug;
--- 49,54 ----
diff -crB circos-0.69-6/lib/Circos/Image.pm circos-0.69-6-new/lib/Circos/Image.pm
*** circos-0.69-6/lib/Circos/Image.pm	2014-05-12 18:20:19.000000000 +0200
--- circos-0.69-6-new/lib/Circos/Image.pm	2018-01-12 10:13:31.094024696 +0100
***************
*** 45,58 ****
  );

  use Carp qw( carp confess croak );
- use FindBin;
  use GD::Image;
  use Params::Validate qw(:all);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration;
  use Circos::Colors;
  use Circos::Constants;
--- 45,53 ----
diff -crB circos-0.69-6/lib/Circos/IO.pm circos-0.69-6-new/lib/Circos/IO.pm
*** circos-0.69-6/lib/Circos/IO.pm	2015-12-03 05:51:11.000000000 +0100
--- circos-0.69-6-new/lib/Circos/IO.pm	2018-01-12 10:13:41.686210640 +0100
***************
*** 39,45 ****
  use Carp qw( carp confess croak );
  use Storable qw(dclone);
  use Cwd;
- use FindBin;
  use Data::Dumper;
  use File::Spec::Functions;
  use Math::Round;
--- 39,44 ----
***************
*** 49,58 ****

  use POSIX qw(floor ceil);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Constants;
  use Circos::Colors;
  use Circos::Configuration;
--- 48,53 ----
diff -crB circos-0.69-6/lib/Circos/Karyotype.pm circos-0.69-6-new/lib/Circos/Karyotype.pm
*** circos-0.69-6/lib/Circos/Karyotype.pm	2014-09-09 00:15:58.000000000 +0200
--- circos-0.69-6-new/lib/Circos/Karyotype.pm	2018-01-12 10:13:53.318413330 +0100
***************
*** 38,44 ****

  use Carp qw( carp confess croak );
  use Cwd;
- use FindBin;
  use Math::Round;
  use Math::VecStat qw(max);
  use Params::Validate qw(:all);
--- 38,43 ----
***************
*** 48,57 ****
  #use Regexp::Common qw(number);
  #use POSIX qw(floor ceil);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration;
  use Circos::Constants;
  use Circos::Debug;
--- 47,52 ----
diff -crB circos-0.69-6/lib/Circos/PNG.pm circos-0.69-6-new/lib/Circos/PNG.pm
*** circos-0.69-6/lib/Circos/PNG.pm	2014-09-17 05:33:06.000000000 +0200
--- circos-0.69-6-new/lib/Circos/PNG.pm	2018-01-12 10:14:31.011059637 +0100
***************
*** 37,51 ****
  our @EXPORT = qw();

  use Carp qw( carp confess croak );
- use FindBin;
  use GD;
  use Math::VecStat qw(min max);
  use Params::Validate qw(:all);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration;
  use Circos::Colors;
  use Circos::Constants;
--- 37,46 ----
diff -crB circos-0.69-6/lib/Circos/Rule.pm circos-0.69-6-new/lib/Circos/Rule.pm
*** circos-0.69-6/lib/Circos/Rule.pm	2014-10-02 01:14:25.000000000 +0200
--- circos-0.69-6-new/lib/Circos/Rule.pm	2018-01-12 10:14:38.195181067 +0100
***************
*** 38,51 ****

  use Carp qw( carp confess croak );
  use Data::Dumper;
- use FindBin;
  use GD::Image;
  use Params::Validate qw(:all);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration; # qw(%CONF $DIMS);
  use Circos::Constants;
  use Circos::DataPoint;
--- 38,46 ----
diff -crB circos-0.69-6/lib/Circos/SVG.pm circos-0.69-6-new/lib/Circos/SVG.pm
*** circos-0.69-6/lib/Circos/SVG.pm	2015-11-30 23:23:52.000000000 +0100
--- circos-0.69-6-new/lib/Circos/SVG.pm	2018-01-12 10:14:47.803342631 +0100
***************
*** 26,39 ****
  							 );

  use Carp qw( carp confess croak );
- use FindBin;
  use GD::Image;
  use Params::Validate qw(:all);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration;
  use Circos::Colors;
  use Circos::Constants;
--- 26,34 ----
diff -crB circos-0.69-6/lib/Circos/Text.pm circos-0.69-6-new/lib/Circos/Text.pm
*** circos-0.69-6/lib/Circos/Text.pm	2014-05-12 18:20:19.000000000 +0200
--- circos-0.69-6-new/lib/Circos/Text.pm	2018-01-12 10:14:57.083497772 +0100
***************
*** 42,55 ****
  );

  use Carp qw( carp confess croak );
- use FindBin;
  use GD::Image;
  use Params::Validate qw(:all);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration; # qw(%CONF $DIMS);
  use Circos::Constants;
  use Circos::Colors;
--- 42,50 ----
diff -crB circos-0.69-6/lib/Circos/Track/Highlight.pm circos-0.69-6-new/lib/Circos/Track/Highlight.pm
*** circos-0.69-6/lib/Circos/Track/Highlight.pm	2014-10-01 00:43:27.000000000 +0200
--- circos-0.69-6-new/lib/Circos/Track/Highlight.pm	2018-01-12 10:15:06.795659206 +0100
***************
*** 37,50 ****
  our @EXPORT = qw();

  use Carp qw( carp confess croak );
- use FindBin;
  use GD::Image;
  use Params::Validate qw(:all);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration; # qw(%CONF $DIMS);
  use Circos::Constants;
  #use Circos::Colors;
--- 37,45 ----
diff -crB circos-0.69-6/lib/Circos/Track/Link.pm circos-0.69-6-new/lib/Circos/Track/Link.pm
*** circos-0.69-6/lib/Circos/Track/Link.pm	2014-05-12 18:20:19.000000000 +0200
--- circos-0.69-6-new/lib/Circos/Track/Link.pm	2018-01-12 10:15:17.387834198 +0100
***************
*** 37,50 ****
  our @EXPORT = qw();

  use Carp qw( carp confess croak );
- use FindBin;
  use GD::Image;
  use Params::Validate qw(:all);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration; # qw(%CONF $DIMS);
  use Circos::Constants;
  #use Circos::Colors;
--- 37,45 ----
diff -crB circos-0.69-6/lib/Circos/Track.pm circos-0.69-6-new/lib/Circos/Track.pm
*** circos-0.69-6/lib/Circos/Track.pm	2014-09-16 05:31:46.000000000 +0200
--- circos-0.69-6-new/lib/Circos/Track.pm	2018-01-12 10:15:29.628035063 +0100
***************
*** 41,56 ****

  use Carp qw( carp confess croak );
  use Data::Dumper;
- use FindBin;
  use GD::Image;
  use List::MoreUtils qw(uniq);
  use Math::VecStat qw(min max);
  use Params::Validate qw(:all);
  use Regexp::Common;
  use Statistics::Basic qw(average stddev);
- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";

  use Circos::Configuration; # qw(%CONF $DIMS);
  use Circos::Constants;
--- 41,52 ----
diff -crB circos-0.69-6/lib/Circos/Unit.pm circos-0.69-6-new/lib/Circos/Unit.pm
*** circos-0.69-6/lib/Circos/Unit.pm	2014-05-12 18:20:19.000000000 +0200
--- circos-0.69-6-new/lib/Circos/Unit.pm	2018-01-12 10:15:37.892169871 +0100
***************
*** 46,60 ****
  );

  use Carp qw( carp confess croak );
- use FindBin;
  use Data::Dumper;
  use Params::Validate qw(:all);
  use Regexp::Common qw(number);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration qw(%CONF $DIMS);
  use Circos::Constants;
  use Circos::Debug;
--- 46,55 ----
diff -crB circos-0.69-6/lib/Circos/URL.pm circos-0.69-6-new/lib/Circos/URL.pm
*** circos-0.69-6/lib/Circos/URL.pm	2014-05-12 18:20:19.000000000 +0200
--- circos-0.69-6-new/lib/Circos/URL.pm	2018-01-12 10:15:46.092303006 +0100
***************
*** 39,52 ****
  );

  use Carp qw( carp confess croak );
- use FindBin;
  use GD;
  use Params::Validate qw(:all);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Configuration;
  #use Circos::Colors;
  use Circos::Constants;
--- 39,47 ----
diff -crB circos-0.69-6/lib/Circos/Utils.pm circos-0.69-6-new/lib/Circos/Utils.pm
*** circos-0.69-6/lib/Circos/Utils.pm	2014-10-01 21:36:19.000000000 +0200
--- circos-0.69-6-new/lib/Circos/Utils.pm	2018-01-12 10:16:11.576712858 +0100
***************
*** 105,114 ****

  use POSIX qw(floor ceil);

- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";
-
  use Circos::Constants;
  use Circos::Debug;
  use Circos::Error;
--- 105,110 ----
diff -crB circos-0.69-6/lib/Circos.pm circos-0.69-6-new/lib/Circos.pm
*** circos-0.69-6/lib/Circos.pm	2016-06-25 00:19:27.000000000 +0200
--- circos-0.69-6-new/lib/Circos.pm	2018-01-12 10:16:35.801097176 +0100
***************
*** 49,57 ****

  use strict;
  use warnings;
- use lib "$FindBin::RealBin";
- use lib "$FindBin::RealBin/../lib";
- use lib "$FindBin::RealBin/lib";

  BEGIN {
  	require Circos::Modules;
--- 49,54 ----


code:
Our llvm does not contain a single top-level library, so consult llvm-config
for the libraries that need to be linked against.

--- clamav-0.100.2/libclamav/c++/configure.ac	2018-09-19 14:29:07.000000000 -0500
+++ clamav-0.100.2/libclamav/c++/configure.ac	2018-10-06 21:45:09.377249158 -0500
@@ -105,7 +105,7 @@

     if test "x$llvm_linking" = "xdynamic"; then
         AC_SUBST(LLVMCONFIG_LDFLAGS, [`$llvmconfig --ldflags`])
-        AC_SUBST(LLVMCONFIG_LIBS, [-lLLVM-$llvmver])
+        AC_SUBST(LLVMCONFIG_LIBS, [`$llvmconfig --libs $llvmcomp`])
         AC_SUBST(LLVMCONFIG_LIBFILES, [])
     else
         if test $llvmver_test -ge 350; then


code:
From: Tobias Geerinckx-Rice <me@tobias.gr>
Date: Sun, 24 Feb 2019 15:50:37 +0100
Subject: gnu: clamav: Add support for system tomsfastmath.

Adjusted from the original for clamav 0.101.1:

From 756ff89526b5ffaa7a4f49b1bbecf2ecbd6f85f9 Mon Sep 17 00:00:00 2001
From: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Date: Wed, 11 Mar 2015 20:03:15 +0100
Subject: add support for system tomsfastmath

Patch-Name: add-support-for-system-tomsfastmath.patch
---
 configure.ac                           |    2 ++
 libclamav/Makefile.am                  |   10 ++++++++--
 libclamav/bignum.h                     |    6 +++++-
 libclamav/xdp.c                        |    2 +-
 m4/reorganization/libs/tomsfastmath.m4 |   12 ++++++++++++
 5 files changed, 28 insertions(+), 4 deletions(-)
 create mode 100644 m4/reorganization/libs/tomsfastmath.m4

--- a/configure.ac	1970-01-01 01:00:00.000000000 +0100
+++ b/configure.ac	2019-02-24 15:47:14.076992864 +0100
@@ -89,6 +89,7 @@
 m4_include([m4/reorganization/libs/json.m4])
 m4_include([m4/reorganization/libs/pcre.m4])
 m4_include([m4/reorganization/libs/libmspack.m4])
+m4_include([m4/reorganization/libs/tomsfastmath.m4])

 if test "x$use_internal_mspack" = "xno"; then
     mspack_msg="External, $LIBMSPACK_CFLAGS $LIBMSPACK_LIBS"
@@ -297,6 +298,7 @@
 fi
 CL_MSG_STATUS([yara        ],[$enable_yara],[$enable_yara])
 CL_MSG_STATUS([fts         ],[yes],[$lfs_fts_msg])
+CL_MSG_STATUS([tomsfastmath],[yes],[$tomsfastmath_msg])

 # Yep, downgrading the compiler avoids the bug too:
diff -Naur clamav-0.101.1/libclamav/bignum.h clamav-0.101.1b/libclamav/bignum.h
--- a/libclamav/bignum.h	1970-01-01 01:00:00.000000000 +0100
+++ b/libclamav/bignum.h	2019-02-24 15:46:36.216998323 +0100
@@ -1,9 +1,13 @@
 #ifndef BIGNUM_H_
 #define BIGNUM_H_

+#if HAVE_SYSTEM_TOMSFASTMATH
+#include <tfm.h>
+#else
 #define TFM_CHECK
-
 #include "bignum_fast.h"
+#endif
+
 typedef fp_int mp_int;
 #define mp_cmp fp_cmp
 #define mp_toradix_n(a,b,c,d) fp_toradix_n(a,b,c,d)
diff -Naur clamav-0.101.1/libclamav/Makefile.am clamav-0.101.1b/libclamav/Makefile.am
--- a/libclamav/Makefile.am	1970-01-01 01:00:00.000000000 +0100
+++ b/libclamav/Makefile.am	2019-02-24 15:46:36.216998323 +0100
@@ -597,8 +597,10 @@
 	yara_clam.h
 endif

-libclamav_la_SOURCES += bignum.h\
-	bignum_fast.h\
+libclamav_la_SOURCES += bignum.h
+
+if !SYSTEM_TOMSFASTMATH
+libclamav_la_SOURCES += bignum_fast.h\
         tomsfastmath/addsub/fp_add.c\
         tomsfastmath/addsub/fp_add_d.c\
         tomsfastmath/addsub/fp_addmod.c\
@@ -680,6 +682,10 @@
         tomsfastmath/sqr/fp_sqr_comba_generic.c\
         tomsfastmath/sqr/fp_sqr_comba_small_set.c\
 	tomsfastmath/sqr/fp_sqrmod.c
+else
+libclamav_la_CFLAGS += $(TOMSFASTMATH_CFLAGS)
+libclamav_la_LIBADD += $(TOMSFASTMATH_LIBS)
+endif

 .PHONY: version.h.tmp
 version.c: version.h
diff -Naur clamav-0.101.1/libclamav/xdp.c clamav-0.101.1b/libclamav/xdp.c
--- a/libclamav/xdp.c	1970-01-01 01:00:00.000000000 +0100
+++ b/libclamav/xdp.c	2019-02-24 15:46:36.216998323 +0100
@@ -52,7 +52,7 @@
 #include "scanners.h"
 #include "conv.h"
 #include "xdp.h"
-#include "bignum_fast.h"
+#include "bignum.h"
 #include "filetypes.h"

 static char *dump_xdp(cli_ctx *ctx, const char *start, size_t sz);
diff -Naur clamav-0.101.1/m4/reorganization/libs/tomsfastmath.m4 clamav-0.101.1b/m4/reorganization/libs/tomsfastmath.m4
--- a/m4/reorganization/libs/tomsfastmath.m4	1970-01-01 01:00:00.000000000 +0100
+++ b/m4/reorganization/libs/tomsfastmath.m4	2019-02-24 15:46:36.216998323 +0100
@@ -0,0 +1,12 @@
+dnl Check for system tomsfastmath
+PKG_CHECK_MODULES([TOMSFASTMATH], [tomsfastmath], [have_system_tomsfastmath=yes], [have_system_tomsfastmath=no])
+
+AM_CONDITIONAL([SYSTEM_TOMSFASTMATH], [test "x$have_system_tomsfastmath" = "xyes"])
+
+if test "x$have_system_tomsfastmath" = "xyes"; then
+    AC_DEFINE([HAVE_SYSTEM_TOMSFASTMATH], [1], [link against system-wide tomsfastmath library])
+    tomsfastmath_msg="External, $TOMSFASTMATH_CFLAGS $TOMSFASTMATH_LIBS"
+else
+    AC_DEFINE([HAVE_SYSTEM_TOMSFASTMATH], [0], [don't link against system-wide tomsfastmath library])
+    tomsfastmath_msg="Internal"
+fi


code:
Clang attempts to guess file names based on the OS and distro (yes!),
but unfortunately, that doesn't work for us.

This patch makes it easy to insert libc's $libdir so that Clang passes the
correct absolute file name of crt1.o etc. to 'ld'.  It also disables all
the distro-specific stuff and removes the hard-coded FHS directory names
to make sure Clang also works on non-Guix systems.

diff --git a/lib/Driver/ToolChains/Linux.cpp b/lib/Driver/ToolChains/Linux.cpp
index bff1ab10..79e1477e 100644
--- a/lib/Driver/ToolChains/Linux.cpp
+++ b/lib/Driver/ToolChains/Linux.cpp
@@ -240,6 +240,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
                          .str());
   }

+// Comment out the distro-specific tweaks so that they don't bite when
+// using Guix on a foreign distro.
+#if 0
   Distro Distro(D.getVFS(), Triple);

   if (Distro.IsAlpineLinux() || Triple.isAndroid()) {
@@ -306,6 +309,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)

   if (IsAndroid || Distro.IsOpenSUSE())
     ExtraOpts.push_back("--enable-new-dtags");
+#endif	// Guix

   // The selection of paths to try here is designed to match the patterns which
   // the GCC driver itself uses, as this is part of the GCC-compatible driver.
@@ -363,7 +367,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
     // the cross. Note that GCC does include some of these directories in some
     // configurations but this seems somewhere between questionable and simply
     // a bug.
-    if (StringRef(LibPath).startswith(SysRoot)) {
+    if (0) {
       addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths);
       addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths);
     }
@@ -382,6 +386,8 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths);
   addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths);

+// This requires the commented distro tweaks above.
+#if 0
   if (IsAndroid) {
     // Android sysroots contain a library directory for each supported OS
     // version as well as some unversioned libraries in the usual multiarch
@@ -410,10 +416,15 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
     addPathIfExists(D, SysRoot + "/" + OSLibDir + "/" + ABIName, Paths);
     addPathIfExists(D, SysRoot + "/usr/" + OSLibDir + "/" + ABIName, Paths);
   }
+#endif

   // Try walking via the GCC triple path in case of biarch or multiarch GCC
   // installations with strange symlinks.
   if (GCCInstallation.isValid()) {
+
+// The following code would end up adding things like
+// "/usr/lib/x86_64-unknown-linux-gnu/../../lib64" to the search path.
+#if 0
     addPathIfExists(D,
                     SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() +
                         "/../../" + OSLibDir,
@@ -426,6 +437,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
                              BiarchSibling.gccSuffix(),
                       Paths);
     }
+#endif

     // See comments above on the multilib variant for details of why this is
     // included even from outside the sysroot.
@@ -450,8 +462,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   if (StringRef(D.Dir).startswith(SysRoot))
     addPathIfExists(D, D.Dir + "/../lib", Paths);

-  addPathIfExists(D, SysRoot + "/lib", Paths);
-  addPathIfExists(D, SysRoot + "/usr/lib", Paths);
+  // Add libc's lib/ directory to the search path, so that crt1.o, crti.o,
+  // and friends can be found.
+  addPathIfExists(D, "@GLIBC_LIBDIR@", Paths);
 }

 ToolChain::CXXStdlibType Linux::GetDefaultCXXStdlibType() const {


code:
Clang attempts to guess file names based on the OS and distro (yes!),
but unfortunately, that doesn't work for us.

This patch makes it easy to insert libc's $libdir so that Clang passes the
correct absolute file name of crt1.o etc. to 'ld'.  It also disables all
the distro-specific stuff and removes the hard-coded FHS directory names
to make sure Clang also works on non-GuixSD systems.

--- cfe-3.6.0.src/lib/Driver/ToolChains.cpp	2015-02-18 22:03:07.000000000 +0100
+++ cfe-3.6.0.src/lib/Driver/ToolChains.cpp	2015-06-19 16:37:20.459701044 +0200
@@ -2931,6 +2931,9 @@ Linux::Linux(const Driver &D, const llvm

   Linker = GetLinkerPath();

+  // Comment out the distro-specific tweaks so that they don't bite when
+  // using Guix on a foreign distro.
+#if 0
   Distro Distro = DetectDistro(Arch);

   if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) {
@@ -2973,6 +2976,7 @@ Linux::Linux(const Driver &D, const llvm

   if (IsOpenSUSE(Distro))
     ExtraOpts.push_back("--enable-new-dtags");
+#endif

   // The selection of paths to try here is designed to match the patterns which
   // the GCC driver itself uses, as this is part of the GCC-compatible driver.
@@ -3043,14 +3047,12 @@ Linux::Linux(const Driver &D, const llvm
     addPathIfExists(D.Dir + "/../" + OSLibDir, Paths);
   }

-  addPathIfExists(SysRoot + "/lib/" + MultiarchTriple, Paths);
-  addPathIfExists(SysRoot + "/lib/../" + OSLibDir, Paths);
-  addPathIfExists(SysRoot + "/usr/lib/" + MultiarchTriple, Paths);
-  addPathIfExists(SysRoot + "/usr/lib/../" + OSLibDir, Paths);
-
   // Try walking via the GCC triple path in case of biarch or multiarch GCC
   // installations with strange symlinks.
   if (GCCInstallation.isValid()) {
+    // The following code would end up adding things like
+    // "/usr/lib/x86_64-unknown-linux-gnu/../../lib64" to the search path.
+#if 0
     addPathIfExists(SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() +
                     "/../../" + OSLibDir, Paths);

@@ -3060,6 +3062,7 @@ Linux::Linux(const Driver &D, const llvm
       addPathIfExists(GCCInstallation.getInstallPath() +
                       BiarchSibling.gccSuffix(), Paths);
     }
+#endif

     // See comments above on the multilib variant for details of why this is
     // included even from outside the sysroot.
@@ -3083,8 +3086,9 @@ Linux::Linux(const Driver &D, const llvm
   if (StringRef(D.Dir).startswith(SysRoot))
     addPathIfExists(D.Dir + "/../lib", Paths);

-  addPathIfExists(SysRoot + "/lib", Paths);
-  addPathIfExists(SysRoot + "/usr/lib", Paths);
+  // Add libc's lib/ directory to the search path, so that crt1.o, crti.o,
+  // and friends can be found.
+  addPathIfExists("@GLIBC_LIBDIR@", Paths);
 }

 bool Linux::HasNativeLLVMSupport() const {


code:
From d9d97cac3702b99a00cd113de98c41eb535d47ed Mon Sep 17 00:00:00 2001
From: Efraim Flashner <efraim@flashner.co.il>
Date: Sun, 14 Oct 2018 12:11:30 +0300
Subject: [PATCH] patch modified from the gcc patch series, also dealing with
 ustat.

---
 .../sanitizer_platform_limits_posix.cc            | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
index 29fea6e..570b9a5 100644
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -129,7 +129,6 @@
 #include <sys/statvfs.h>
 #include <sys/timex.h>
 #include <sys/user.h>
-#include <sys/ustat.h>
 #include <linux/cyclades.h>
 #include <linux/if_eql.h>
 #include <linux/if_plip.h>
@@ -222,7 +221,19 @@ namespace __sanitizer {
 #endif  // SANITIZER_LINUX || SANITIZER_FREEBSD

 #if SANITIZER_LINUX && !SANITIZER_ANDROID
-  unsigned struct_ustat_sz = sizeof(struct ustat);
+  // Use pre-computed size of struct ustat to avoid <sys/ustat.h> which
+  // has been removed from glibc 2.28.
+#if defined(__aarch64__) || defined(__s390x__) || defined (__mips64) \
+  || defined(__powerpc64__) || defined(__arch64__) || defined(__sparcv9) \
+  || defined(__x86_64__)
+#define SIZEOF_STRUCT_USTAT 32
+#elif defined(__arm__) || defined(__i386__) || defined(__mips__) \
+  || defined(__powerpc__) || defined(__s390__)
+#define SIZEOF_STRUCT_USTAT 20
+#else
+#error Unknown size of struct ustat
+#endif
+  unsigned struct_ustat_sz = SIZEOF_STRUCT_USTAT;
   unsigned struct_rlimit64_sz = sizeof(struct rlimit64);
   unsigned struct_statvfs64_sz = sizeof(struct statvfs64);
 #endif  // SANITIZER_LINUX && !SANITIZER_ANDROID
--
2.19.1


code:
Clang attempts to guess file names based on the OS and distro (yes!),
but unfortunately, that doesn't work for us.

This patch makes it easy to insert libc's $libdir so that Clang passes the
correct absolute file name of crt1.o etc. to 'ld'.  It also disables all
the distro-specific stuff and removes the hard-coded FHS directory names
to make sure Clang also works on non-GuixSD systems.

This patch makes slight adjustments over "clang-libc-search-path.patch" for
changes in clang 3.8.

--- cfe-3.8.0.src/lib/Driver/ToolChains.cpp
+++ cfe-3.8.0.src/lib/Driver/ToolChains.cpp
@@ -3661,6 +3661,9 @@
                          GCCInstallation.getTriple().str() + "/bin")
                        .str());

+  // Comment out the distro-specific tweaks so that they don't bite when
+  // using Guix on a foreign distro.
+#if 0
   Distro Distro = DetectDistro(D, Arch);

   if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) {
@@ -3702,6 +3705,7 @@

   if (IsOpenSUSE(Distro))
     ExtraOpts.push_back("--enable-new-dtags");
+#endif

   // The selection of paths to try here is designed to match the patterns which
   // the GCC driver itself uses, as this is part of the GCC-compatible driver.
@@ -3771,14 +3775,12 @@
     addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
   }

-  addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths);
-  addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths);
-  addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths);
-  addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths);
-
   // Try walking via the GCC triple path in case of biarch or multiarch GCC
   // installations with strange symlinks.
   if (GCCInstallation.isValid()) {
+    // The following code would end up adding things like
+    // "/usr/lib/x86_64-unknown-linux-gnu/../../lib64" to the search path.
+#if 0
     addPathIfExists(D,
                     SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() +
                         "/../../" + OSLibDir,
@@ -3791,6 +3793,7 @@
                              BiarchSibling.gccSuffix(),
                       Paths);
     }
+#endif

     // See comments above on the multilib variant for details of why this is
     // included even from outside the sysroot.
@@ -3815,8 +3818,9 @@
   if (StringRef(D.Dir).startswith(SysRoot))
     addPathIfExists(D, D.Dir + "/../lib", Paths);

-  addPathIfExists(D, SysRoot + "/lib", Paths);
-  addPathIfExists(D, SysRoot + "/usr/lib", Paths);
+  // Add libc's lib/ directory to the search path, so that crt1.o, crti.o,
+  // and friends can be found.
+  addPathIfExists(D, "@GLIBC_LIBDIR@", Paths);
 }

 bool Linux::HasNativeLLVMSupport() const { return true; }


code:
Clang attempts to guess file names based on the OS and distro (yes!),
but unfortunately, that doesn't work for us.

This patch makes it easy to insert libc's $libdir so that Clang passes the
correct absolute file name of crt1.o etc. to 'ld'.  It also disables all
the distro-specific stuff and removes the hard-coded FHS directory names
to make sure Clang also works on non-GuixSD systems.

--- cfe-6.0.0.src/lib/Driver/ToolChains/Linux.cpp
+++ cfe-6.0.0.src/lib/Driver/ToolChains/Linux.cpp
@@ -207,7 +207,9 @@
   PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
                          GCCInstallation.getTriple().str() + "/bin")
                        .str());
-
+  // Comment out the distro-specific tweaks so that they don't bite when
+  // using Guix on a foreign distro.
+#if 0
   Distro Distro(D.getVFS());

   if (Distro.IsAlpineLinux()) {
@@ -255,6 +257,7 @@

   if (IsAndroid || Distro.IsOpenSUSE())
     ExtraOpts.push_back("--enable-new-dtags");
+#endif

   // The selection of paths to try here is designed to match the patterns which
   // the GCC driver itself uses, as this is part of the GCC-compatible driver.
@@ -329,14 +332,12 @@
     addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
   }

-  addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths);
-  addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths);
-  addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths);
-  addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths);
-
   // Try walking via the GCC triple path in case of biarch or multiarch GCC
   // installations with strange symlinks.
   if (GCCInstallation.isValid()) {
+    // The following code would end up adding things like
+    // "/usr/lib/x86_64-unknown-linux-gnu/../../lib64" to the search path.
+#if 0
     addPathIfExists(D,
                     SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() +
                         "/../../" + OSLibDir,
@@ -349,6 +350,7 @@
                              BiarchSibling.gccSuffix(),
                       Paths);
     }
+#endif

     // See comments above on the multilib variant for details of why this is
     // included even from outside the sysroot.
@@ -373,8 +375,9 @@
   if (StringRef(D.Dir).startswith(SysRoot))
     addPathIfExists(D, D.Dir + "/../lib", Paths);

-  addPathIfExists(D, SysRoot + "/lib", Paths);
-  addPathIfExists(D, SysRoot + "/usr/lib", Paths);
+  // Add libc's lib/ directory to the search path, so that crt1.o, crti.o,
+  // and friends can be found.
+  addPathIfExists(D, "@GLIBC_LIBDIR@", Paths);
 }

 bool Linux::HasNativeLLVMSupport() const { return true; }


code:
Clang attempts to guess file names based on the OS and distro (yes!),
but unfortunately, that doesn't work for us.

This patch makes it easy to insert libc's $libdir so that Clang passes the
correct absolute file name of crt1.o etc. to 'ld'.  It also disables all
the distro-specific stuff and removes the hard-coded FHS directory names
to make sure Clang also works on non-GuixSD systems.

--- a/lib/Driver/ToolChains/Linux.cpp
+++ b/lib/Driver/ToolChains/Linux.cpp
@@ -225,7 +225,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
                          GCCInstallation.getTriple().str() + "/bin")
                        .str());
-
+  // Comment out the distro-specific tweaks so that they don't bite when
+  // using Guix on a foreign distro.
+#if 0
   Distro Distro(D.getVFS());

   if (Distro.IsAlpineLinux()) {
@@ -284,6 +286,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)

   if (IsAndroid || Distro.IsOpenSUSE())
     ExtraOpts.push_back("--enable-new-dtags");
+#endif

   // The selection of paths to try here is designed to match the patterns which
   // the GCC driver itself uses, as this is part of the GCC-compatible driver.
@@ -342,7 +345,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
     // the cross. Note that GCC does include some of these directories in some
     // configurations but this seems somewhere between questionable and simply
     // a bug.
-    if (StringRef(LibPath).startswith(SysRoot)) {
+    if (0) {
       addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths);
       addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths);
     }
@@ -361,6 +364,8 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths);
   addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths);

+  // This requires the commented distro tweaks above.
+#if 0
   if (IsAndroid) {
     // Android sysroots contain a library directory for each supported OS
     // version as well as some unversioned libraries in the usual multiarch
@@ -389,10 +394,14 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
     addPathIfExists(D, SysRoot + "/" + OSLibDir + "/" + ABIName, Paths);
     addPathIfExists(D, SysRoot + "/usr/" + OSLibDir + "/" + ABIName, Paths);
   }
+#endif

   // Try walking via the GCC triple path in case of biarch or multiarch GCC
   // installations with strange symlinks.
   if (GCCInstallation.isValid()) {
+    // The following code would end up adding things like
+    // "/usr/lib/x86_64-unknown-linux-gnu/../../lib64" to the search path.
+#if 0
     addPathIfExists(D,
                     SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() +
                         "/../../" + OSLibDir,
@@ -405,6 +414,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
                              BiarchSibling.gccSuffix(),
                       Paths);
     }
+#endif

     // See comments above on the multilib variant for details of why this is
     // included even from outside the sysroot.
@@ -429,8 +439,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   if (StringRef(D.Dir).startswith(SysRoot))
     addPathIfExists(D, D.Dir + "/../lib", Paths);

-  addPathIfExists(D, SysRoot + "/lib", Paths);
-  addPathIfExists(D, SysRoot + "/usr/lib", Paths);
+  // Add libc's lib/ directory to the search path, so that crt1.o, crti.o,
+  // and friends can be found.
+  addPathIfExists(D, "@GLIBC_LIBDIR@", Paths);
 }

 bool Linux::HasNativeLLVMSupport() const { return true; }


code:
Clang attempts to guess file names based on the OS and distro (yes!),
but unfortunately, that doesn't work for us.

This patch makes it easy to insert libc's $libdir so that Clang passes the
correct absolute file name of crt1.o etc. to 'ld'.  It also disables all
the distro-specific stuff and removes the hard-coded FHS directory names
to make sure Clang also works on non-GuixSD systems.

diff --git a/lib/Driver/ToolChains/Linux.cpp b/lib/Driver/ToolChains/Linux.cpp
--- a/lib/Driver/ToolChains/Linux.cpp
+++ b/lib/Driver/ToolChains/Linux.cpp
@@ -240,6 +240,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
                          .str());
   }

+// Comment out the distro-specific tweaks so that they don't bite when
+// using Guix on a foreign distro.
+#if 0
   Distro Distro(D.getVFS());

   if (Distro.IsAlpineLinux() || Triple.isAndroid()) {
@@ -306,6 +309,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)

   if (IsAndroid || Distro.IsOpenSUSE())
     ExtraOpts.push_back("--enable-new-dtags");
+#endif

   // The selection of paths to try here is designed to match the patterns which
   // the GCC driver itself uses, as this is part of the GCC-compatible driver.
@@ -363,7 +367,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
     // the cross. Note that GCC does include some of these directories in some
     // configurations but this seems somewhere between questionable and simply
     // a bug.
-    if (StringRef(LibPath).startswith(SysRoot)) {
+    if (0) {
       addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths);
       addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths);
     }
@@ -382,6 +386,8 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths);
   addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths);

+// This requires the commented distro tweaks above.
+#if 0
   if (IsAndroid) {
     // Android sysroots contain a library directory for each supported OS
     // version as well as some unversioned libraries in the usual multiarch
@@ -410,10 +416,15 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
     addPathIfExists(D, SysRoot + "/" + OSLibDir + "/" + ABIName, Paths);
     addPathIfExists(D, SysRoot + "/usr/" + OSLibDir + "/" + ABIName, Paths);
   }
+#endif

   // Try walking via the GCC triple path in case of biarch or multiarch GCC
   // installations with strange symlinks.
   if (GCCInstallation.isValid()) {
+
+// The following code would end up adding things like
+// "/usr/lib/x86_64-unknown-linux-gnu/../../lib64" to the search path.
+#if 0
     addPathIfExists(D,
                     SysRoot + "/usr/lib/" + GCCInstallation.getTriple().str() +
                         "/../../" + OSLibDir,
@@ -426,6 +437,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
                              BiarchSibling.gccSuffix(),
                       Paths);
     }
+#endif

     // See comments above on the multilib variant for details of why this is
     // included even from outside the sysroot.
@@ -450,8 +462,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
   if (StringRef(D.Dir).startswith(SysRoot))
     addPathIfExists(D, D.Dir + "/../lib", Paths);

-  addPathIfExists(D, SysRoot + "/lib", Paths);
-  addPathIfExists(D, SysRoot + "/usr/lib", Paths);
+  // Add libc's lib/ directory to the search path, so that crt1.o, crti.o,
+  // and friends can be found.
+  addPathIfExists(D, "@GLIBC_LIBDIR@", Paths);
 }

 ToolChain::CXXStdlibType Linux::GetDefaultCXXStdlibType() const {


code:
Adjust libsanitizer to ABI change in glibc 2.31.

Adapted to 3.x from this upstream commit:
https://github.com/llvm/llvm-project/commit/947f9692440836dcb8d88b74b69dd379d85974ce

--- a/lib/sanitizer_common/saniniitizer_platform_limits_posix.h.orig	2020-08-11 16:01:32.494882282 +0200 #
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.h	2020-08-11 16:32:49.711383554 +0200
@@ -176,8 +176,7 @@
     unsigned long __unused1;
     unsigned long __unused2;
 #else
-    unsigned short mode;
-    unsigned short __pad1;
+    unsigned int mode;
     unsigned short __seq;
     unsigned short __pad2;
 #if defined(__x86_64__) && !defined(_LP64)
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc	2020-08-11 16:01:07.926821829 +0200
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc.orig	2020-08-11 16:01:03.698811421 +0200
@@ -1056,7 +1056,9 @@
 CHECK_SIZE_AND_OFFSET(ipc_perm, gid);
 CHECK_SIZE_AND_OFFSET(ipc_perm, cuid);
 CHECK_SIZE_AND_OFFSET(ipc_perm, cgid);
+#if !SANITIZER_LINUX || __GLIBC_PREREQ (2, 31)
 CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
+#endif

 CHECK_TYPE_SIZE(shmid_ds);
 CHECK_SIZE_AND_OFFSET(shmid_ds, shm_perm);


code:
Adjust libsanitizer to ABI change in glibc 2.31.

Adapted to 3.x from this upstream commit:
https://github.com/llvm/llvm-project/commit/947f9692440836dcb8d88b74b69dd379d85974ce

diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -1130,8 +1130,9 @@ CHECK_SIZE_AND_OFFSET(ipc_perm, cgid);
 #ifndef __GLIBC_PREREQ
 #define __GLIBC_PREREQ(x, y) 0
 #endif
-#if !defined(__aarch64__) || !SANITIZER_LINUX || __GLIBC_PREREQ (2, 21)
-/* On aarch64 glibc 2.20 and earlier provided incorrect mode field.  */
+#if !SANITIZER_LINUX || __GLIBC_PREREQ (2, 31)
+/* glibc 2.30 and earlier provided 16-bit mode field instead of 32-bit
+   on many architectures.  */
 CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
 #endif

diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/lib/sanitizer_common/sanitizer_platform_limits_posix.h
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -188,17 +188,16 @@ namespace __sanitizer {
     unsigned __seq;
     u64 __unused1;
     u64 __unused2;
-#elif defined(__mips__) || defined(__aarch64__)
-    unsigned int mode;
-    unsigned short __seq;
-    unsigned short __pad1;
-    unsigned long __unused1;
-    unsigned long __unused2;
+#elif defined(__sparc__)
+  unsigned mode;
+  unsigned short __pad2;
+  unsigned short __seq;
+  unsigned long long __unused1;
+  unsigned long long __unused2;
 #else
-    unsigned short mode;
-    unsigned short __pad1;
-    unsigned short __seq;
-    unsigned short __pad2;
+  unsigned int mode;
+  unsigned short __seq;
+  unsigned short __pad2;
 #if defined(__x86_64__) && !defined(_LP64)
     u64 __unused1;
     u64 __unused2;


code:
Adjust libsanitizer to ABI change in glibc 2.31.

Adapted to 3.x from this upstream commit:
https://github.com/llvm/llvm-project/commit/947f9692440836dcb8d88b74b69dd379d85974ce

diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -1139,8 +1139,9 @@ CHECK_SIZE_AND_OFFSET(ipc_perm, uid);
 CHECK_SIZE_AND_OFFSET(ipc_perm, gid);
 CHECK_SIZE_AND_OFFSET(ipc_perm, cuid);
 CHECK_SIZE_AND_OFFSET(ipc_perm, cgid);
-#if !defined(__aarch64__) || !SANITIZER_LINUX || __GLIBC_PREREQ (2, 21)
-/* On aarch64 glibc 2.20 and earlier provided incorrect mode field.  */
+#if !SANITIZER_LINUX || __GLIBC_PREREQ (2, 31)
+/* glibc 2.30 and earlier provided 16-bit mode field instead of 32-bit
+   on many architectures.  */
 CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
 #endif

diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -194,17 +194,16 @@ namespace __sanitizer {
     unsigned __seq;
     u64 __unused1;
     u64 __unused2;
-#elif defined(__mips__) || defined(__aarch64__) || defined(__s390x__)
-    unsigned int mode;
-    unsigned short __seq;
-    unsigned short __pad1;
-    unsigned long __unused1;
-    unsigned long __unused2;
+#elif defined(__sparc__)
+  unsigned mode;
+  unsigned short __pad2;
+  unsigned short __seq;
+  unsigned long long __unused1;
+  unsigned long long __unused2;
 #else
-    unsigned short mode;
-    unsigned short __pad1;
-    unsigned short __seq;
-    unsigned short __pad2;
+  unsigned int mode;
+  unsigned short __seq;
+  unsigned short __pad2;
 #if defined(__x86_64__) && !defined(_LP64)
     u64 __unused1;
     u64 __unused2;