code:
https://src.fedoraproject.org/cgit/rpms/freeimage.git/tree/FreeImage_unbundle.patch

diff -rupN FreeImage/genfipsrclist.sh FreeImage-new/genfipsrclist.sh
--- FreeImage/genfipsrclist.sh	2015-02-20 10:52:16.000000000 +0100
+++ FreeImage-new/genfipsrclist.sh	2015-09-05 02:13:52.041353305 +0200
@@ -1,6 +1,6 @@
 #!/bin/sh

-DIRLIST=". Source Source/Metadata Source/FreeImageToolkit Source/LibJPEG Source/LibPNG Source/LibTIFF4 Source/ZLib Source/LibOpenJPEG Source/OpenEXR Source/OpenEXR/Half Source/OpenEXR/Iex Source/OpenEXR/IlmImf Source/OpenEXR/IlmThread Source/OpenEXR/Imath Source/OpenEXR/IexMath Source/LibRawLite Source/LibRawLite/dcraw Source/LibRawLite/internal Source/LibRawLite/libraw Source/LibRawLite/src Source/LibWebP Source/LibJXR Source/LibJXR/common/include Source/LibJXR/image/sys Source/LibJXR/jxrgluelib Wrapper/FreeImagePlus"
+DIRLIST="Wrapper/FreeImagePlus"

 echo "VER_MAJOR = 3" > fipMakefile.srcs
@@ -19,5 +19,6 @@ echo -n "INCLUDE =" >> fipMakefile.srcs
 for DIR in $DIRLIST; do
 	echo -n " -I$DIR" >> fipMakefile.srcs
 done
+echo -n " -IDist" >> fipMakefile.srcs
 echo >> fipMakefile.srcs

diff -rupN FreeImage/gensrclist.sh FreeImage-new/gensrclist.sh
--- FreeImage/gensrclist.sh	2015-02-20 10:51:50.000000000 +0100
+++ FreeImage-new/gensrclist.sh	2015-09-05 02:13:52.041353305 +0200
@@ -1,6 +1,6 @@
 #!/bin/sh

-DIRLIST=". Source Source/Metadata Source/FreeImageToolkit Source/LibJPEG Source/LibPNG Source/LibTIFF4 Source/ZLib Source/LibOpenJPEG Source/OpenEXR Source/OpenEXR/Half Source/OpenEXR/Iex Source/OpenEXR/IlmImf Source/OpenEXR/IlmThread Source/OpenEXR/Imath Source/OpenEXR/IexMath Source/LibRawLite Source/LibRawLite/dcraw Source/LibRawLite/internal Source/LibRawLite/libraw Source/LibRawLite/src Source/LibWebP Source/LibJXR Source/LibJXR/common/include Source/LibJXR/image/sys Source/LibJXR/jxrgluelib"
+DIRLIST=". Source Source/Metadata Source/FreeImageToolkit"

 echo "VER_MAJOR = 3" > Makefile.srcs
 echo "VER_MINOR = 18.0" >> Makefile.srcs
diff -rupN FreeImage/Makefile.fip FreeImage-new/Makefile.fip
--- FreeImage/Makefile.fip	2015-03-08 18:03:56.000000000 +0100
+++ FreeImage-new/Makefile.fip	2015-09-05 02:14:09.212684028 +0200
@@ -17,20 +17,22 @@ MODULES = $(SRCS:.c=.o)
 MODULES := $(MODULES:.cpp=.o)
 CFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden
 # OpenJPEG
-CFLAGS += -DOPJ_STATIC
+override CFLAGS += -DOPJ_STATIC
 # LibRaw
-CFLAGS += -DNO_LCMS
+override CFLAGS += -DNO_LCMS
 # LibJXR
-CFLAGS += -DDISABLE_PERF_MEASUREMENT -D__ANSI__
-CFLAGS += $(INCLUDE)
+override CFLAGS += -DDISABLE_PERF_MEASUREMENT -D__ANSI__
+override CFLAGS += $(INCLUDE)
 CXXFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden -Wno-ctor-dtor-privacy
 # LibJXR
-CXXFLAGS += -D__ANSI__
-CXXFLAGS += $(INCLUDE)
+override CXXFLAGS += -D__ANSI__
+override CXXFLAGS += $(INCLUDE)
+LDFLAGS ?=
+override LDFLAGS += -LDist -lfreeimage-$(VER_MAJOR).$(VER_MINOR)

 ifeq ($(shell sh -c 'uname -m 2>/dev/null || echo not'),x86_64)
-	CFLAGS += -fPIC
-	CXXFLAGS += -fPIC
+	override CFLAGS += -fPIC
+	override CXXFLAGS += -fPIC
 endif

 TARGET  = freeimageplus
@@ -68,7 +70,7 @@ $(STATICLIB): $(MODULES)
 	$(AR) r $@ $(MODULES)

 $(SHAREDLIB): $(MODULES)
-	$(CC) -s -shared -Wl,-soname,$(VERLIBNAME) $(LDFLAGS) -o $@ $(MODULES) $(LIBRARIES)
+	$(CC) -shared -Wl,-soname,$(VERLIBNAME) $(LDFLAGS) -o $@ $(MODULES) $(LIBRARIES)

 install:
 	install -d $(INCDIR) $(INSTALLDIR)
diff -rupN FreeImage/Makefile.gnu FreeImage-new/Makefile.gnu
--- FreeImage/Makefile.gnu	2015-03-08 18:04:00.000000000 +0100
+++ FreeImage-new/Makefile.gnu	2015-09-05 02:14:04.810599259 +0200
@@ -16,21 +16,11 @@ LIBRARIES = -lstdc++
 MODULES = $(SRCS:.c=.o)
 MODULES := $(MODULES:.cpp=.o)
 CFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden
-# OpenJPEG
-CFLAGS += -DOPJ_STATIC
-# LibRaw
-CFLAGS += -DNO_LCMS
-# LibJXR
-CFLAGS += -DDISABLE_PERF_MEASUREMENT -D__ANSI__
-CFLAGS += $(INCLUDE)
-CXXFLAGS ?= -O3 -fPIC -fexceptions -fvisibility=hidden -Wno-ctor-dtor-privacy
-# LibJXR
-CXXFLAGS += -D__ANSI__
-CXXFLAGS += $(INCLUDE)
+override CFLAGS += $(INCLUDE) -D__ANSI__ -I/usr/include/jxrlib $(shell pkg-config --cflags OpenEXR libopenjp2 libraw libpng libtiff-4 libwebp libwebpmux zlib)
+override LDFLAGS += -ljpeg -ljpegxr -ljxrglue $(shell pkg-config --libs OpenEXR libopenjp2 libraw libpng libtiff-4 libwebp libwebpmux zlib)

 ifeq ($(shell sh -c 'uname -m 2>/dev/null || echo not'),x86_64)
-	CFLAGS += -fPIC
-	CXXFLAGS += -fPIC
+	override CFLAGS += -fPIC
 endif

 TARGET  = freeimage
@@ -61,13 +51,13 @@ FreeImage: $(STATICLIB) $(SHAREDLIB)
 	$(CC) $(CFLAGS) -c $< -o $@

 .cpp.o:
-	$(CXX) $(CXXFLAGS) -c $< -o $@
+	$(CXX) $(CFLAGS) -c $< -o $@

 $(STATICLIB): $(MODULES)
 	$(AR) r $@ $(MODULES)

 $(SHAREDLIB): $(MODULES)
-	$(CC) -s -shared -Wl,-soname,$(VERLIBNAME) $(LDFLAGS) -o $@ $(MODULES) $(LIBRARIES)
+	$(CC) -shared -Wl,-soname,$(VERLIBNAME) $(LDFLAGS) -o $@ $(MODULES) $(LIBRARIES)

 install:
 	install -d $(INCDIR) $(INSTALLDIR)
diff -rupN FreeImage/Source/FreeImage/J2KHelper.cpp FreeImage-new/Source/FreeImage/J2KHelper.cpp
--- FreeImage/Source/FreeImage/J2KHelper.cpp	2015-03-02 02:07:08.000000000 +0100
+++ FreeImage-new/Source/FreeImage/J2KHelper.cpp	2015-09-05 02:13:52.042353324 +0200
@@ -21,7 +21,7 @@

 #include "FreeImage.h"
 #include "Utilities.h"
-#include "../LibOpenJPEG/openjpeg.h"
+#include <openjpeg.h>
 #include "J2KHelper.h"

 // --------------------------------------------------------------------------
