During linking is reported a lot of mismatches between declarations and actual use of some types (-Wlto-type-mismatch) and it is causing that LTO is disabled automatically during linking. Belw it is only beginning of very long list. gcc -DHAVE_MKSTEMP -DHAVE_FILE64 -DHAVE_FSEEKO -DHAVE_MKSTEMP64 -DHAVE_FONTCONFIG -DHAVE_SETLOCALE -DHAVE_SSE2 -DHAVE_DBUS -DHAVE_BSWAP32 -DHAVE_BYTESWAP_H -DHAVE_STRERROR -DHAVE_ISNAN -DHAVE_ISINF -DHAVE_PREAD_PWRITE=1 -DGS_RECURSIVE_MUTEXATTR=PTHREAD_MUTEX_RECURSIVE -fPIC -O2 -Wall -Wstrict-prototypes -Wundef -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings -fno-strict-aliasing -Werror=declaration-after-statement -fno-builtin -fno-common -Werror=return-type -DHAVE_STDINT_H=1 -DHAVE_DIRENT_H=1 -DHAVE_SYS_DIR_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_LIBDL=1 -DGX_COLOR_INDEX_TYPE="unsigned long long" -D__USE_UNIX98=1 -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -flto=auto -flto-partition=none -DHAVE_RESTRICT=1 -DUSE_LIBPAPER -fno-strict-aliasing -DHAVE_POPEN_PROTO=1 -DGS_DEVS_SHARED -DGS_DEVS_SHARED_DIR=\"/usr/lib64/ghostscript\" -I./obj -I./base -I./devices -DWHICH_CMS="lcms2" -o ./obj/gscdefs.o -c ./obj/gscdefs.c gcc -DHAVE_MKSTEMP -DHAVE_FILE64 -DHAVE_FSEEKO -DHAVE_MKSTEMP64 -DHAVE_FONTCONFIG -DHAVE_SETLOCALE -DHAVE_SSE2 -DHAVE_DBUS -DHAVE_BSWAP32 -DHAVE_BYTESWAP_H -DHAVE_STRERROR -DHAVE_ISNAN -DHAVE_ISINF -DHAVE_PREAD_PWRITE=1 -DGS_RECURSIVE_MUTEXATTR=PTHREAD_MUTEX_RECURSIVE -fPIC -O2 -Wall -Wstrict-prototypes -Wundef -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings -fno-strict-aliasing -Werror=declaration-after-statement -fno-builtin -fno-common -Werror=return-type -DHAVE_STDINT_H=1 -DHAVE_DIRENT_H=1 -DHAVE_SYS_DIR_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_LIBDL=1 -DGX_COLOR_INDEX_TYPE="unsigned long long" -D__USE_UNIX98=1 -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -flto=auto -flto-partition=none -DHAVE_RESTRICT=1 -DUSE_LIBPAPER -fno-strict-aliasing -DHAVE_POPEN_PROTO=1 -DGS_DEVS_SHARED -DGS_DEVS_SHARED_DIR=\"/usr/lib64/ghostscript\" -I./obj -I./base -I./devices -DWHICH_CMS="lcms2" -o ./obj/gsromfs0.o -c ./base/gsromfs0.c ./obj/aux/echogs -w ./obj/ldt.tr -n - gcc -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -flto=auto -flto-partition=none -fuse-linker-plugin -o ./bin/gs ./obj/aux/echogs -a ./obj/ldt.tr -n -s ./obj/gsromfs0.o ./obj/gs.o -s cat ./obj/gsld.tr >> ./obj/ldt.tr ./obj/aux/echogs -a ./obj/ldt.tr -s - -lm -ldl -lpaper -ltiff -rdynamic -lfontconfig -lfreetype -lfreetype -lopenjp2 -lpthread -lm if [ x != x ]; then LD_RUN_PATH=; export LD_RUN_PATH; fi; \ XCFLAGS= XINCLUDE= XLDFLAGS= XLIBDIRS= XLIBS= \ PSI_FEATURE_DEVS= FEATURE_DEVS= DEVICE_DEVS= DEVICE_DEVS1= DEVICE_DEVS2= DEVICE_DEVS3= \ DEVICE_DEVS4= DEVICE_DEVS5= DEVICE_DEVS6= DEVICE_DEVS7= DEVICE_DEVS8= \ DEVICE_DEVS9= DEVICE_DEVS10= DEVICE_DEVS11= DEVICE_DEVS12= \ DEVICE_DEVS13= DEVICE_DEVS14= DEVICE_DEVS15= DEVICE_DEVS16= \ DEVICE_DEVS17= DEVICE_DEVS18= DEVICE_DEVS19= DEVICE_DEVS20= \ DEVICE_DEVS_EXTRA= \ /bin/sh <./obj/ldt.tr ./obj/gconfig.h:427:1: warning: type of ‘gs_nullpage_device’ does not match original declaration [-Wlto-type-mismatch] 427 | device2_(gs_nullpage_device) | ^ ./base/gdevnfwd.c:1153:22: note: type ‘const struct gx_device_null’ should match type ‘const struct gx_device’ 1153 | const gx_device_null gs_nullpage_device = { | ^ ./base/gdevnfwd.c:1153:22: note: ‘gs_nullpage_device’ was previously declared here ./obj/gconfig.h:425:1: warning: type of ‘gs_pngmono_device’ does not match original declaration [-Wlto-type-mismatch] 425 | device2_(gs_pngmono_device) | ^ ./devices/gdevpng.c:92:21: note: type ‘const struct gx_device_png’ should match type ‘const struct gx_device’ 92 | const gx_device_png gs_pngmono_device = | ^ ./devices/gdevpng.c:92:21: note: ‘gs_pngmono_device’ was previously declared here ./obj/gconfig.h:419:1: warning: type of ‘gs_png16_device’ does not match original declaration [-Wlto-type-mismatch] 419 | device2_(gs_png16_device) | ^ ./devices/gdevpng.c:109:21: note: type ‘const struct gx_device_png’ should match type ‘const struct gx_device’ 109 | const gx_device_png gs_png16_device = { | ^ ./devices/gdevpng.c:109:21: note: ‘gs_png16_device’ was previously declared here ./obj/gconfig.h:421:1: warning: type of ‘gs_png256_device’ does not match original declaration [-Wlto-type-mismatch] 421 | device2_(gs_png256_device) | ^ ./devices/gdevpng.c:125:21: note: type ‘const struct gx_device_png’ should match type ‘const struct gx_device’ 125 | const gx_device_png gs_png256_device = { | ^ ./devices/gdevpng.c:125:21: note: ‘gs_png256_device’ was previously declared here ./obj/gconfig.h:424:1: warning: type of ‘gs_pnggray_device’ does not match original declaration [-Wlto-type-mismatch] 424 | device2_(gs_pnggray_device) | ^ ./devices/gdevpng.c:142:21: note: type ‘const struct gx_device_png’ should match type ‘const struct gx_device’ 142 | const gx_device_png gs_pnggray_device = | ^ ./devices/gdevpng.c:142:21: note: ‘gs_pnggray_device’ was previously declared here ./obj/gconfig.h:426:1: warning: type of ‘gs_pngmonod_device’ does not match original declaration [-Wlto-type-mismatch] 426 | device2_(gs_pngmonod_device) | ^ ./devices/gdevpng.c:160:21: note: type ‘const struct gx_device_png’ should match type ‘const struct gx_device’ 160 | const gx_device_png gs_pngmonod_device = | ^ ./devices/gdevpng.c:160:21: note: ‘gs_pngmonod_device’ was previously declared here ./obj/gconfig.h:420:1: warning: type of ‘gs_png16m_device’ does not match original declaration [-Wlto-type-mismatch] 420 | device2_(gs_png16m_device) | ^ ./devices/gdevpng.c:177:21: note: type ‘const struct gx_device_png’ should match type ‘const struct gx_device’ 177 | const gx_device_png gs_png16m_device = | ^ ./devices/gdevpng.c:177:21: note: ‘gs_png16m_device’ was previously declared here ./obj/gconfig.h:422:1: warning: type of ‘gs_png48_device’ does not match original declaration [-Wlto-type-mismatch] 422 | device2_(gs_png48_device) | ^ ./devices/gdevpng.c:192:21: note: type ‘const struct gx_device_png’ should match type ‘const struct gx_device’ 192 | const gx_device_png gs_png48_device = | ^ ./devices/gdevpng.c:192:21: note: ‘gs_png48_device’ was previously declared here
There is, basically, no prospect of Ghostcript ever being compatible with LTO. Ghostscript relies heavily on it's own version of (sort of) polymorphism implemented in C, and it's that which causes most of errors. Frankly, we are unlikely to undertake a large scale rewrite of Ghostscript and its associated products in order to support LTO.
All LTO warnings are related to mismatching declarations.