diff -rupN FreeImage/Source/FreeImage/Plugin.cpp FreeImage-new/Source/FreeImage/Plugin.cpp
--- FreeImage/Source/FreeImage/Plugin.cpp	2015-03-02 02:07:08.000000000 +0100
+++ FreeImage-new/Source/FreeImage/Plugin.cpp	2015-09-05 02:13:52.042353324 +0200
@@ -263,7 +263,12 @@ FreeImage_Initialise(BOOL load_local_plu
 			s_plugins->AddNode(InitDDS);
 	        s_plugins->AddNode(InitGIF);
 	        s_plugins->AddNode(InitHDR);
-			s_plugins->AddNode(InitG3);
+/* The G3 fax format plugin is deliberately disabled in the Fedora build of
+   FreeImage as it requires that FreeImage uses a private copy of libtiff
+   which is a no no because of security reasons. */
+#if 0
+ 			s_plugins->AddNode(InitG3);
+#endif
 			s_plugins->AddNode(InitSGI);
 			s_plugins->AddNode(InitEXR);
 			s_plugins->AddNode(InitJ2K);
diff -rupN FreeImage/Source/FreeImage/PluginEXR.cpp FreeImage-new/Source/FreeImage/PluginEXR.cpp
--- FreeImage/Source/FreeImage/PluginEXR.cpp	2015-03-02 02:07:08.000000000 +0100
+++ FreeImage-new/Source/FreeImage/PluginEXR.cpp	2015-09-05 02:13:52.042353324 +0200
@@ -28,16 +28,16 @@
 #pragma warning (disable : 4800) // ImfVersion.h - 'const int' : forcing value to bool 'true' or 'false' (performance warning)
 #endif

-#include "../OpenEXR/IlmImf/ImfIO.h"
-#include "../OpenEXR/Iex/Iex.h"
-#include "../OpenEXR/IlmImf/ImfOutputFile.h"
-#include "../OpenEXR/IlmImf/ImfInputFile.h"
-#include "../OpenEXR/IlmImf/ImfRgbaFile.h"
-#include "../OpenEXR/IlmImf/ImfChannelList.h"
-#include "../OpenEXR/IlmImf/ImfRgba.h"
-#include "../OpenEXR/IlmImf/ImfArray.h"
-#include "../OpenEXR/IlmImf/ImfPreviewImage.h"
-#include "../OpenEXR/Half/half.h"
+#include <OpenEXR/ImfIO.h>
+#include <OpenEXR/Iex.h>
+#include <OpenEXR/ImfOutputFile.h>
+#include <OpenEXR/ImfInputFile.h>
+#include <OpenEXR/ImfRgbaFile.h>
+#include <OpenEXR/ImfChannelList.h>
+#include <OpenEXR/ImfRgba.h>
+#include <OpenEXR/ImfArray.h>
+#include <OpenEXR/ImfPreviewImage.h>
+#include <OpenEXR/half.h>

 // ==========================================================
diff -rupN FreeImage/Source/FreeImage/PluginJ2K.cpp FreeImage-new/Source/FreeImage/PluginJ2K.cpp
--- FreeImage/Source/FreeImage/PluginJ2K.cpp	2015-03-02 02:07:08.000000000 +0100
+++ FreeImage-new/Source/FreeImage/PluginJ2K.cpp	2015-09-05 02:13:52.043353343 +0200
@@ -21,7 +21,7 @@

 #include "FreeImage.h"
 #include "Utilities.h"
-#include "../LibOpenJPEG/openjpeg.h"
+#include <openjpeg.h>
 #include "J2KHelper.h"

 // ==========================================================
diff -rupN FreeImage/Source/FreeImage/PluginJP2.cpp FreeImage-new/Source/FreeImage/PluginJP2.cpp
--- FreeImage/Source/FreeImage/PluginJP2.cpp	2015-03-02 02:07:08.000000000 +0100
+++ FreeImage-new/Source/FreeImage/PluginJP2.cpp	2015-09-05 02:13:52.043353343 +0200
@@ -21,7 +21,7 @@

 #include "FreeImage.h"
 #include "Utilities.h"
-#include "../LibOpenJPEG/openjpeg.h"
+#include <openjpeg.h>
 #include "J2KHelper.h"

 // ==========================================================
diff -rupN FreeImage/Source/FreeImage/PluginJPEG.cpp FreeImage-new/Source/FreeImage/PluginJPEG.cpp
--- FreeImage/Source/FreeImage/PluginJPEG.cpp	2015-03-02 02:07:08.000000000 +0100
+++ FreeImage-new/Source/FreeImage/PluginJPEG.cpp	2015-09-05 02:13:52.043353343 +0200
@@ -35,9 +35,9 @@ extern "C" {
 #undef FAR
 #include <setjmp.h>

-#include "../LibJPEG/jinclude.h"
-#include "../LibJPEG/jpeglib.h"
-#include "../LibJPEG/jerror.h"
+#include <stdio.h>
+#include <jpeglib.h>
+#include <jerror.h>
 }

 #include "FreeImage.h"
diff -rupN FreeImage/Source/FreeImage/PluginJXR.cpp FreeImage-new/Source/FreeImage/PluginJXR.cpp
--- FreeImage/Source/FreeImage/PluginJXR.cpp	2015-03-03 23:07:08.000000000 +0100
+++ FreeImage-new/Source/FreeImage/PluginJXR.cpp	2018-07-31 23:37:58.561953201 +0200
@@ -23,7 +23,7 @@
 #include "Utilities.h"
 #include "../Metadata/FreeImageTag.h"

-#include "../LibJXR/jxrgluelib/JXRGlue.h"
+#include <JXRGlue.h>

 // ==========================================================
 // Plugin Interface
diff -rupN FreeImage/Source/FreeImage/PluginPNG.cpp FreeImage-new/Source/FreeImage/PluginPNG.cpp
--- FreeImage/Source/FreeImage/PluginPNG.cpp	2015-03-10 20:16:12.000000000 +0100
+++ FreeImage-new/Source/FreeImage/PluginPNG.cpp	2015-09-05 02:13:52.044353363 +0200
@@ -40,8 +40,8 @@

 // ----------------------------------------------------------

-#include "../ZLib/zlib.h"
-#include "../LibPNG/png.h"
+#include <zlib.h>
+#include <png.h>

 // ----------------------------------------------------------

diff -rupN FreeImage/Source/FreeImage/PluginRAW.cpp FreeImage-new/Source/FreeImage/PluginRAW.cpp
--- FreeImage/Source/FreeImage/PluginRAW.cpp	2015-03-08 20:12:04.000000000 +0100
+++ FreeImage-new/Source/FreeImage/PluginRAW.cpp	2015-09-05 02:13:52.044353363 +0200
@@ -19,7 +19,7 @@
 // Use at your own risk!
 // ==========================================================

-#include "../LibRawLite/libraw/libraw.h"
+#include <libraw/libraw.h>

 #include "FreeImage.h"
 #include "Utilities.h"

diff -rupN FreeImage/Source/FreeImage/PluginTIFF.cpp FreeImage-new/Source/FreeImage/PluginTIFF.cpp
--- FreeImage/Source/FreeImage/PluginTIFF.cpp	2015-03-02 02:07:08.000000000 +0100
+++ FreeImage-new/Source/FreeImage/PluginTIFF.cpp	2015-09-05 02:13:52.044353363 +0200
@@ -37,9 +37,9 @@

 #include "FreeImage.h"
 #include "Utilities.h"
-#include "../LibTIFF4/tiffiop.h"
+#include <tiffio.h>
 #include "../Metadata/FreeImageTag.h"
-#include "../OpenEXR/Half/half.h"
+#include <OpenEXR/half.h>

 #include "FreeImageIO.h"
 #include "PSDParser.h"
@@ -194,16 +194,6 @@ TIFFFdOpen(thandle_t handle, const char *name, const char *mode) {
 	return tif;
 }

-/**
-Open a TIFF file for reading or writing
-@param name
-@param mode
-*/
-TIFF*
-TIFFOpen(const char* name, const char* mode) {
-	return 0;
-}
-
 // ----------------------------------------------------------
 //   TIFF library FreeImage-specific routines.
 // ----------------------------------------------------------
diff -rupN FreeImage/Source/FreeImage/PluginWebP.cpp FreeImage-new/Source/FreeImage/PluginWebP.cpp
--- FreeImage/Source/FreeImage/PluginWebP.cpp	2015-03-02 02:07:08.000000000 +0100
+++ FreeImage-new/Source/FreeImage/PluginWebP.cpp	2015-09-05 02:13:52.044353363 +0200
@@ -24,10 +24,10 @@

 #include "../Metadata/FreeImageTag.h"

-#include "../LibWebP/src/webp/decode.h"
-#include "../LibWebP/src/webp/encode.h"
-#include "../LibWebP/src/webp/mux.h"
+#include <webp/decode.h>
+#include <webp/encode.h>
+#include <webp/mux.h>

 // ==========================================================
 // Plugin Interface
 diff -rupN FreeImage/Source/FreeImage/PSDParser.cpp FreeImage-new/Source/FreeImage/PSDParser.cpp
--- FreeImage/Source/FreeImage/PSDParser.cpp	2016-02-11 03:18:02.000000000 +0100
+++ FreeImage-new/Source/FreeImage/PSDParser.cpp	2018-08-01 00:17:18.323822675 +0200
@@ -133,8 +133,8 @@ public:
 template <>
 class PSDGetValue<8> {
 public:
-	static inline UINT64 get(const BYTE * iprBuffer) {
-		UINT64 v = ((const UINT64*)iprBuffer)[0];
+	static inline uint64_t get(const BYTE * iprBuffer) {
+		uint64_t v = ((const uint64_t*)iprBuffer)[0];
 #ifndef FREEIMAGE_BIGENDIAN
 		SwapInt64(&v);
 #endif
@@ -147,7 +147,7 @@ public:

 // --------------------------------------------------------------------------

-static UINT64
+static uint64_t
 psdReadSize(FreeImageIO *io, fi_handle handle, const psdHeaderInfo& header) {
 	if(header._Version == 1) {
 		BYTE Length[4];
@@ -199,11 +199,11 @@ public:
 template <>
 class PSDSetValue<8> {
 public:
-	static inline void set(const BYTE * iprBuffer, UINT64 v) {
+	static inline void set(const BYTE * iprBuffer, uint64_t v) {
 #ifndef FREEIMAGE_BIGENDIAN
 		SwapInt64(&v);
 #endif
-		((UINT64*)iprBuffer)[0] = v;
+		((uint64_t*)iprBuffer)[0] = v;
 	}
 };

@@ -213,7 +213,7 @@ public:
 // --------------------------------------------------------------------------

 static inline bool
-psdWriteSize(FreeImageIO *io, fi_handle handle, const psdHeaderInfo& header, UINT64 v) {
+psdWriteSize(FreeImageIO *io, fi_handle handle, const psdHeaderInfo& header, uint64_t v) {
 	if(header._Version == 1) {
 		BYTE Length[4];
 		psdSetLongValue(Length, sizeof(Length), (DWORD)v);
@@ -1063,10 +1063,10 @@ unsigned psdParser::GetChannelOffset(FIB
 bool psdParser::ReadLayerAndMaskInfoSection(FreeImageIO *io, fi_handle handle)	{
 	bool bSuccess = true;

-	UINT64 nTotalBytes = psdReadSize(io, handle, _headerInfo);
+	uint64_t nTotalBytes = psdReadSize(io, handle, _headerInfo);

 	// Hack to handle large PSB files without using fseeko().
-	if (sizeof(long) < sizeof(UINT64)) {
+	if (sizeof(long) < sizeof(uint64_t)) {
 		const long offset = 0x10000000;
 		while (nTotalBytes > offset) {
 			if (io->seek_proc(handle, offset, SEEK_CUR) != 0) {
@@ -1672,7 +1672,7 @@ bool psdParser::WriteLayerAndMaskInfoSec
 	// Short section with no layers.
 	BYTE IntValue[4];

-	UINT64 size;
+	uint64_t size;
 	if(_headerInfo._Version == 1) {
 		size = 8;
 	} else {
diff -rupN FreeImage/Source/FreeImage/ZLibInterface.cpp FreeImage-new/Source/FreeImage/ZLibInterface.cpp
--- FreeImage/Source/FreeImage/ZLibInterface.cpp	2015-03-02 02:07:10.000000000 +0100
+++ FreeImage-new/Source/FreeImage/ZLibInterface.cpp	2015-09-05 02:13:52.044353363 +0200
@@ -19,10 +19,9 @@
 // Use at your own risk!
 // ==========================================================

-#include "../ZLib/zlib.h"
+#include <zlib.h>
 #include "FreeImage.h"
 #include "Utilities.h"
-#include "../ZLib/zutil.h"	/* must be the last header because of error C3163 in VS2008 (_vsnprintf defined in stdio.h) */

 /**
 Compresses a source buffer into a target buffer, using the ZLib library.
@@ -115,7 +114,7 @@ FreeImage_ZLibGZip(BYTE *target, DWORD t
 			return 0;
         case Z_OK: {
             // patch header, setup crc and length (stolen from mod_trace_output)
-            BYTE *p = target + 8; *p++ = 2; *p = OS_CODE; // xflags, os_code
+            BYTE *p = target + 8; *p++ = 2; *p = 0x03; // xflags, os_code (unix)
  	        crc = crc32(crc, source, source_size);
 	        memcpy(target + 4 + dest_len, &crc, 4);
 	        memcpy(target + 8 + dest_len, &source_size, 4);
diff -rupN FreeImage/Source/FreeImage.h FreeImage-new/Source/FreeImage.h
--- FreeImage/Source/FreeImage.h	2015-03-04 02:17:54.000000000 +0100
+++ FreeImage-new/Source/FreeImage.h	2015-09-05 02:13:52.045353382 +0200
@@ -155,8 +155,11 @@ typedef uint8_t BYTE;
 typedef uint16_t WORD;
 typedef uint32_t DWORD;
 typedef int32_t LONG;
+// Disable these, they conflict with the (wrong) ones of libraw
+#if 0
 typedef int64_t INT64;
 typedef uint64_t UINT64;
+#endif
 #else
 // MS is not C99 ISO compliant
 typedef long BOOL;
@@ -410,7 +413,12 @@ FI_ENUM(FREE_IMAGE_FORMAT) {
 	FIF_DDS		= 24,
 	FIF_GIF     = 25,
 	FIF_HDR		= 26,
-	FIF_FAXG3	= 27,
+/* The G3 fax format plugin is deliberately disabled in the Fedora build of
+   FreeImage as it requires that FreeImage uses a private copy of libtiff
+   which is a no no because of security reasons. */
+#if 0
+ 	FIF_FAXG3	= 27,
+#endif
 	FIF_SGI		= 28,
 	FIF_EXR		= 29,
 	FIF_J2K		= 30,
@@ -473,6 +481,10 @@ FI_ENUM(FREE_IMAGE_DITHER) {
 	FID_BAYER16x16	= 6		//! Bayer ordered dispersed dot dithering (order 4 dithering matrix)
 };

+/* The FreeImage_JPEGTransform functions are deliberately disabled in the
+   Fedora build of FreeImage as they require that FreeImage uses a private copy
+   of libjpeg which is a no no because of security reasons. */
+#if 0
 /** Lossless JPEG transformations
 Constants used in FreeImage_JPEGTransform
 */
@@ -486,6 +498,7 @@ FI_ENUM(FREE_IMAGE_JPEG_OPERATION) {
 	FIJPEG_OP_ROTATE_180	= 6,	//! 180-degree rotation
 	FIJPEG_OP_ROTATE_270	= 7		//! 270-degree clockwise (or 90 ccw)
 };
+#endif

 /** Tone mapping operators.
 Constants used in FreeImage_ToneMapping.
@@ -1076,7 +1089,10 @@ DLL_API const char* DLL_CALLCONV FreeIma
 // --------------------------------------------------------------------------
 // JPEG lossless transformation routines
 // --------------------------------------------------------------------------
-
+/* The FreeImage_JPEGTransform functions are deliberately disabled in the
++   Fedora build of FreeImage as they require that FreeImage uses a private copy
++   of libjpeg which is a no no because of security reasons. */
+#if 0
 DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransform(const char *src_file, const char *dst_file, FREE_IMAGE_JPEG_OPERATION operation, BOOL perfect FI_DEFAULT(TRUE));
 DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransformU(const wchar_t *src_file, const wchar_t *dst_file, FREE_IMAGE_JPEG_OPERATION operation, BOOL perfect FI_DEFAULT(TRUE));
 DLL_API BOOL DLL_CALLCONV FreeImage_JPEGCrop(const char *src_file, const char *dst_file, int left, int top, int right, int bottom);
@@ -1085,6 +1101,7 @@ DLL_API BOOL DLL_CALLCONV FreeImage_JPEG
 DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransformCombined(const char *src_file, const char *dst_file, FREE_IMAGE_JPEG_OPERATION operation, int* left, int* top, int* right, int* bottom, BOOL perfect FI_DEFAULT(TRUE));
 DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransformCombinedU(const wchar_t *src_file, const wchar_t *dst_file, FREE_IMAGE_JPEG_OPERATION operation, int* left, int* top, int* right, int* bottom, BOOL perfect FI_DEFAULT(TRUE));
 DLL_API BOOL DLL_CALLCONV FreeImage_JPEGTransformCombinedFromMemory(FIMEMORY* src_stream, FIMEMORY* dst_stream, FREE_IMAGE_JPEG_OPERATION operation, int* left, int* top, int* right, int* bottom, BOOL perfect FI_DEFAULT(TRUE));
+#endif

 // --------------------------------------------------------------------------
diff -rupN FreeImage/Source/FreeImageToolkit/JPEGTransform.cpp FreeImage-new/Source/FreeImageToolkit/JPEGTransform.cpp
--- FreeImage/Source/FreeImageToolkit/JPEGTransform.cpp	2015-03-02 02:07:10.000000000 +0100
+++ FreeImage-new/Source/FreeImageToolkit/JPEGTransform.cpp	2015-09-05 02:13:52.045353382 +0200
@@ -26,10 +26,10 @@ extern "C" {
 #undef FAR
 #include <setjmp.h>

-#include "../LibJPEG/jinclude.h"
-#include "../LibJPEG/jpeglib.h"
-#include "../LibJPEG/jerror.h"
-#include "../LibJPEG/transupp.h"
+#include <jinclude.h>
+#include <jpeglib.h>
+#include <jerror.h>
+#include <transupp.h>
 }

 #include "FreeImage.h"
diff -rupN FreeImage/Source/Metadata/TagConversion.cpp FreeImage-new/Source/Metadata/TagConversion.cpp
--- FreeImage/Source/Metadata/TagConversion.cpp	2015-03-02 02:07:10.000000000 +0100
+++ FreeImage-new/Source/Metadata/TagConversion.cpp	2015-09-05 02:13:52.045353382 +0200
@@ -30,6 +30,11 @@

 #define MAX_TEXT_EXTENT	512

+// These were in FreeImage.h, but are moved here to avoid conflicts (see note in FreeImage.h)
+typedef int64_t INT64;
+typedef uint64_t UINT64;
+
+
 /**
 Convert a tag to a C string
 */
diff -rupN FreeImage/Source/Metadata/XTIFF.cpp FreeImage-new/Source/Metadata/XTIFF.cpp
--- FreeImage/Source/Metadata/XTIFF.cpp	2015-03-02 02:07:10.000000000 +0100
+++ FreeImage-new/Source/Metadata/XTIFF.cpp	2015-09-05 02:13:52.045353382 +0200
@@ -29,13 +29,18 @@
 #pragma warning (disable : 4786) // identifier was truncated to 'number' characters
 #endif

-#include "../LibTIFF4/tiffiop.h"
+#include <tiffio.h>

 #include "FreeImage.h"
 #include "Utilities.h"
 #include "FreeImageTag.h"
 #include "FIRational.h"

+extern "C"
+{
+    int _TIFFDataSize(TIFFDataType type);
+}
+
 // ----------------------------------------------------------
 //   Extended TIFF Directory GEO Tag Support
 // ----------------------------------------------------------
@@ -224,6 +229,33 @@ tiff_write_geotiff_profile(TIFF *tif, FI
 //   TIFF EXIF tag reading & writing
 // ----------------------------------------------------------

+static uint32 exif_tag_ids[] = {
+  EXIFTAG_EXPOSURETIME, EXIFTAG_FNUMBER, EXIFTAG_EXPOSUREPROGRAM,
+  EXIFTAG_SPECTRALSENSITIVITY, EXIFTAG_ISOSPEEDRATINGS, EXIFTAG_OECF,
+  EXIFTAG_EXIFVERSION, EXIFTAG_DATETIMEORIGINAL, EXIFTAG_DATETIMEDIGITIZED,
+  EXIFTAG_COMPONENTSCONFIGURATION, EXIFTAG_COMPRESSEDBITSPERPIXEL,
+  EXIFTAG_SHUTTERSPEEDVALUE, EXIFTAG_APERTUREVALUE,
+  EXIFTAG_BRIGHTNESSVALUE, EXIFTAG_EXPOSUREBIASVALUE,
+  EXIFTAG_MAXAPERTUREVALUE, EXIFTAG_SUBJECTDISTANCE, EXIFTAG_METERINGMODE,
+  EXIFTAG_LIGHTSOURCE, EXIFTAG_FLASH, EXIFTAG_FOCALLENGTH,
+  EXIFTAG_SUBJECTAREA, EXIFTAG_MAKERNOTE, EXIFTAG_USERCOMMENT,
+  EXIFTAG_SUBSECTIME, EXIFTAG_SUBSECTIMEORIGINAL,
+  EXIFTAG_SUBSECTIMEDIGITIZED, EXIFTAG_FLASHPIXVERSION, EXIFTAG_COLORSPACE,
+  EXIFTAG_PIXELXDIMENSION, EXIFTAG_PIXELYDIMENSION,
+  EXIFTAG_RELATEDSOUNDFILE, EXIFTAG_FLASHENERGY,
+  EXIFTAG_SPATIALFREQUENCYRESPONSE, EXIFTAG_FOCALPLANEXRESOLUTION,
+  EXIFTAG_FOCALPLANEYRESOLUTION, EXIFTAG_FOCALPLANERESOLUTIONUNIT,
+  EXIFTAG_SUBJECTLOCATION, EXIFTAG_EXPOSUREINDEX, EXIFTAG_SENSINGMETHOD,
+  EXIFTAG_FILESOURCE, EXIFTAG_SCENETYPE, EXIFTAG_CFAPATTERN,
+  EXIFTAG_CUSTOMRENDERED, EXIFTAG_EXPOSUREMODE, EXIFTAG_WHITEBALANCE,
+  EXIFTAG_DIGITALZOOMRATIO, EXIFTAG_FOCALLENGTHIN35MMFILM,
+  EXIFTAG_SCENECAPTURETYPE, EXIFTAG_GAINCONTROL, EXIFTAG_CONTRAST,
+  EXIFTAG_SATURATION, EXIFTAG_SHARPNESS, EXIFTAG_DEVICESETTINGDESCRIPTION,
+  EXIFTAG_SUBJECTDISTANCERANGE, EXIFTAG_GAINCONTROL, EXIFTAG_GAINCONTROL,
+  EXIFTAG_IMAGEUNIQUEID
+};
+static int nExifTags = sizeof(exif_tag_ids) / sizeof(exif_tag_ids[0]);
+
 /**
 Read a single Exif tag

@@ -575,45 +607,11 @@ tiff_read_exif_tags(TIFF *tif, TagLib::M

 	// loop over all Core Directory Tags
 	// ### uses private data, but there is no other way
+	// -> Fedora: Best we can do without private headers is to hard-code a list of known EXIF tags and read those
 	if(md_model == TagLib::EXIF_MAIN) {
-		const TIFFDirectory *td = &tif->tif_dir;
-
-		uint32 lastTag = 0;	//<- used to prevent reading some tags twice (as stored in tif_fieldinfo)
-
-		for (int fi = 0, nfi = (int)tif->tif_nfields; nfi > 0; nfi--, fi++) {
-			const TIFFField *fld = tif->tif_fields[fi];
-
-			const uint32 tag_id = TIFFFieldTag(fld);
-
-			if(tag_id == lastTag) {
-				continue;
-			}
-
-			// test if tag value is set
-			// (lifted directly from LibTiff _TIFFWriteDirectory)
-
-			if( fld->field_bit == FIELD_CUSTOM ) {
-				int is_set = FALSE;
-
-				for(int ci = 0; ci < td->td_customValueCount; ci++ ) {
-					is_set |= (td->td_customValues[ci].info == fld);
-				}
-
-				if( !is_set ) {
-					continue;
-				}
-
-			} else if(!TIFFFieldSet(tif, fld->field_bit)) {
-				continue;
-			}
-
-			// process *all* other tags (some will be ignored)
-
-			tiff_read_exif_tag(tif, tag_id, dib, md_model);
-
-			lastTag = tag_id;
+		for (int i = 0; i < nExifTags; ++i) {
+			tiff_read_exif_tag(tif, exif_tag_ids[i], dib, md_model);
 		}
-
 	}

 	return TRUE;
@@ -723,10 +721,9 @@ tiff_write_exif_tags(TIFF *tif, TagLib::

 	TagLib& tag_lib = TagLib::instance();

-	for (int fi = 0, nfi = (int)tif->tif_nfields; nfi > 0; nfi--, fi++) {
-		const TIFFField *fld = tif->tif_fields[fi];
-
-		const uint32 tag_id = TIFFFieldTag(fld);
+	for (int fi = 0; fi < nExifTags; fi++) {
+		const uint32 tag_id = exif_tag_ids[fi];
+		const TIFFField *fld = TIFFFieldWithTag(tif, tag_id);

 		if(skip_write_field(tif, tag_id)) {
 			// skip tags that are already handled by the LibTIFF writing process
diff -rupN FreeImage/Source/Utilities.h FreeImage-new/Source/Utilities.h
--- FreeImage/Source/Utilities.h	2016-04-11 15:15:32.000000000 +0200
+++ FreeImage-new/Source/Utilities.h	2018-08-01 00:16:29.826825358 +0200
@@ -446,12 +446,12 @@ SwapLong(DWORD *lp) {
 }

 inline void
-SwapInt64(UINT64 *arg) {
+SwapInt64(uint64_t *arg) {
 #if defined(_MSC_VER) && _MSC_VER >= 1310
 	*arg = _byteswap_uint64(*arg);
 #else
 	union Swap {
-		UINT64 sv;
+		uint64_t sv;
 		DWORD ul[2];
 	} tmp, result;
 	tmp.sv = *arg;


code:
This patch is from Debian, named '0006-arm64.patch'

Author: Riku Voipio <riku.voipio@linaro.org>
Description: fuse_kernel.h: clean includes
 Use <linux/types.h> for linux and define types used for other operating systems
 using <stdint.h> types (Closes: #752081).

diff -Naurp fuse.orig/include/fuse_kernel.h fuse/include/fuse_kernel.h
--- fuse.orig/include/fuse_kernel.h
+++ fuse/include/fuse_kernel.h
@@ -88,12 +88,16 @@
 #ifndef _LINUX_FUSE_H
 #define _LINUX_FUSE_H

-#include <sys/types.h>
+#ifdef __linux__
+#include <linux/types.h>
+#else
+#include <stdint.h>
 #define __u64 uint64_t
 #define __s64 int64_t
 #define __u32 uint32_t
 #define __s32 int32_t
 #define __u16 uint16_t
+#endif

 /*
  * Version negotiation:

repo_name: maximed/guix

license: mit


code:
--- a/gajim/common/configpaths.py	2020-11-19 12:12:02.004414323 +0100
+++ a/gajim/common/configpaths.py	2020-11-19 15:34:52.211476895 +0100
@@ -47,7 +47,7 @@
         return [Path(_paths['PLUGINS_BASE']),
                 Path('/app/plugins')]
     return [Path(_paths['PLUGINS_BASE']),
-            Path(_paths['PLUGINS_USER'])]
+            Path(_paths['PLUGINS_USER'])] + ([Path(os.getenv('GAJIM_PLUGIN_PATH'))] if os.getenv('GAJIM_PLUGIN_PATH') and Path(os.getenv('GAJIM_PLUGIN_PATH')).is_dir() else [])

 def get_paths(type_: PathType) -> Generator[str, None, None]:


code:
Sort the ecode list in the gnt-cluster manual for deterministic results.

Submitted upstream: <https://github.com/ganeti/ganeti/pull/1504>.

diff --git a/lib/build/sphinx_ext.py b/lib/build/sphinx_ext.py
--- a/lib/build/sphinx_ext.py
+++ b/lib/build/sphinx_ext.py
@@ -108,7 +108,7 @@ CV_ECODES_DOC = "ecodes"
 # pylint: disable=W0621
 CV_ECODES_DOC_LIST = [(name, doc) for (_, name, doc) in constants.CV_ALL_ECODES]
 DOCUMENTED_CONSTANTS = {
-  CV_ECODES_DOC: CV_ECODES_DOC_LIST,
+  CV_ECODES_DOC: sorted(CV_ECODES_DOC_LIST, key=lambda tup: tup[0]),
   }


code:
This patch adds a new "--disable-version-links" configuration option
that allows installing to the standard GNU installation directories
instead of having to add symlinks in /etc/ganeti/{lib,share} that
points to the right $ganeti/{lib,share}/$version.  Mainly to reduce
service complexity, and because Guix users can install as many versions
of Ganeti they can muster without resorting to such hacks.

diff --git a/Makefile.am b/Makefile.am
--- a/Makefile.am
+++ b/Makefile.am
@@ -66,11 +66,16 @@ SHELL_ENV_INIT = autotools/shell-env-init
 # so, if some currently architecture-independent executable is replaced by an
 # architecture-dependent one (and hence has to go under $(versiondir)), add a link
 # under $(versionedsharedir) but do not change the external links.
+#
+# As of Ganeti 3.0, it is possible to disable this behavior by passing
+# --disable-version-links, in which case the standard GNU installation
+# directories are used.
 if USE_VERSION_FULL
 DIRVERSION=$(VERSION_FULL)
 else
 DIRVERSION=$(VERSION_MAJOR).$(VERSION_MINOR)
 endif
+if USE_VERSION_LINKS
 versiondir = $(libdir)/ganeti/$(DIRVERSION)
 defaultversiondir = $(libdir)/ganeti/default
 versionedsharedir = $(prefix)/share/ganeti/$(DIRVERSION)
@@ -90,6 +95,18 @@ gntpythondir = $(versionedsharedir)
 pkgpython_bindir = $(versionedsharedir)
 gnt_python_sbindir = $(versionedsharedir)
 tools_pythondir = $(versionedsharedir)
+else
+myexeclibdir = $(pkglibdir)
+pkgpython_rpc_stubdir = $(pkgpythondir)/rpc/stub
+gntpythondir = $(sbindir)
+pkgpython_bindir = $(pkglibdir)
+gnt_python_sbindir = $(sbindir)
+tools_pythondir = $(pkglibdir)
+versionedsharedir = $(pkglibdir)
+# This is a hack but works because the only user does $(versiondir)$(datadir).
+versiondir =
+endif !USE_VERSION_LINKS
+

 clientdir = $(pkgpythondir)/client
 cmdlibdir = $(pkgpythondir)/cmdlib
@@ -2356,6 +2373,7 @@ src/AutoConf.hs: Makefile src/AutoConf.hs.in $(PRINT_PY_CONSTANTS) \
 	    -DVERSION_SUFFIX="$(VERSION_SUFFIX)" \
 	    -DVERSION_FULL="$(VERSION_FULL)" \
 	    -DDIRVERSION="$(DIRVERSION)" \
+	    -DUSE_VERSION_LINKS="$(USE_VERSION_LINKS)" \
 	    -DLOCALSTATEDIR="$(localstatedir)" \
 	    -DSYSCONFDIR="$(sysconfdir)" \
 	    -DSSH_CONFIG_DIR="$(SSH_CONFIG_DIR)" \
@@ -2857,6 +2875,7 @@ install-exec-local:
 	@mkdir_p@ "$(DESTDIR)${localstatedir}/lib/ganeti" \
 	  "$(DESTDIR)${localstatedir}/log/ganeti" \
 	  "$(DESTDIR)${localstatedir}/run/ganeti"
+if USE_VERSION_LINKS
 	for dir in $(SYMLINK_TARGET_DIRS); do \
 	  @mkdir_p@  $(DESTDIR)$$dir; \
 	done
@@ -2892,7 +2911,8 @@ install-exec-local:
 if INSTALL_SYMLINKS
 	$(LN_S) -f $(versionedsharedir) $(DESTDIR)$(sysconfdir)/ganeti/share
 	$(LN_S) -f $(versiondir) $(DESTDIR)$(sysconfdir)/ganeti/lib
-endif
+endif INSTALL_SYMLINKS
+endif USE_VERSION_LINKS

 .PHONY: apidoc
 if WANT_HSAPIDOC
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -29,6 +29,23 @@ AC_SUBST([BINDIR], $bindir)
 AC_SUBST([SBINDIR], $sbindir)
 AC_SUBST([MANDIR], $mandir)

+# --enable-version-links
+AC_ARG_ENABLE([version-links],
+  [AS_HELP_STRING([--enable-version-links],
+                  m4_normalize([install ganeti to version-specific
+                  subdirectories to allow installing multiple versions
+                  in parallel (default: enabled)]))],
+  [[if test "$enableval" != no; then
+      USE_VERSION_LINKS=True
+    else
+      USE_VERSION_LINKS=False
+    fi
+  ]],
+  [USE_VERSION_LINKS=True
+  ])
+AC_SUBST(USE_VERSION_LINKS, $USE_VERSION_LINKS)
+AM_CONDITIONAL([USE_VERSION_LINKS], [test "$USE_VERSION_LINKS" = True])
+
 # --enable-versionfull
 AC_ARG_ENABLE([versionfull],
   [AS_HELP_STRING([--enable-versionfull],
diff --git a/lib/bootstrap.py b/lib/bootstrap.py
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -944,7 +944,7 @@ def SetupNodeDaemon(opts, cluster_name, node, ssh_port):
                          debug=opts.debug, verbose=opts.verbose,
                          use_cluster_key=True, ask_key=opts.ssh_key_check,
                          strict_host_check=opts.ssh_key_check,
-                         ensure_version=True)
+                         ensure_version=constants.USE_VERSION_LINKS)

   _WaitForSshDaemon(node, ssh_port)
   _WaitForNodeDaemon(node)
diff --git a/src/AutoConf.hs.in b/src/AutoConf.hs.in
--- a/src/AutoConf.hs.in
+++ b/src/AutoConf.hs.in
@@ -64,6 +64,9 @@ versionFull = "VERSION_FULL"
 dirVersion :: String
 dirVersion = "DIRVERSION"

+useVersionLinks :: Bool
+useVersionLinks = USE_VERSION_LINKS
+
 localstatedir :: String
 localstatedir = "LOCALSTATEDIR"

diff --git a/src/Ganeti/Constants.hs b/src/Ganeti/Constants.hs
--- a/src/Ganeti/Constants.hs
+++ b/src/Ganeti/Constants.hs
@@ -164,5 +164,8 @@ versionRevision = AutoConf.versionRevision
 dirVersion :: String
 dirVersion = AutoConf.dirVersion

+useVersionLinks :: Bool
+useVersionLinks = AutoConf.useVersionLinks
+
 osApiV10 :: Int
 osApiV10 = 10


code:
This patch adds support for newer versions of DRBD.

Submitted upstream: <https://github.com/ganeti/ganeti/pull/1496>.

diff --git a/lib/storage/drbd.py b/lib/storage/drbd.py
--- a/lib/storage/drbd.py
+++ b/lib/storage/drbd.py
@@ -315,6 +315,13 @@ class DRBD8Dev(base.BlockDev):
     """
     return self._show_info_cls.GetDevInfo(self._GetShowData(minor))

+  @staticmethod
+  def _NeedsLocalSyncerParams():
+    # For DRBD >= 8.4, syncer init must be done after local, not in net.
+    info = DRBD8.GetProcInfo()
+    version = info.GetVersion()
+    return version["k_minor"] >= 4
+
   def _MatchesLocal(self, info):
     """Test if our local config matches with an existing device.

@@ -397,6 +404,20 @@ class DRBD8Dev(base.BlockDev):
         base.ThrowError("drbd%d: can't attach local disk: %s",
                         minor, result.output)

+    def _WaitForMinorSyncParams():
+      """Call _SetMinorSyncParams and raise RetryAgain on errors.
+      """
+      if self._SetMinorSyncParams(minor, self.params):
+        raise utils.RetryAgain()
+
+    if self._NeedsLocalSyncerParams():
+      # Retry because disk config for DRBD resource may be still uninitialized.
+      try:
+        utils.Retry(_WaitForMinorSyncParams, 1.0, 5.0)
+      except utils.RetryTimeout as e:
+        base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
+                        (minor, utils.CommaJoin(e.args[0])))
+
   def _AssembleNet(self, minor, net_info, dual_pri=False, hmac=None,
                    secret=None):
     """Configure the network part of the device.
@@ -432,21 +453,24 @@ class DRBD8Dev(base.BlockDev):
     # sync speed only after setting up both sides can race with DRBD
     # connecting, hence we set it here before telling DRBD anything
     # about its peer.
-    sync_errors = self._SetMinorSyncParams(minor, self.params)
-    if sync_errors:
-      base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
-                      (minor, utils.CommaJoin(sync_errors)))
+
+    if not self._NeedsLocalSyncerParams():
+      sync_errors = self._SetMinorSyncParams(minor, self.params)
+      if sync_errors:
+        base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
+                        (minor, utils.CommaJoin(sync_errors)))

     family = self._GetNetFamily(minor, lhost, rhost)

-    cmd = self._cmd_gen.GenNetInitCmd(minor, family, lhost, lport,
+    cmds = self._cmd_gen.GenNetInitCmds(minor, family, lhost, lport,
                                       rhost, rport, protocol,
                                       dual_pri, hmac, secret, self.params)

-    result = utils.RunCmd(cmd)
-    if result.failed:
-      base.ThrowError("drbd%d: can't setup network: %s - %s",
-                      minor, result.fail_reason, result.output)
+    for cmd in cmds:
+      result = utils.RunCmd(cmd)
+      if result.failed:
+        base.ThrowError("drbd%d: can't setup network: %s - %s",
+                         minor, result.fail_reason, result.output)

     def _CheckNetworkConfig():
       info = self._GetShowInfo(minor)
@@ -463,19 +487,20 @@ class DRBD8Dev(base.BlockDev):
       base.ThrowError("drbd%d: timeout while configuring network", minor)

     # Once the assembly is over, try to set the synchronization parameters
-    try:
-      # The minor may not have been set yet, requiring us to set it at least
-      # temporarily
-      old_minor = self.minor
-      self._SetFromMinor(minor)
-      sync_errors = self.SetSyncParams(self.params)
-      if sync_errors:
-        base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
-                        (self.minor, utils.CommaJoin(sync_errors)))
-    finally:
-      # Undo the change, regardless of whether it will have to be done again
-      # soon
-      self._SetFromMinor(old_minor)
+    if not self._NeedsLocalSyncerParams():
+      try:
+        # The minor may not have been set yet, requiring us to set it at least
+        # temporarily
+        old_minor = self.minor
+        self._SetFromMinor(minor)
+        sync_errors = self.SetSyncParams(self.params)
+        if sync_errors:
+          base.ThrowError("drbd%d: can't set the synchronization parameters: %s" %
+                          (self.minor, utils.CommaJoin(sync_errors)))
+      finally:
+        # Undo the change, regardless of whether it will have to be done again
+        # soon
+        self._SetFromMinor(old_minor)

   @staticmethod
   def _GetNetFamily(minor, lhost, rhost):
diff --git a/lib/storage/drbd_cmdgen.py b/lib/storage/drbd_cmdgen.py
--- a/lib/storage/drbd_cmdgen.py
+++ b/lib/storage/drbd_cmdgen.py
@@ -56,7 +56,7 @@ class BaseDRBDCmdGenerator(object):
   def GenLocalInitCmds(self, minor, data_dev, meta_dev, size_mb, params):
     raise NotImplementedError

-  def GenNetInitCmd(self, minor, family, lhost, lport, rhost, rport, protocol,
+  def GenNetInitCmds(self, minor, family, lhost, lport, rhost, rport, protocol,
                     dual_pri, hmac, secret, params):
     raise NotImplementedError

@@ -138,7 +138,7 @@ class DRBD83CmdGenerator(BaseDRBDCmdGenerator):

     return [args]

-  def GenNetInitCmd(self, minor, family, lhost, lport, rhost, rport, protocol,
+  def GenNetInitCmds(self, minor, family, lhost, lport, rhost, rport, protocol,
                     dual_pri, hmac, secret, params):
     args = ["drbdsetup", self._DevPath(minor), "net",
             "%s:%s:%s" % (family, lhost, lport),
@@ -155,7 +155,7 @@ class DRBD83CmdGenerator(BaseDRBDCmdGenerator):
     if params[constants.LDP_NET_CUSTOM]:
       args.extend(shlex.split(params[constants.LDP_NET_CUSTOM]))

-    return args
+    return [args]

   def GenSyncParamsCmd(self, minor, params):
     args = ["drbdsetup", self._DevPath(minor), "syncer"]
@@ -345,8 +345,14 @@ class DRBD84CmdGenerator(BaseDRBDCmdGenerator):

     return cmds

-  def GenNetInitCmd(self, minor, family, lhost, lport, rhost, rport, protocol,
+  def GenNetInitCmds(self, minor, family, lhost, lport, rhost, rport, protocol,
                     dual_pri, hmac, secret, params):
+    cmds = []
+
+    cmds.append(["drbdsetup", "new-resource", self._GetResource(minor)])
+    cmds.append(["drbdsetup", "new-minor", self._GetResource(minor),
+                 str(minor), "0"])
+
     args = ["drbdsetup", "connect", self._GetResource(minor),
             "%s:%s:%s" % (family, lhost, lport),
             "%s:%s:%s" % (family, rhost, rport),
@@ -362,7 +368,8 @@ class DRBD84CmdGenerator(BaseDRBDCmdGenerator):
     if params[constants.LDP_NET_CUSTOM]:
       args.extend(shlex.split(params[constants.LDP_NET_CUSTOM]))

-    return args
+    cmds.append(args)
+    return cmds

   def GenSyncParamsCmd(self, minor, params):
     args = ["drbdsetup", "disk-options", minor]


code:
This patch allows the Haskell daemons to locate Python libraries
installed to a non-standard pythondir.  It is necessary because Guix
does not use versionedsharedir (see related patch that disables it).

diff --git a/Makefile.am b/Makefile.am
--- a/Makefile.am
+++ b/Makefile.am
@@ -83,6 +83,7 @@ myexeclibdir = $(pkglibdir)
 bindir = $(versiondir)/$(BINDIR)
 sbindir = $(versiondir)$(SBINDIR)
 mandir = $(versionedsharedir)/root$(MANDIR)
+pythondir = $(versionedsharedir)
 pkgpythondir = $(versionedsharedir)/ganeti
 pkgpython_rpc_stubdir = $(versionedsharedir)/ganeti/rpc/stub
 gntpythondir = $(versionedsharedir)
@@ -2386,6 +2387,7 @@ src/AutoConf.hs: Makefile src/AutoConf.hs.in $(PRINT_PY_CONSTANTS) \
 	    -DPKGLIBDIR="$(libdir)/ganeti" \
 	    -DSHAREDIR="$(prefix)/share/ganeti" \
 	    -DVERSIONEDSHAREDIR="$(versionedsharedir)" \
+	    -DPYTHONDIR="$(pythondir)" \
 	    -DDRBD_BARRIERS="$(DRBD_BARRIERS)" \
 	    -DDRBD_NO_META_FLUSH="$(DRBD_NO_META_FLUSH)" \
 	    -DSYSLOG_USAGE="$(SYSLOG_USAGE)" \
diff --git a/src/AutoConf.hs.in b/src/AutoConf.hs.in
--- a/src/AutoConf.hs.in
+++ b/src/AutoConf.hs.in
@@ -157,6 +157,9 @@ sharedir = "SHAREDIR"
 versionedsharedir :: String
 versionedsharedir = "VERSIONEDSHAREDIR"

+pythondir :: String
+pythondir = "PYTHONDIR"
+
 drbdBarriers :: String
 drbdBarriers = "DRBD_BARRIERS"

diff --git a/src/Ganeti/Path.hs b/src/Ganeti/Path.hs
--- a/src/Ganeti/Path.hs
+++ b/src/Ganeti/Path.hs
@@ -188,5 +188,5 @@ getInstReasonFilename instName = instanceReasonDir `pjoin` instName

 -- | The path to the Python executable for starting jobs.
 jqueueExecutorPy :: IO FilePath
-jqueueExecutorPy = return $ versionedsharedir
-                            </> "ganeti" </> "jqueue" </> "exec.py"
+jqueueExecutorPy = return $ pythondir
+                           </> "ganeti" </> "jqueue" </> "exec.py"
diff --git a/src/Ganeti/Query/Exec.hs b/src/Ganeti/Query/Exec.hs
--- a/src/Ganeti/Query/Exec.hs
+++ b/src/Ganeti/Query/Exec.hs
@@ -99,12 +99,12 @@ spawnJobProcess jid = withErrorLogAt CRITICAL (show jid) $
   do
     use_debug <- isDebugMode
     env_ <- (M.toList . M.insert "GNT_DEBUG" (if use_debug then "1" else "0")
-            . M.insert "PYTHONPATH" AC.versionedsharedir
+            . M.insert "PYTHONPATH" AC.pythondir
             . M.fromList)
            `liftM` getEnvironment
     execPy <- P.jqueueExecutorPy
     logDebug $ "Executing " ++ AC.pythonPath ++ " " ++ execPy
-               ++ " with PYTHONPATH=" ++ AC.versionedsharedir
+               ++ " with PYTHONPATH=" ++ AC.pythondir

     (master, child) <- pipeClient connectConfig
     let (rh, wh) = clientToHandle child


code:
This exposes information about disk sizes to OS install scripts.  instance-guix
uses this if available to determine the size of the VM image.

Submitted upstream:
https://github.com/ganeti/ganeti/pull/1503

diff --git a/lib/backend.py b/lib/backend.py
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -4305,6 +4305,7 @@ def OSEnvironment(instance, inst_os, debug=0):
     uri = _CalculateDeviceURI(instance, disk, real_disk)
     result["DISK_%d_ACCESS" % idx] = disk.mode
     result["DISK_%d_UUID" % idx] = disk.uuid
+    result["DISK_%d_SIZE" % idx] = str(disk.size)
     if real_disk.dev_path:
       result["DISK_%d_PATH" % idx] = real_disk.dev_path
     if uri:


code:
Do not override PYTHONPATH when calling Python code from the Haskell
daemons.  This is necessary because the Python library dependencies are
only available through PYTHONPATH.

diff --git a/src/Ganeti/Query/Exec.hs b/src/Ganeti/Query/Exec.hs
--- a/src/Ganeti/Query/Exec.hs
+++ b/src/Ganeti/Query/Exec.hs
@@ -99,12 +99,10 @@ spawnJobProcess jid = withErrorLogAt CRITICAL (show jid) $
   do
     use_debug <- isDebugMode
     env_ <- (M.toList . M.insert "GNT_DEBUG" (if use_debug then "1" else "0")
-            . M.insert "PYTHONPATH" AC.pythondir
             . M.fromList)
            `liftM` getEnvironment
     execPy <- P.jqueueExecutorPy
     logDebug $ "Executing " ++ AC.pythonPath ++ " " ++ execPy
-               ++ " with PYTHONPATH=" ++ AC.pythondir

     (master, child) <- pipeClient connectConfig
     let (rh, wh) = clientToHandle child


code:
By default, master-failover will call "herd start ganeti-wconfd" with
extra arguments such as --force-node.  That does not work with the
Shepherd, so the Guix service has a "force-start" action for this purpose.

diff --git a/lib/bootstrap.py b/lib/bootstrap.py
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -1011,9 +1011,7 @@ def MasterFailover(no_voting=False):

   try:
     # Forcefully start WConfd so that we can access the configuration
-    result = utils.RunCmd([pathutils.DAEMON_UTIL,
-                           "start", constants.WCONFD, "--force-node",
-                           "--no-voting", "--yes-do-it"])
+    result = utils.RunCmd(["herd", "force-start", constants.WCONFD])
     if result.failed:
       raise errors.OpPrereqError("Could not start the configuration daemon,"
                                  " command %s had exitcode %s and error %s" %


code:
Ganeti uses an internal tool to start/stop daemons during init and
upgrade.  This patch makes the tool use native Shepherd facilities.

diff --git a/daemons/daemon-util.in b/daemons/daemon-util.in
--- a/daemons/daemon-util.in
+++ b/daemons/daemon-util.in
@@ -184,6 +184,21 @@ use_systemctl() {
   return 1
 }

+# Checks if we should use the Shepherd to start/stop daemons
+use_shepherd() {
+  # Is Shepherd running as PID 1?
+  ps --no-headers -p 1 -o cmd | grep -q shepherd || return 1
+
+  type -p herd >/dev/null || return 1
+
+  # Does Shepherd know about Ganeti at all?
+  if herd status | grep -q ganeti; then
+    return 0
+  fi
+
+  return 1
+}
+
 # Prints path to PID file for a daemon.
 daemon_pidfile() {
   if [[ "$#" -lt 1 ]]; then
@@ -261,6 +276,13 @@ check() {
     else
       return 1
     fi
+  elif use_shepherd; then
+    activestate="$(herd status ${name})"
+    if echo $activestate | grep -q Running ; then
+      return 0
+    else
+      return 1
+    fi
   elif type -p start-stop-daemon >/dev/null; then
     start-stop-daemon --stop --signal 0 --quiet \
       --pidfile $pidfile --name "$name"
@@ -291,6 +313,20 @@ start() {
     return $?
   fi

+  if use_shepherd; then
+    if herd status "$name" | grep -q "disabled"; then
+      # The Shepherd will disable a service that has stopped, even if it exits
+      # gracefully.  Thus, we must re-enable it in case of a master failover.
+      herd enable "${name}"
+    fi
+    # Note: unlike systemd, which happily starts a service and returns success
+    # even if the daemon immediately exits, the Shepherd actually waits for it
+    # to come up.  Thus, ignore the exit status from 'herd start' in case of
+    # master daemons running on the wrong node, or ganeti-kvmd disabled, etc.
+    herd start "${name}"
+    return 0
+  fi
+
   # Read $<daemon>_ARGS and $EXTRA_<daemon>_ARGS
   eval local args="\"\$${ucname}_ARGS \$EXTRA_${ucname}_ARGS\""

@@ -336,6 +372,13 @@ stop() {

   if use_systemctl; then
     systemctl stop "${name}.service"
+  elif use_shepherd; then
+    if herd status | grep -q "$name"; then
+      herd stop "$name"
+    else
+      # Do not raise an error if the service has not been enabled.
+      return 0
+    fi
   elif type -p start-stop-daemon >/dev/null; then
     start-stop-daemon --stop --quiet --oknodo --retry 30 \
       --pidfile $pidfile --name "$name"
@@ -352,6 +395,9 @@ check_and_start() {
     if use_systemctl; then
       echo "${name} supervised by systemd but not running, will not restart."
       return 1
+    elif use_shepherd; then
+      echo "${name} supervised by shepherd but not running, will not restart."
+      return 1
     fi

     start $name


code:
'ls.scm' monkey-patches (ice-9 getopt-long) to allow it to recognize '-1'
as a valid option.  Unfortunately, monkey patching no longer works with
Guile 3.0 due to inlining, so change the test to make do without '-1'.

diff --git a/tests/core-utils.org b/tests/core-utils.org
index d35ede8..22718e3 100644
--- a/tests/core-utils.org
+++ b/tests/core-utils.org
@@ -93,14 +93,11 @@
 * ls
 :script:
 #+begin_src sh
-  ls -1 tests/data/star
+  ls tests/data/star
 #+end_src
 :stdout:
 #+begin_example
-  0
-  1
-  2
-  3
+  0  1  2  3
 #+end_example

 * test-file


code:
As for libc's `system', change Awk to look for `sh' in $PATH.  This patch is
only meant to be used during bootstrapping, where we don't know in advance the
absolute file name of `sh'.

--- gawk-4.1.3/io.c	2015-05-19 15:37:20.000000000 +0200
+++ gawk-4.1.3/io.c	2015-06-09 18:39:36.918414881 +0200
@@ -2025,7 +2025,7 @@

 		set_sigpipe_to_default();

-		execl("/bin/sh", "sh", "-c", command, NULL);
+		execlp("sh", "sh", "-c", command, NULL);
 		_exit(errno == ENOENT ? 127 : 126);

 	case -1:
@@ -2077,7 +2077,7 @@

 		signal(SIGPIPE, SIG_DFL);

-		execl("/bin/sh", "sh", "-c", command, NULL);
+		execlp("sh", "sh", "-c", command, NULL);
 		_exit(errno == ENOENT ? 127 : 126);

 	case -1:
@@ -2422,7 +2422,7 @@
 			fatal(_("close of pipe failed (%s)"), strerror(errno));
 		/* stderr does NOT get dup'ed onto child's stdout */
 		set_sigpipe_to_default();
-		execl("/bin/sh", "sh", "-c", str, NULL);
+		execlp("sh", "sh", "-c", str, NULL);
 		_exit(errno == ENOENT ? 127 : 126);
 	}
 #endif /* NOT __EMX__, NOT __MINGW32__ */
@@ -2659,7 +2659,7 @@
 		if (close(p[0]) == -1 || close(p[1]) == -1)
 			fatal(_("close of pipe failed (%s)"), strerror(errno));
 		set_sigpipe_to_default();
-		execl("/bin/sh", "sh", "-c", cmd, NULL);
+		execlp("sh", "sh", "-c", cmd, NULL);
 		_exit(errno == ENOENT ? 127 : 126);
 	}
 #endif /* NOT __EMX__, NOT __MINGW32__ */


code:
Taken from  https://gcc.gnu.org/cgi-bin/get-raw-msg?listname=gcc-patches&date=2016-01&msgid=1451802493-17406-1-git-send-email-vapier%40gentoo.org

Since the 3.0.3 release of gperf (made in May 2007), the generated func
has had the gnu_inline attribute applied to it.  The gcc source however
has not been updated to include that which has lead to a mismatch.

In practice, this hasn't been an issue for two reasons:
(1) Before gcc-5, the default standard was (gnu) C89, and gcc does not
warn or throw an error in this mode.
(2) Starting with gcc-4.8, the compiler driver used to build gcc was
changed to C++, and g++ does not warn or throw an error in this mode.

This error does show up though when using gcc-5 to build gcc-4.7 or
older as then the default is (gnu) C11 and the C compiler driver is
used.  That failure looks like:
In file included from .../gcc-4.7.4/gcc/cp/except.c:990:0:
cfns.gperf: At top level:
cfns.gperf:101:1: error: 'gnu_inline' attribute present on 'libc_name_p'
cfns.gperf:26:14: error: but not here

Whether the compiler should always emit this error regardless of the
active standard or compiler driver is debatable (I think it should be
consistent -- either always do it or never do it).

2015-08-06  Mike Frysinger  <vapier@gentoo.org>

	* cfns.gperf [__GNUC__, __GNUC_STDC_INLINE__]: Apply the
	__gnu_inline__ attribute.
	* cfns.h: Regenerated.
---
 gcc/cp/cfns.gperf | 3 +++
 gcc/cp/cfns.h     | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/gcc/cp/cfns.gperf b/gcc/cp/cfns.gperf
index 68acd3d..953262f 100644
--- a/gcc/cp/cfns.gperf
+++ b/gcc/cp/cfns.gperf
@@ -22,6 +22,9 @@ __inline
 static unsigned int hash (const char *, unsigned int);
 #ifdef __GNUC__
 __inline
+#ifdef __GNUC_STDC_INLINE__
+__attribute__ ((__gnu_inline__))
+#endif
 #endif
 const char * libc_name_p (const char *, unsigned int);
 %}
diff --git a/gcc/cp/cfns.h b/gcc/cp/cfns.h
index 1c6665d..6d00c0e 100644
--- a/gcc/cp/cfns.h
+++ b/gcc/cp/cfns.h
@@ -53,6 +53,9 @@ __inline
 static unsigned int hash (const char *, unsigned int);
 #ifdef __GNUC__
 __inline
+#ifdef __GNUC_STDC_INLINE__
+__attribute__ ((__gnu_inline__))
+#endif
 #endif
 const char * libc_name_p (const char *, unsigned int);
 /* maximum key range = 391, duplicates = 0 */
--
2.6.2


code:
This patch was taken from https://gcc.gnu.org/ml/gcc-patches/2015-08/msg00375.html.
It is used by propeller-gcc-4.

Since the 3.0.3 release of gperf (made in May 2007), the generated func
has had the gnu_inline attribute applied to it.  The gcc source however
has not been updated to include that which has lead to a mismatch.

In practice, this hasn't been an issue for two reasons:
(1) Before gcc-5, the default standard was (gnu) C89, and gcc does not
warn or throw an error in this mode.
(2) Starting with gcc-4.8, the compiler driver used to build gcc was
changed to C++, and g++ does not warn or throw an error in this mode.

This error does show up though when using gcc-5 to build gcc-4.7 or
older as then the default is (gnu) C11 and the C compiler driver is
used.  That failure looks like:
In file included from .../gcc-4.7.4/gcc/cp/except.c:990:0:
cfns.gperf: At top level:
cfns.gperf:101:1: error: 'gnu_inline' attribute present on 'libc_name_p'
cfns.gperf:26:14: error: but not here

Whether the compiler should always emit this error regardless of the
active standard or compiler driver is debatable (I think it should be
consistent -- either always do it or never do it).

2015-08-06  Mike Frysinger  <vapier@gentoo.org>

	* cfns.gperf [__GNUC__, __GNUC_STDC_INLINE__]: Apply the
	__gnu_inline__ attribute.
	* cfns.h: Regenerated.
---
 gcc/cp/cfns.gperf | 3 +++
 gcc/cp/cfns.h     | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/gcc/cp/cfns.gperf b/gcc/cp/cfns.gperf
index 68acd3d..953262f 100644
--- a/gcc/cp/cfns.gperf
+++ b/gcc/cp/cfns.gperf
@@ -22,6 +22,9 @@ __inline
 static unsigned int hash (const char *, unsigned int);
 #ifdef __GNUC__
 __inline
+#ifdef __GNUC_STDC_INLINE__
+__attribute__ ((__gnu_inline__))
+#endif
 #endif
 const char * libc_name_p (const char *, unsigned int);
 %}
diff --git a/gcc/cp/cfns.h b/gcc/cp/cfns.h
index 1c6665d..6d00c0e 100644
--- a/gcc/cp/cfns.h
+++ b/gcc/cp/cfns.h
@@ -53,6 +53,9 @@ __inline
 static unsigned int hash (const char *, unsigned int);
 #ifdef __GNUC__
 __inline
+#ifdef __GNUC_STDC_INLINE__
+__attribute__ ((__gnu_inline__))
+#endif
 #endif
 const char * libc_name_p (const char *, unsigned int);
 /* maximum key range = 391, duplicates = 0 */
--
2.4.4


code:
This is a backport of part of this patch from 6.5 to 4.8:

  https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=8937b94d1a643fd9760714642296d034a45254a8

--- a/libsanitizer/tsan/tsan_platform_linux.cc
+++ b/libsanitizer/tsan/tsan_platform_linux.cc
@@ -351,7 +351,7 @@ bool IsGlobalVar(uptr addr) {
 // closes within glibc. The code is a pure hack.
 int ExtractResolvFDs(void *state, int *fds, int nfd) {
   int cnt = 0;
-  __res_state *statp = (__res_state*)state;
+  struct __res_state *statp = (struct __res_state*)state;
   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
       fds[cnt++] = statp->_u._ext.nssocks[i];


code:
This is a backport of this patch from 6.5 to 4.9:

  https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=8937b94d1a643fd9760714642296d034a45254a8

diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cc b/libsanitizer/sanitizer_common/sanitizer_linux.cc
index 69c9c10..8e53673 100644
--- a/libsanitizer/sanitizer_common/sanitizer_linux.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_linux.cc
@@ -599,8 +599,7 @@ uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5) {
   return internal_syscall(__NR_prctl, option, arg2, arg3, arg4, arg5);
 }

-uptr internal_sigaltstack(const struct sigaltstack *ss,
-                         struct sigaltstack *oss) {
+uptr internal_sigaltstack(const void *ss, void *oss) {
   return internal_syscall(__NR_sigaltstack, (uptr)ss, (uptr)oss);
 }

diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.h b/libsanitizer/sanitizer_common/sanitizer_linux.h
index 6422df1..8a8e526 100644
--- a/libsanitizer/sanitizer_common/sanitizer_linux.h
+++ b/libsanitizer/sanitizer_common/sanitizer_linux.h
@@ -18,7 +18,6 @@
 #include "sanitizer_platform_limits_posix.h"

 struct link_map;  // Opaque type returned by dlopen().
-struct sigaltstack;

 namespace __sanitizer {
 // Dirent structure for getdents(). Note that this structure is different from
@@ -28,8 +27,7 @@ struct linux_dirent;
 // Syscall wrappers.
 uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
 uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5);
-uptr internal_sigaltstack(const struct sigaltstack* ss,
-                          struct sigaltstack* oss);
+uptr internal_sigaltstack(const void *ss, void *oss);
 uptr internal_sigaction(int signum, const __sanitizer_kernel_sigaction_t *act,
     __sanitizer_kernel_sigaction_t *oldact);
 uptr internal_sigprocmask(int how, __sanitizer_kernel_sigset_t *set,
diff --git a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
index 6ee63ec..50c21a3 100644
--- a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
@@ -238,7 +238,7 @@ static int TracerThread(void* argument) {

   // Alternate stack for signal handling.
   InternalScopedBuffer<char> handler_stack_memory(kHandlerStackSize);
-  struct sigaltstack handler_stack;
+  stack_t handler_stack;
   internal_memset(&handler_stack, 0, sizeof(handler_stack));
   handler_stack.ss_sp = handler_stack_memory.data();
   handler_stack.ss_size = kHandlerStackSize;
diff --git a/libsanitizer/tsan/tsan_platform_linux.cc b/libsanitizer/tsan/tsan_platform_linux.cc
index fe69430..49f5270 100644
--- a/libsanitizer/tsan/tsan_platform_linux.cc
+++ b/libsanitizer/tsan/tsan_platform_linux.cc
@@ -351,7 +351,7 @@ bool IsGlobalVar(uptr addr) {
 // closes within glibc. The code is a pure hack.
 int ExtractResolvFDs(void *state, int *fds, int nfd) {
   int cnt = 0;
-  __res_state *statp = (__res_state*)state;
+  struct __res_state *statp = (struct __res_state*)state;
   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
       fds[cnt++] = statp->_u._ext.nssocks[i];


code:
Fix assertion failure in libsanitizer when using glibc 2.31 and later.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92154
https://reviews.llvm.org/D69104

Adapted from these upstream revision:

https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=277981
https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=279653

diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
index 196eb3b3c64..b588e07e5ab 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -928,7 +928,11 @@ 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 !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
 CHECK_SIZE_AND_OFFSET(ipc_perm, __seq);

 CHECK_TYPE_SIZE(shmid_ds);
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
index aec950454b3..6d94fc65c28 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -154,20 +154,13 @@ namespace __sanitizer {
     u64 __unused1;
     u64 __unused2;
 #elif defined(__sparc__)
-# if defined(__arch64__)
     unsigned mode;
-    unsigned short __pad1;
-# else
-    unsigned short __pad1;
-    unsigned short mode;
     unsigned short __pad2;
-# endif
     unsigned short __seq;
     unsigned long long __unused1;
     unsigned long long __unused2;
 #else
-    unsigned short mode;
-    unsigned short __pad1;
+    unsigned int mode;
     unsigned short __seq;
     unsigned short __pad2;
 #if defined(__x86_64__) && !defined(_LP64)


code:
Remove use of deprecated ustat interface in glibc 2.28:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85835

Adapted to GCC 4 series from this upstream patch:
https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=260684

--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -81,7 +81,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>
@@ -163,7 +162,19 @@
   unsigned struct_old_utsname_sz = sizeof(struct old_utsname);
   unsigned struct_oldold_utsname_sz = sizeof(struct oldold_utsname);
   unsigned struct_itimerspec_sz = sizeof(struct itimerspec);
-  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;
 #endif // SANITIZER_LINUX

 #if SANITIZER_LINUX && !SANITIZER_ANDROID


code:
--- a/libgcc/config/i386/gthr-win32.h	2016-03-30 07:45:33.388684463 +0200
+++ b/libgcc/config/i386/gthr-win32.h	2016-03-30 15:51:24.123896436 +0200
@@ -30,7 +30,7 @@

 /* Make sure CONST_CAST2 (origin in system.h) is declared.  */
 #ifndef CONST_CAST2
-#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((__extension__(union {FROMTYPE _q; TOTYPE _nq;})(X))._nq)
+#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((TOTYPE)X)
 #endif

 /* Windows32 threads specific definitions. The windows32 threading model


code:
This patch is needed to build gcc-5.5.0 on the Hurd.

Backported from upstream: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=6cd9cb89ebdc1e1394b81c4a418c2b3b0eb86c57

commit b590b96ebc3f5b42a4829170e069722dd940e2543
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Sat May 9 04:50:23 2015 +0000

            * src/c++98/Makefile.am (AM_CXXFLAGS): Add -std=gnu++98.
            * src/c++98/Makefile.in: Regenerate.
            * src/Makefile.am (AM_CXXFLAGS): Add -std=gnu++98.
            * src/Makefile.in: Regenerate.

    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@222964 138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am
index a5f48b22c6d..cd07ccd81bc 100644
--- a/libstdc++-v3/src/Makefile.am
+++ b/libstdc++-v3/src/Makefile.am
@@ -168,6 +168,7 @@ compatibility-condvar.o: compatibility-condvar.cc
 # OPTIMIZE_CXXFLAGS on the compile line so that -O2 can be overridden
 # as the occasion calls for it.
 AM_CXXFLAGS = \
+	-std=gnu++98 \
 	$(glibcxx_compiler_pic_flag) \
 	$(XTEMPLATE_FLAGS) $(VTV_CXXFLAGS) \
 	$(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS)
diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in
index 433f9ea121a..31b56282e26 100644
--- a/libstdc++-v3/src/Makefile.in
+++ b/libstdc++-v3/src/Makefile.in
@@ -429,6 +429,7 @@ libstdc___la_LINK = $(CXXLINK) $(libstdc___la_LDFLAGS)
 # OPTIMIZE_CXXFLAGS on the compile line so that -O2 can be overridden
 # as the occasion calls for it.
 AM_CXXFLAGS = \
+	-std=gnu++98 \
 	$(glibcxx_compiler_pic_flag) \
 	$(XTEMPLATE_FLAGS) $(VTV_CXXFLAGS) \
 	$(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS)
diff --git a/libstdc++-v3/src/c++98/Makefile.am b/libstdc++-v3/src/c++98/Makefile.am
index e348dfb1205..a5b68a19a8b 100644
--- a/libstdc++-v3/src/c++98/Makefile.am
+++ b/libstdc++-v3/src/c++98/Makefile.am
@@ -215,6 +215,7 @@ parallel_settings.o: parallel_settings.cc
 # OPTIMIZE_CXXFLAGS on the compile line so that -O2 can be overridden
 # as the occasion calls for it.
 AM_CXXFLAGS = \
+	-std=gnu++98 \
 	$(glibcxx_lt_pic_flag) $(glibcxx_compiler_shared_flag) \
 	$(XTEMPLATE_FLAGS) $(VTV_CXXFLAGS) \
 	$(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS)
diff --git a/libstdc++-v3/src/c++98/Makefile.in b/libstdc++-v3/src/c++98/Makefile.in
index 3c69791bb66..ce86136906b 100644
--- a/libstdc++-v3/src/c++98/Makefile.in
+++ b/libstdc++-v3/src/c++98/Makefile.in
@@ -421,6 +421,7 @@ PARALLEL_FLAGS = -D_GLIBCXX_PARALLEL
 # OPTIMIZE_CXXFLAGS on the compile line so that -O2 can be overridden
 # as the occasion calls for it.
 AM_CXXFLAGS = \
+	-std=gnu++98 \
 	$(glibcxx_lt_pic_flag) $(glibcxx_compiler_shared_flag) \
 	$(XTEMPLATE_FLAGS) $(VTV_CXXFLAGS) \
 	$(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS)


code:
Make GCC respect SOURCE_DATE_EPOCH in __DATE__ and __TIME__ macros.

Patch adapted from upstream source repository:

https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=e3e8c48c4a494d9da741c1c8ea6c4c0b7c4ff934

From e3e8c48c4a494d9da741c1c8ea6c4c0b7c4ff934 Mon Sep 17 00:00:00 2001
From: doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 28 Apr 2016 09:12:05 +0000
Subject: [PATCH] gcc/c-family/ChangeLog:

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 1bf5d080034..6f0898a38d7 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -12318,4 +12318,37 @@ pointer_to_zero_sized_aggr_p (tree t)
   return (TYPE_SIZE (t) && integer_zerop (TYPE_SIZE (t)));
 }

+/* Read SOURCE_DATE_EPOCH from environment to have a deterministic
+   timestamp to replace embedded current dates to get reproducible
+   results.  Returns -1 if SOURCE_DATE_EPOCH is not defined.  */
+time_t
+get_source_date_epoch ()
+{
+  char *source_date_epoch;
+  long long epoch;
+  char *endptr;
+
+  source_date_epoch = getenv ("SOURCE_DATE_EPOCH");
+  if (!source_date_epoch)
+    return (time_t) -1;
+
+  errno = 0;
+  epoch = strtoll (source_date_epoch, &endptr, 10);
+  if ((errno == ERANGE && (epoch == LLONG_MAX || epoch == LLONG_MIN))
+      || (errno != 0 && epoch == 0))
+    fatal_error (UNKNOWN_LOCATION, "environment variable $SOURCE_DATE_EPOCH: "
+		 "strtoll: %s\n", xstrerror(errno));
+  if (endptr == source_date_epoch)
+    fatal_error (UNKNOWN_LOCATION, "environment variable $SOURCE_DATE_EPOCH: "
+		 "no digits were found: %s\n", endptr);
+  if (*endptr != '\0')
+    fatal_error (UNKNOWN_LOCATION, "environment variable $SOURCE_DATE_EPOCH: "
+		 "trailing garbage: %s\n", endptr);
+  if (epoch < 0)
+    fatal_error (UNKNOWN_LOCATION, "environment variable $SOURCE_DATE_EPOCH: "
+		 "value must be nonnegative: %lld \n", epoch);
+
+  return (time_t) epoch;
+}
+
 #include "gt-c-family-c-common.h"
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index fdb227f85c3..ba0a5d7df50 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1437,4 +1437,10 @@ extern bool contains_cilk_spawn_stmt (tree);
 extern tree cilk_for_number_of_iterations (tree);
 extern bool check_no_cilk (tree, const char *, const char *,
 		           location_t loc = UNKNOWN_LOCATION);
+
+/* Read SOURCE_DATE_EPOCH from environment to have a deterministic
+   timestamp to replace embedded current dates to get reproducible
+   results.  Returns -1 if SOURCE_DATE_EPOCH is not defined.  */
+extern time_t get_source_date_epoch (void);
+
 #endif /* ! GCC_C_COMMON_H */
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index bb55be8063e..e68471b9d2b 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -402,6 +402,9 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags,
   enum cpp_ttype type;
   unsigned char add_flags = 0;
   enum overflow_type overflow = OT_NONE;
+  time_t source_date_epoch = get_source_date_epoch ();
+
+  cpp_init_source_date_epoch (parse_in, source_date_epoch);

   timevar_push (TV_CPP);
  retry:
diff --git a/gcc/doc/cppenv.texi b/gcc/doc/cppenv.texi
index 100811dc637..3b5317beb53 100644
--- a/gcc/doc/cppenv.texi
+++ b/gcc/doc/cppenv.texi
@@ -79,4 +79,21 @@ main input file is omitted.
 @ifclear cppmanual
 @xref{Preprocessor Options}.
 @end ifclear
+
+@item SOURCE_DATE_EPOCH
+
+If this variable is set, its value specifies a UNIX timestamp to be
+used in replacement of the current date and time in the @code{__DATE__}
+and @code{__TIME__} macros, so that the embedded timestamps become
+reproducible.
+
+The value of @env{SOURCE_DATE_EPOCH} must be a UNIX timestamp,
+defined as the number of seconds (excluding leap seconds) since
+01 Jan 1970 00:00:00 represented in ASCII, identical to the output of
+@samp{@command{date +%s}}.
+
+The value should be a known timestamp such as the last modification
+time of the source or package and it should be set by the build
+process.
+
 @end vtable
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 1b731d1a3ad..7a5481219be 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -775,6 +775,9 @@ extern void cpp_init_special_builtins (cpp_reader *);
 /* Set up built-ins like __FILE__.  */
 extern void cpp_init_builtins (cpp_reader *, int);

+/* Initialize the source_date_epoch value.  */
+extern void cpp_init_source_date_epoch (cpp_reader *, time_t);
+
 /* This is called after options have been parsed, and partially
    processed.  */
 extern void cpp_post_options (cpp_reader *);
diff --git a/libcpp/init.c b/libcpp/init.c
index 45a4d13ffa3..a8d00f4628b 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -530,6 +530,13 @@ cpp_init_builtins (cpp_reader *pfile, int hosted)
     _cpp_define_builtin (pfile, "__OBJC__ 1");
 }

+/* Initialize the source_date_epoch value.  */
+void
+cpp_init_source_date_epoch (cpp_reader *pfile, time_t source_date_epoch)
+{
+  pfile->source_date_epoch = source_date_epoch;
+}
+
 /* Sanity-checks are dependent on command-line options, so it is
    called as a subroutine of cpp_read_main_file ().  */
 #if ENABLE_CHECKING
diff --git a/libcpp/internal.h b/libcpp/internal.h
index c2d08168945..8507eba1747 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -502,6 +502,10 @@ struct cpp_reader
   const unsigned char *date;
   const unsigned char *time;

+  /* Externally set timestamp to replace current date and time useful for
+     reproducibility.  */
+  time_t source_date_epoch;
+
   /* EOF token, and a token forcing paste avoidance.  */
   cpp_token avoid_paste;
   cpp_token eof;
diff --git a/libcpp/macro.c b/libcpp/macro.c
index eb32a6f8c98..3f3b278e97d 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -350,13 +350,20 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
 	  time_t tt;
 	  struct tm *tb = NULL;

-	  /* (time_t) -1 is a legitimate value for "number of seconds
-	     since the Epoch", so we have to do a little dance to
-	     distinguish that from a genuine error.  */
-	  errno = 0;
-	  tt = time(NULL);
-	  if (tt != (time_t)-1 || errno == 0)
-	    tb = localtime (&tt);
+	  /* Set a reproducible timestamp for __DATE__ and __TIME__ macro
+	     usage if SOURCE_DATE_EPOCH is defined.  */
+	  if (pfile->source_date_epoch != (time_t) -1)
+	     tb = gmtime (&pfile->source_date_epoch);
+	  else
+	    {
+	      /* (time_t) -1 is a legitimate value for "number of seconds
+		 since the Epoch", so we have to do a little dance to
+		 distinguish that from a genuine error.  */
+	      errno = 0;
+	      tt = time (NULL);
+	      if (tt != (time_t)-1 || errno == 0)
+		tb = localtime (&tt);
+	    }

 	  if (tb)
 	    {
--
2.11.0


code:
Continuation of the SOURCE_DATE_EPOCH patch.

Patch adapted from upstream source repository:

https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=dfa5c0d3f3e23e4fdb14857a42de376d9ff8601c

From dfa5c0d3f3e23e4fdb14857a42de376d9ff8601c Mon Sep 17 00:00:00 2001
From: doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 1 Jun 2016 16:42:41 +0000
Subject: [PATCH] gcc/c-family/ChangeLog:

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 6f0898a38d7..efbc78ef218 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -12321,8 +12321,9 @@ pointer_to_zero_sized_aggr_p (tree t)
 /* Read SOURCE_DATE_EPOCH from environment to have a deterministic
    timestamp to replace embedded current dates to get reproducible
    results.  Returns -1 if SOURCE_DATE_EPOCH is not defined.  */
+
 time_t
-get_source_date_epoch ()
+cb_get_source_date_epoch (cpp_reader *pfile ATTRIBUTE_UNUSED)
 {
   char *source_date_epoch;
   long long epoch;
@@ -12334,19 +12335,14 @@ get_source_date_epoch ()

   errno = 0;
   epoch = strtoll (source_date_epoch, &endptr, 10);
-  if ((errno == ERANGE && (epoch == LLONG_MAX || epoch == LLONG_MIN))
-      || (errno != 0 && epoch == 0))
-    fatal_error (UNKNOWN_LOCATION, "environment variable $SOURCE_DATE_EPOCH: "
-		 "strtoll: %s\n", xstrerror(errno));
-  if (endptr == source_date_epoch)
-    fatal_error (UNKNOWN_LOCATION, "environment variable $SOURCE_DATE_EPOCH: "
-		 "no digits were found: %s\n", endptr);
-  if (*endptr != '\0')
-    fatal_error (UNKNOWN_LOCATION, "environment variable $SOURCE_DATE_EPOCH: "
-		 "trailing garbage: %s\n", endptr);
-  if (epoch < 0)
-    fatal_error (UNKNOWN_LOCATION, "environment variable $SOURCE_DATE_EPOCH: "
-		 "value must be nonnegative: %lld \n", epoch);
+  if (errno != 0 || endptr == source_date_epoch || *endptr != '\0'
+      || epoch < 0 || epoch > MAX_SOURCE_DATE_EPOCH)
+    {
+      error_at (input_location, "environment variable SOURCE_DATE_EPOCH must "
+	        "expand to a non-negative integer less than or equal to %wd",
+		MAX_SOURCE_DATE_EPOCH);
+      return (time_t) -1;
+    }

   return (time_t) epoch;
 }
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index ba0a5d7df50..977ae9df5ea 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1063,6 +1063,16 @@ extern vec<tree, va_gc> *make_tree_vector_copy (const vec<tree, va_gc> *);
    c_register_builtin_type.  */
 extern GTY(()) tree registered_builtin_types;

+/* Read SOURCE_DATE_EPOCH from environment to have a deterministic
+   timestamp to replace embedded current dates to get reproducible
+   results.  Returns -1 if SOURCE_DATE_EPOCH is not defined.  */
+extern time_t cb_get_source_date_epoch (cpp_reader *pfile);
+
+/* The value (as a unix timestamp) corresponds to date
+   "Dec 31 9999 23:59:59 UTC", which is the latest date that __DATE__ and
+   __TIME__ can store.  */
+#define MAX_SOURCE_DATE_EPOCH HOST_WIDE_INT_C (253402300799)
+
 /* In c-gimplify.c  */
 extern void c_genericize (tree);
 extern int c_gimplify_expr (tree *, gimple_seq *, gimple_seq *);
@@ -1438,9 +1448,4 @@ extern tree cilk_for_number_of_iterations (tree);
 extern bool check_no_cilk (tree, const char *, const char *,
 		           location_t loc = UNKNOWN_LOCATION);

-/* Read SOURCE_DATE_EPOCH from environment to have a deterministic
-   timestamp to replace embedded current dates to get reproducible
-   results.  Returns -1 if SOURCE_DATE_EPOCH is not defined.  */
-extern time_t get_source_date_epoch (void);
-
 #endif /* ! GCC_C_COMMON_H */
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index e68471b9d2b..3f78073f640 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -97,6 +97,7 @@ init_c_lex (void)
   cb->valid_pch = c_common_valid_pch;
   cb->read_pch = c_common_read_pch;
   cb->has_attribute = c_common_has_attribute;
+  cb->get_source_date_epoch = cb_get_source_date_epoch;

   /* Set the debug callbacks if we can use them.  */
   if ((debug_info_level == DINFO_LEVEL_VERBOSE
@@ -402,9 +403,6 @@ c_lex_with_flags (tree *value, location_t *loc, unsigned char *cpp_flags,
   enum cpp_ttype type;
   unsigned char add_flags = 0;
   enum overflow_type overflow = OT_NONE;
-  time_t source_date_epoch = get_source_date_epoch ();
-
-  cpp_init_source_date_epoch (parse_in, source_date_epoch);

   timevar_push (TV_CPP);
  retry:
diff --git a/gcc/doc/cppenv.texi b/gcc/doc/cppenv.texi
index 3b5317beb53..7b4cf6adc11 100644
--- a/gcc/doc/cppenv.texi
+++ b/gcc/doc/cppenv.texi
@@ -81,7 +81,6 @@ main input file is omitted.
 @end ifclear

 @item SOURCE_DATE_EPOCH
-
 If this variable is set, its value specifies a UNIX timestamp to be
 used in replacement of the current date and time in the @code{__DATE__}
 and @code{__TIME__} macros, so that the embedded timestamps become
@@ -89,8 +88,9 @@ reproducible.

 The value of @env{SOURCE_DATE_EPOCH} must be a UNIX timestamp,
 defined as the number of seconds (excluding leap seconds) since
-01 Jan 1970 00:00:00 represented in ASCII, identical to the output of
-@samp{@command{date +%s}}.
+01 Jan 1970 00:00:00 represented in ASCII; identical to the output of
+@samp{@command{date +%s}} on GNU/Linux and other systems that support the
+@code{%s} extension in the @code{date} command.

 The value should be a known timestamp such as the last modification
 time of the source or package and it should be set by the build
diff --git a/gcc/gcc.c b/gcc/gcc.c
index d956c36b151..2709f295734 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -3328,6 +3328,29 @@ save_switch (const char *opt, size_t n_args, const char *const *args,
   n_switches++;
 }

+/* Set the SOURCE_DATE_EPOCH environment variable to the current time if it is
+   not set already.  */
+
+static void
+set_source_date_epoch_envvar ()
+{
+  /* Array size is 21 = ceil(log_10(2^64)) + 1 to hold string representations
+     of 64 bit integers.  */
+  char source_date_epoch[21];
+  time_t tt;
+
+  errno = 0;
+  tt = time (NULL);
+  if (tt < (time_t) 0 || errno != 0)
+    tt = (time_t) 0;
+
+  snprintf (source_date_epoch, 21, "%llu", (unsigned long long) tt);
+  /* Using setenv instead of xputenv because we want the variable to remain
+     after finalizing so that it's still set in the second run when using
+     -fcompare-debug.  */
+  setenv ("SOURCE_DATE_EPOCH", source_date_epoch, 0);
+}
+
 /* Handle an option DECODED that is unknown to the option-processing
    machinery.  */

@@ -3628,6 +3651,7 @@ driver_handle_option (struct gcc_options *opts,
       else
 	compare_debug_opt = arg;
       save_switch (compare_debug_replacement_opt, 0, NULL, validated, true);
+      set_source_date_epoch_envvar ();
       return true;

     case OPT_fdiagnostics_color_:
diff --git a/gcc/testsuite/gcc.dg/cpp/source_date_epoch-1.c b/gcc/testsuite/gcc.dg/cpp/source_date_epoch-1.c
new file mode 100644
index 00000000000..f6aa1a360ff
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/source_date_epoch-1.c
@@ -0,0 +1,11 @@
+/* { dg-do run } */
+/* { dg-set-compiler-env-var SOURCE_DATE_EPOCH "630333296" } */
+
+int
+main(void)
+{
+  __builtin_printf ("%s %s\n", __DATE__, __TIME__);
+  return 0;
+}
+
+/* { dg-output "^Dec 22 1989 12:34:56\n$" } */
diff --git a/gcc/testsuite/gcc.dg/cpp/source_date_epoch-2.c b/gcc/testsuite/gcc.dg/cpp/source_date_epoch-2.c
new file mode 100644
index 00000000000..ae18362ae87
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/source_date_epoch-2.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-set-compiler-env-var SOURCE_DATE_EPOCH "AAA" } */
+
+/* Make sure that SOURCE_DATE_EPOCH is only parsed once */
+
+int
+main(void)
+{
+  __builtin_printf ("%s %s\n", __DATE__, __TIME__); /* { dg-error "SOURCE_DATE_EPOCH must expand" } */
+  __builtin_printf ("%s %s\n", __DATE__, __TIME__);
+  return 0;
+}
diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp
index 4fa433d9954..7656b2254a1 100644
--- a/gcc/testsuite/lib/gcc-dg.exp
+++ b/gcc/testsuite/lib/gcc-dg.exp
@@ -324,6 +324,38 @@ proc restore-target-env-var { } {
     }
 }

+proc dg-set-compiler-env-var { args } {
+    global set_compiler_env_var
+    global saved_compiler_env_var
+    if { [llength $args] != 3 } {
+	error "dg-set-compiler-env-var: need two arguments"
+	return
+    }
+    set var [lindex $args 1]
+    set value [lindex $args 2]
+    if [info exists ::env($var)] {
+      lappend saved_compiler_env_var [list $var 1 $::env($var)]
+    } else {
+      lappend saved_compiler_env_var [list $var 0]
+    }
+    setenv $var $value
+    lappend set_compiler_env_var [list $var $value]
+}
+
+proc restore-compiler-env-var { } {
+    global saved_compiler_env_var
+    for { set env_vari [llength $saved_compiler_env_var] } {
+          [incr env_vari -1] >= 0 } {} {
+	set env_var [lindex $saved_compiler_env_var $env_vari]
+	set var [lindex $env_var 0]
+	if [lindex $env_var 1] {
+	    setenv $var [lindex $env_var 2]
+	} else {
+	    unsetenv $var
+	}
+    }
+}
+
 # Utility routines.

 #
@@ -785,6 +817,11 @@ if { [info procs saved-dg-test] == [list] } {
 	if [info exists set_target_env_var] {
 	    unset set_target_env_var
 	}
+	if [info exists set_compiler_env_var] {
+	    restore-compiler-env-var
+	    unset set_compiler_env_var
+	    unset saved_compiler_env_var
+	}
 	unset_timeout_vars
 	if [info exists compiler_conditional_xfail_data] {
 	    unset compiler_conditional_xfail_data
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 7a5481219be..867aeebc39f 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -585,6 +585,9 @@ struct cpp_callbacks

   /* Callback that can change a user builtin into normal macro.  */
   bool (*user_builtin_macro) (cpp_reader *, cpp_hashnode *);
+
+  /* Callback to parse SOURCE_DATE_EPOCH from environment.  */
+  time_t (*get_source_date_epoch) (cpp_reader *);
 };

 #ifdef VMS
@@ -775,9 +778,6 @@ extern void cpp_init_special_builtins (cpp_reader *);
 /* Set up built-ins like __FILE__.  */
 extern void cpp_init_builtins (cpp_reader *, int);

-/* Initialize the source_date_epoch value.  */
-extern void cpp_init_source_date_epoch (cpp_reader *, time_t);
-
 /* This is called after options have been parsed, and partially
    processed.  */
 extern void cpp_post_options (cpp_reader *);
diff --git a/libcpp/init.c b/libcpp/init.c
index a8d00f4628b..61c9bbbf945 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -254,6 +254,9 @@ cpp_create_reader (enum c_lang lang, cpp_hash_table *table,
   /* Do not force token locations by default.  */
   pfile->forced_token_location_p = NULL;

+  /* Initialize source_date_epoch to -2 (not yet set).  */
+  pfile->source_date_epoch = (time_t) -2;
+
   /* The expression parser stack.  */
   _cpp_expand_op_stack (pfile);

@@ -530,13 +533,6 @@ cpp_init_builtins (cpp_reader *pfile, int hosted)
     _cpp_define_builtin (pfile, "__OBJC__ 1");
 }

-/* Initialize the source_date_epoch value.  */
-void
-cpp_init_source_date_epoch (cpp_reader *pfile, time_t source_date_epoch)
-{
-  pfile->source_date_epoch = source_date_epoch;
-}
-
 /* Sanity-checks are dependent on command-line options, so it is
    called as a subroutine of cpp_read_main_file ().  */
 #if ENABLE_CHECKING
diff --git a/libcpp/internal.h b/libcpp/internal.h
index 8507eba1747..226ae328e76 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -503,7 +503,8 @@ struct cpp_reader
   const unsigned char *time;

   /* Externally set timestamp to replace current date and time useful for
-     reproducibility.  */
+     reproducibility.  It should be initialized to -2 (not yet set) and
+     set to -1 to disable it or to a non-negative value to enable it.  */
   time_t source_date_epoch;

   /* EOF token, and a token forcing paste avoidance.  */
diff --git a/libcpp/macro.c b/libcpp/macro.c
index 3f3b278e97d..756c7c6e0c6 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -351,9 +351,13 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
 	  struct tm *tb = NULL;

 	  /* Set a reproducible timestamp for __DATE__ and __TIME__ macro
-	     usage if SOURCE_DATE_EPOCH is defined.  */
-	  if (pfile->source_date_epoch != (time_t) -1)
-	     tb = gmtime (&pfile->source_date_epoch);
+	     if SOURCE_DATE_EPOCH is defined.  */
+	  if (pfile->source_date_epoch == (time_t) -2
+	      && pfile->cb.get_source_date_epoch != NULL)
+	    pfile->source_date_epoch = pfile->cb.get_source_date_epoch (pfile);
+
+	  if (pfile->source_date_epoch >= (time_t) 0)
+	    tb = gmtime (&pfile->source_date_epoch);
 	  else
 	    {
 	      /* (time_t) -1 is a legitimate value for "number of seconds
--
2.11.0


code:
GCC 4.9 and later have libvtv and, just like libstdc++ (see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32354), it doesn't
have $libdir in its RUNPATH, but it NEEDs libgcc_s.  This patch
fixes that.

--- gcc-5.1.0/libvtv/Makefile.in	2014-10-30 09:28:58.000000000 +0100
+++ gcc-5.1.0/libvtv/Makefile.in	2015-04-30 09:51:04.161129705 +0200
@@ -15,6 +15,7 @@

 @SET_MAKE@

+libvtv_la_LDFLAGS = -Wl,-rpath=$(libdir)

 VPATH = @srcdir@
 pkgdatadir = $(datadir)/@PACKAGE@


code:
From Anatol Pomozov <anatol.pomozov@gmail.com>
Taken from Arch Linux arm-none-eabi-gcc package.

Modified version of ARM patch https://gcc.gnu.org/ml/gcc-patches/2012-05/msg00083/enable-with-multilib-list-for-arm.patch

This patch enables the use of the "--with-multilib-list" flag, when
configuring GCC 6.2.  It makes GCC 6 compatible with the configure flags used
in the "gcc-arm-none-eabi-4.9" package.

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 4ab7405..6e1ea2c 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -535,6 +535,7 @@ lang_opt_files=@lang_opt_files@ $(srcdir)/c-family/c.opt $(srcdir)/common.opt
 lang_specs_files=@lang_specs_files@
 lang_tree_files=@lang_tree_files@
 target_cpu_default=@target_cpu_default@
+with_multilib_list=@with_multilib_list@
 OBJC_BOEHM_GC=@objc_boehm_gc@
 extra_modes_file=@extra_modes_file@
 extra_opt_files=@extra_opt_files@
diff --git a/gcc/config.gcc b/gcc/config.gcc
index cb08a5c..7bded02 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1072,7 +1072,7 @@ arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtems*)
 	case ${target} in
 	arm*-*-eabi*)
 	  tm_file="$tm_file newlib-stdint.h"
-	  tmake_file="${tmake_file} arm/t-bpabi"
+	  tmake_file="${tmake_file} arm/t-bpabi arm/t-mlibs"
 	  use_gcc_stdint=wrap
 	  ;;
 	arm*-*-rtems*)
@@ -3684,42 +3684,6 @@ case "${target}" in
 			exit 1
 		fi

-		# Add extra multilibs
-		if test "x$with_multilib_list" != x; then
-			arm_multilibs=`echo $with_multilib_list | sed -e 's/,/ /g'`
-			for arm_multilib in ${arm_multilibs}; do
-				case ${arm_multilib} in
-				aprofile)
-				# Note that arm/t-aprofile is a
-				# stand-alone make file fragment to be
-				# used only with itself.  We do not
-				# specifically use the
-				# TM_MULTILIB_OPTION framework because
-				# this shorthand is more
-				# pragmatic. Additionally it is only
-				# designed to work without any
-				# with-cpu, with-arch with-mode
-				# with-fpu or with-float options.
-					if test "x$with_arch" != x \
-					    || test "x$with_cpu" != x \
-					    || test "x$with_float" != x \
-					    || test "x$with_fpu" != x \
-					    || test "x$with_mode" != x ; then
-					    echo "Error: You cannot use any of --with-arch/cpu/fpu/float/mode with --with-multilib-list=aprofile" 1>&2
-					    exit 1
-					fi
-					tmake_file="${tmake_file} arm/t-aprofile"
-					break
-					;;
-				default)
-					;;
-				*)
-					echo "Error: --with-multilib-list=${with_multilib_list} not supported." 1>&2
-					exit 1
-					;;
-				esac
-			done
-		fi
 		;;

 	fr*-*-*linux*)
diff --git a/gcc/config/arm/t-mlibs b/gcc/config/arm/t-mlibs
new file mode 100644
index 0000000..5720cf7
--- /dev/null
+++ b/gcc/config/arm/t-mlibs
@@ -0,0 +1,89 @@
+# A set of predefined MULTILIB which can be used for different ARM targets.
+# Via the configure option --with-multilib-list, user can customize the
+# final MULTILIB implementation.
+
+comma := ,
+space :=
+space +=
+
+MULTILIB_OPTIONS   = mthumb/marm
+MULTILIB_DIRNAMES  = thumb arm
+MULTILIB_OPTIONS  += march=armv6s-m/march=armv7-m/march=armv7e-m/march=armv7
+MULTILIB_DIRNAMES += armv6-m armv7-m armv7e-m armv7-ar
+MULTILIB_OPTIONS  += mfloat-abi=softfp/mfloat-abi=hard
+MULTILIB_DIRNAMES += softfp fpu
+MULTILIB_OPTIONS  += mfpu=fpv4-sp-d16/mfpu=vfpv3-d16
+MULTILIB_DIRNAMES += fpv4-sp-d16 vfpv3-d16
+
+MULTILIB_MATCHES   = march?armv6s-m=mcpu?cortex-m0
+MULTILIB_MATCHES  += march?armv6s-m=mcpu?cortex-m0plus
+MULTILIB_MATCHES  += march?armv6s-m=mcpu?cortex-m1
+MULTILIB_MATCHES  += march?armv6s-m=march?armv6-m
+MULTILIB_MATCHES  += march?armv7-m=mcpu?cortex-m3
+MULTILIB_MATCHES  += march?armv7e-m=mcpu?cortex-m4
+MULTILIB_MATCHES  += march?armv7e-m=mcpu?cortex-m7
+MULTILIB_MATCHES  += march?armv7=march?armv7-r
+MULTILIB_MATCHES  += march?armv7=march?armv7-a
+MULTILIB_MATCHES  += march?armv7=mcpu?cortex-r4
+MULTILIB_MATCHES  += march?armv7=mcpu?cortex-r4f
+MULTILIB_MATCHES  += march?armv7=mcpu?cortex-r5
+MULTILIB_MATCHES  += march?armv7=mcpu?cortex-r7
+MULTILIB_MATCHES  += march?armv7=mcpu?cortex-a5
+MULTILIB_MATCHES  += march?armv7=mcpu?cortex-a7
+MULTILIB_MATCHES  += march?armv7=mcpu?cortex-a8
+MULTILIB_MATCHES  += march?armv7=mcpu?cortex-a9
+MULTILIB_MATCHES  += march?armv7=mcpu?cortex-a15
+MULTILIB_MATCHES  += mfpu?fpv4-sp-d16=mfpu?fpv5-sp-d16
+MULTILIB_MATCHES  += mfpu?fpv4-sp-d16=mfpu?fpv5-d16
+MULTILIB_MATCHES  += mfpu?vfpv3-d16=mfpu?vfpv3
+MULTILIB_MATCHES  += mfpu?vfpv3-d16=mfpu?vfpv3-fp16
+MULTILIB_MATCHES  += mfpu?vfpv3-d16=mfpu?vfpv3-d16-fp16
+MULTILIB_MATCHES  += mfpu?vfpv3-d16=mfpu?vfpv3xd
+MULTILIB_MATCHES  += mfpu?vfpv3-d16=mfpu?vfpv3xd-fp16
+MULTILIB_MATCHES  += mfpu?vfpv3-d16=mfpu?vfpv4
+MULTILIB_MATCHES  += mfpu?vfpv3-d16=mfpu?vfpv4-d16
+MULTILIB_MATCHES  += mfpu?vfpv3-d16=mfpu?neon
+MULTILIB_MATCHES  += mfpu?vfpv3-d16=mfpu?neon-fp16
+MULTILIB_MATCHES  += mfpu?vfpv3-d16=mfpu?neon-vfpv4
+
+MULTILIB_EXCEPTIONS =
+MULTILIB_REUSE =
+
+MULTILIB_REQUIRED  = mthumb
+MULTILIB_REQUIRED += marm
+MULTILIB_REQUIRED += mfloat-abi=hard
+
+MULTILIB_OSDIRNAMES  = mthumb=!thumb
+MULTILIB_OSDIRNAMES += marm=!arm
+MULTILIB_OSDIRNAMES += mfloat-abi.hard=!fpu
+
+ifneq (,$(findstring armv6-m,$(subst $(comma),$(space),$(with_multilib_list))))
+MULTILIB_REQUIRED   += mthumb/march=armv6s-m
+MULTILIB_OSDIRNAMES += mthumb/march.armv6s-m=!armv6-m
+endif
+
+ifneq (,$(findstring armv7-m,$(subst $(comma),$(space),$(with_multilib_list))))
+MULTILIB_REQUIRED   += mthumb/march=armv7-m
+MULTILIB_OSDIRNAMES += mthumb/march.armv7-m=!armv7-m
+endif
+
+ifneq (,$(findstring armv7e-m,$(subst $(comma),$(space),$(with_multilib_list))))
+MULTILIB_REQUIRED   += mthumb/march=armv7e-m
+MULTILIB_REQUIRED   += mthumb/march=armv7e-m/mfloat-abi=softfp/mfpu=fpv4-sp-d16
+MULTILIB_REQUIRED   += mthumb/march=armv7e-m/mfloat-abi=hard/mfpu=fpv4-sp-d16
+MULTILIB_OSDIRNAMES += mthumb/march.armv7e-m=!armv7e-m
+MULTILIB_OSDIRNAMES += mthumb/march.armv7e-m/mfloat-abi.hard/mfpu.fpv4-sp-d16=!armv7e-m/fpu
+MULTILIB_OSDIRNAMES += mthumb/march.armv7e-m/mfloat-abi.softfp/mfpu.fpv4-sp-d16=!armv7e-m/softfp
+endif
+
+ifneq (,$(filter armv7 armv7-r armv7-a,$(subst $(comma),$(space),$(with_multilib_list))))
+MULTILIB_REQUIRED   += mthumb/march=armv7
+MULTILIB_REQUIRED   += mthumb/march=armv7/mfloat-abi=softfp/mfpu=vfpv3-d16
+MULTILIB_REQUIRED   += mthumb/march=armv7/mfloat-abi=hard/mfpu=vfpv3-d16
+MULTILIB_OSDIRNAMES += mthumb/march.armv7=!armv7-ar/thumb
+MULTILIB_OSDIRNAMES += mthumb/march.armv7/mfloat-abi.hard/mfpu.vfpv3-d16=!armv7-ar/thumb/fpu
+MULTILIB_OSDIRNAMES += mthumb/march.armv7/mfloat-abi.softfp/mfpu.vfpv3-d16=!armv7-ar/thumb/softfp
+MULTILIB_REUSE      += mthumb/march.armv7=marm/march.armv7
+MULTILIB_REUSE      += mthumb/march.armv7/mfloat-abi.softfp/mfpu.vfpv3-d16=marm/march.armv7/mfloat-abi.softfp/mfpu.vfpv3-d16
+MULTILIB_REUSE      += mthumb/march.armv7/mfloat-abi.hard/mfpu.vfpv3-d16=marm/march.armv7/mfloat-abi.hard/mfpu.vfpv3-d16
+endif
diff --git a/gcc/configure b/gcc/configure
index 9523773..24952e3 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -763,6 +763,7 @@ SET_MAKE
 accel_dir_suffix
 real_target_noncanonical
 enable_as_accelerator
+with_multilib_list
 REPORT_BUGS_TEXI
 REPORT_BUGS_TO
 PKGVERSION
@@ -7462,6 +7463,7 @@ else
 fi

+
 # -------------------------
 # Checks for other programs
 # -------------------------
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 68b0ee8..f8a1097 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -925,6 +925,7 @@ AC_ARG_WITH(multilib-list,
 [AS_HELP_STRING([--with-multilib-list], [select multilibs (AArch64, SH and x86-64 only)])],
 :,
 with_multilib_list=default)
+AC_SUBST(with_multilib_list)

 # -------------------------
 # Checks for other programs


code:
Search path environment variables for cross-compilers.  See the discussion
at <http://gcc.gnu.org/ml/gcc/2013-02/msg00124.html>.

Note: Touch 'C_INCLUDE_PATH' et al. rather than 'CPATH', as discussed
at <http://bugs.gnu.org/22186>.

--- a/gcc/incpath.c
+++ b/gcc/incpath.c
@@ -461,8 +461,8 @@ register_include_chains (cpp_reader *pfile, const char *sysroot,
 			 int stdinc, int cxx_stdinc, int verbose)
 {
   static const char *const lang_env_vars[] =
-    { "C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH",
-      "OBJC_INCLUDE_PATH", "OBJCPLUS_INCLUDE_PATH" };
+    { "CROSS_C_INCLUDE_PATH", "CROSS_CPLUS_INCLUDE_PATH",
+      "CROSS_OBJC_INCLUDE_PATH", "CROSS_OBJCPLUS_INCLUDE_PATH" };
   cpp_options *cpp_opts = cpp_get_options (pfile);
   size_t idx = (cpp_opts->objc ? 2: 0);

@@ -473,7 +473,7 @@ register_include_chains (cpp_reader *pfile, const char *sysroot,

   /* CPATH and language-dependent environment variables may add to the
      include chain.  */
-  add_env_var_paths ("CPATH", BRACKET);
+  add_env_var_paths ("CROSS_CPATH", BRACKET);
   add_env_var_paths (lang_env_vars[idx], SYSTEM);

   target_c_incpath.extra_pre_includes (sysroot, iprefix, stdinc);
diff --git a/gcc/system.h b/gcc/system.h
index 42bc509..af3b9ad 100644
--- a/gcc/system.h
+++ b/gcc/system.h
@@ -1063,4 +1063,6 @@ helper_const_non_const_cast (const char *p)
 /* Get definitions of HOST_WIDE_INT and HOST_WIDEST_INT.  */
 #include "hwint.h"

+#define LIBRARY_PATH_ENV "CROSS_LIBRARY_PATH"
+
 #endif /* ! GCC_SYSTEM_H */
diff --git a/gcc/tlink.c b/gcc/tlink.c
index bc358b8..ad6242f 100644
--- a/gcc/tlink.c
+++ b/gcc/tlink.c
@@ -458,7 +458,7 @@ recompile_files (void)
   file *f;

   putenv (xstrdup ("COMPILER_PATH="));
-  putenv (xstrdup ("LIBRARY_PATH="));
+  putenv (xstrdup (LIBRARY_PATH_ENV "="));

   while ((f = file_pop ()) != NULL)
     {
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 0f042b0..c23fb0b 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -4264,7 +4264,7 @@ process_command (unsigned int decoded_options_count,
     }

   temp = env.get (LIBRARY_PATH_ENV);
-  if (temp && *cross_compile == '0')
+  if (temp)
     {
       const char *startp, *endp;
       char *nstore = (char *) alloca (strlen (temp) + 3);


code:
Fixes a possible buffer overflow.  (There are others)
Author: Danny Milosavljevic <dannym@scratchpost.org>
Date: 2020-11-16

--- a/gcc/gimplify.c.orig	2020-10-29 08:45:11.532479774 +0100
+++ b/gcc/gimplify.c	2020-10-29 08:45:49.584637018 +0100
@@ -5229,7 +5229,7 @@
 	     flexibility, split it into separate input and output
  	     operands.  */
 	  tree input;
-	  char buf[10];
+	  char buf[12];

 	  /* Turn the in/out constraint into an output constraint.  */
 	  char *p = xstrdup (constraint);


code:
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86724
Author: Rainer Jung
Date: 2018-07-29

isl 0.20 stopped including other unused header files in their header files.
Therefore,now it's necessary to include the stuff ourselves.
--- .../gcc/graphite.h 2018-01-03 11:03:58.000000000 +0000
+++ .../gcc/graphite.h 2018-07-29 17:42:55.836121000 +0000
@@ -37,6 +37,8 @@
 #include <isl/schedule.h>
 #include <isl/ast_build.h>
 #include <isl/schedule_node.h>
+#include <isl/id.h>
+#include <isl/space.h>

 typedef struct poly_dr *poly_dr_p;


code:
Fix assertion failure in libsanitizer when using glibc 2.31 and later.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92154
https://reviews.llvm.org/D69104

Adapted from these upstream revision:

https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=277981
https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=279653

diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
index 069d8d557de..c49c28c6e07 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ b/libsanitizer/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/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
index 304d04e3935..6dee89c97e1 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -207,20 +207,13 @@ namespace __sanitizer {
     unsigned long __unused1;
     unsigned long __unused2;
 #elif defined(__sparc__)
-# if defined(__arch64__)
     unsigned mode;
-    unsigned short __pad1;
-# else
-    unsigned short __pad1;
-    unsigned short mode;
     unsigned short __pad2;
-# endif
     unsigned short __seq;
     unsigned long long __unused1;
     unsigned long long __unused2;
 #else
-    unsigned short mode;
-    unsigned short __pad1;
+    unsigned int mode;
     unsigned short __seq;
     unsigned short __pad2;
 #if defined(__x86_64__) && !defined(_LP64)