Repository: godot
Issue: [3.x] Linking warnings in official builds with LTO (`-Wstringop-overflow=` and `-Wattributes`)
Labels: bug,topic:core,topic:buildsystem,topic:thirdparty

### Godot version

3.x (52df2940bc3e8dfbe97bd2029badb831d772257c)

### System information

Fedora 34 host, multiple target platforms

### Issue description

When building official builds with https://github.com/godotengine/godot-build-scripts with LTO, I get a number of linking warnings. This is not new and doesn't prevent linking, but I'm finally taking time to list them so that we can see if they're fixable.

## Windows MinGW GCC 10

### Editor 64-bit release_debug

```
x86_64-w64-mingw32-g++ -o bin/godot.windows.opt.tools.64.exe -static -flto=64 -Wl,--stack,8388608 -Wl,--nxcompat platform/windows/godot_windows.windows.opt.tools.64.o platform/windows/context_gl_windows.windows.
opt.tools.64.o platform/windows/crash_handler_windows.windows.opt.tools.64.o platform/windows/os_windows.windows.opt.tools.64.o platform/windows/key_mapping_windows.windows.opt.tools.64.o platform/windows/joypad
_windows.windows.opt.tools.64.o platform/windows/power_windows.windows.opt.tools.64.o platform/windows/windows_terminal_logger.windows.opt.tools.64.o platform/windows/godot_res.windows.opt.tools.64.o main/libmai
n.windows.opt.tools.64.a main/tests/libtests.windows.opt.tools.64.a modules/libmodules.windows.opt.tools.64.a platform/libplatform.windows.opt.tools.64.a drivers/libdrivers.windows.opt.tools.64.a editor/libedito
r.windows.opt.tools.64.a scene/libscene.windows.opt.tools.64.a servers/libservers.windows.opt.tools.64.a core/libcore.windows.opt.tools.64.a modules/freetype/libfreetype_builtin.windows.opt.tools.64.a -lmingw32 
-lopengl32 -ldsound -lole32 -ld3d9 -lwinmm -lgdi32 -liphlpapi -lshlwapi -lwsock32 -lws2_32 -lkernel32 -loleaut32 -ldinput8 -ldxguid -lksuser -limm32 -lbcrypt -lavrt -luuid -ldwmapi -lpsapi
thirdparty/miniupnpc/miniupnpc/miniupnpc.c: In function 'GetUPNPUrls':
thirdparty/miniupnpc/miniupnpc/miniupnpc.c:496:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
  496 | }
      | ^
thirdparty/miniupnpc/miniupnpc/upnpcommands.c: In function 'UPNP_GetExternalIPAddress':
thirdparty/miniupnpc/miniupnpc/upnpcommands.c:336:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
  336 | }
      | ^
thirdparty/zstd/compress/zstd_compress.c: In function 'ZSTD_cParam_getBounds':
thirdparty/zstd/compress/zstd_compress.c:475:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
  475 | }
      | ^
thirdparty/jpeg-compressor/jpgd.cpp: In member function 'make_huff_table':
thirdparty/jpeg-compressor/jpgd.cpp:2300:15: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
 2300 |   huffsize[p] = 0;
      |               ^
thirdparty/jpeg-compressor/jpgd.cpp:2276:9: note: at offset [0, 2147483646] to object 'huffsize' with size 258 declared here
 2276 |   uint8 huffsize[258];
      |         ^
thirdparty/libwebp/src/enc/picture_enc.c: In function 'WebPMemoryWrite':
thirdparty/libwebp/src/enc/picture_enc.c:216:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
  216 | }
      | ^
thirdparty/libwebp/src/utils/utils.c: In function 'WebPSafeMalloc':
thirdparty/libwebp/src/utils/utils.c:199:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
  199 | }
      | ^
thirdparty/libwebp/src/enc/config_enc.c: In function 'WebPValidateConfig':
thirdparty/libwebp/src/enc/config_enc.c:129:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
  129 | }
      | ^
thirdparty/libwebp/src/enc/picture_enc.c: In function 'WebPPictureAlloc':
thirdparty/libwebp/src/enc/picture_enc.c:167:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
  167 | }
      | ^
thirdparty/libwebp/src/enc/picture_csp_enc.c: In function 'WebPPictureImportRGB':
thirdparty/libwebp/src/enc/picture_csp_enc.c:1194:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
 1194 | }
      | ^
thirdparty/libwebp/src/enc/picture_csp_enc.c: In function 'WebPPictureImportRGBA':
thirdparty/libwebp/src/enc/picture_csp_enc.c:1201:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
 1201 | }
      | ^
At top level:
lto1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
```

### Template 64-bit release

```
x86_64-w64-mingw32-g++ -o bin/godot.windows.opt.64.exe -Wl,--subsystem,windows -static -flto=64 -Wl,--stack,8388608 -Wl,--nxcompat platform/windows/godot_windows.windows.opt.64.o platform/windows/context_gl_wind
ows.windows.opt.64.o platform/windows/crash_handler_windows.windows.opt.64.o platform/windows/os_windows.windows.opt.64.o platform/windows/key_mapping_windows.windows.opt.64.o platform/windows/joypad_windows.win
dows.opt.64.o platform/windows/power_windows.windows.opt.64.o platform/windows/windows_terminal_logger.windows.opt.64.o platform/windows/godot_res.windows.opt.64.o main/libmain.windows.opt.64.a modules/libmodule
s.windows.opt.64.a platform/libplatform.windows.opt.64.a drivers/libdrivers.windows.opt.64.a scene/libscene.windows.opt.64.a servers/libservers.windows.opt.64.a core/libcore.windows.opt.64.a modules/freetype/lib
freetype_builtin.windows.opt.64.a -lmingw32 -lopengl32 -ldsound -lole32 -ld3d9 -lwinmm -lgdi32 -liphlpapi -lshlwapi -lwsock32 -lws2_32 -lkernel32 -loleaut32 -ldinput8 -ldxguid -lksuser -limm32 -lbcrypt -lavrt -l
uuid -ldwmapi
In member function 'get_packet',
    inlined from 'get_packet' at core/io/packet_peer_udp.cpp:99:0:
./core/ring_buffer.h:68:18: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
   68 |     p_buf[dst++] = read[pos + i];
      |                  ^
core/io/packet_peer_udp.cpp: In member function 'get_packet':
core/io/packet_peer_udp.h:52: note: at offset 0 to object 'packet_port' with size 4 declared here
   52 |  int packet_port;
      | 
In member function 'get_packet',
    inlined from 'get_packet' at core/io/packet_peer_udp.cpp:99:0:
./core/ring_buffer.h:68:18: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
   68 |     p_buf[dst++] = read[pos + i];
      |                  ^
core/io/packet_peer_udp.cpp: In member function 'get_packet':
core/io/packet_peer_udp.h:52: note: at offset 0 to object 'packet_port' with size 4 declared here
   52 |  int packet_port;
      | 
In member function 'get_packet',
    inlined from 'get_packet' at core/io/packet_peer_udp.cpp:99:0:
./core/ring_buffer.h:68:18: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
   68 |     p_buf[dst++] = read[pos + i];
      |                  ^
core/io/packet_peer_udp.cpp: In member function 'get_packet':
core/io/packet_peer_udp.h:52: note: at offset 0 to object 'packet_port' with size 4 declared here
   52 |  int packet_port;
      | 
thirdparty/libwebp/src/enc/picture_enc.c: In function 'WebPMemoryWrite':
thirdparty/libwebp/src/enc/picture_enc.c:216:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
  216 | }
      | ^
thirdparty/libwebp/src/enc/config_enc.c: In function 'WebPValidateConfig':
thirdparty/libwebp/src/enc/config_enc.c:129:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
  129 | }
      | ^
thirdparty/libwebp/src/utils/utils.c: In function 'WebPSafeMalloc':
thirdparty/libwebp/src/utils/utils.c:199:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
  199 | }
      | ^
thirdparty/libwebp/src/enc/picture_csp_enc.c: In function 'WebPPictureImportRGB':
thirdparty/libwebp/src/enc/picture_csp_enc.c:1194:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
 1194 | }
      | ^
thirdparty/libwebp/src/enc/picture_csp_enc.c: In function 'WebPPictureImportRGBA':
thirdparty/libwebp/src/enc/picture_csp_enc.c:1201:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
 1201 | }
      | ^
thirdparty/miniupnpc/miniupnpc/upnpcommands.c: In function 'UPNP_GetExternalIPAddress':
thirdparty/miniupnpc/miniupnpc/upnpcommands.c:336:1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
  336 | }
      | ^
At top level:
lto1: warning: visibility attribute not supported in this configuration; ignored [-Wattributes]
```

## Linux GCC 10

### Editor, release_debug

```
g++ -o bin/godot.x11.opt.tools.64 -flto=64 -pipe -no-pie -static-libgcc -static-libstdc++ platform/x11/godot_x11.x11.opt.tools.64.o platform/x11/context_gl_x11.x11.opt.tools.64.o platform/x11/crash_handler_x11.x
11.opt.tools.64.o platform/x11/os_x11.x11.opt.tools.64.o platform/x11/key_mapping_x11.x11.opt.tools.64.o platform/x11/joypad_linux.x11.opt.tools.64.o platform/x11/power_x11.x11.opt.tools.64.o platform/x11/detect
_prime.x11.opt.tools.64.o platform/x11/libudev-so_wrap.x11.opt.tools.64.o -L/root/x86_64-godot-linux-gnu_sdk-buildroot/x86_64-godot-linux-gnu/sysroot/usr/lib main/libmain.x11.opt.tools.64.a main/tests/libtests.x
11.opt.tools.64.a modules/libmodules.x11.opt.tools.64.a platform/libplatform.x11.opt.tools.64.a drivers/libdrivers.x11.opt.tools.64.a editor/libeditor.x11.opt.tools.64.a scene/libscene.x11.opt.tools.64.a servers
/libservers.x11.opt.tools.64.a core/libcore.x11.opt.tools.64.a modules/freetype/libfreetype_builtin.x11.opt.tools.64.a -lXcursor -lXinerama -lXext -lXrandr -lXrender -lX11 -lXi -lGL -lpthread -ldl
In function 'getenv',
    inlined from 'getenv_int' at thirdparty/oidn/mkl-dnn/src/common/utils.cpp:73:15,
    inlined from 'dump_jit_code' at thirdparty/oidn/mkl-dnn/src/common/utils.cpp:121:35,
    inlined from 'register_jit_code' at thirdparty/oidn/mkl-dnn/src/cpu/jit_utils/jit_utils.cpp:102:18,
    inlined from 'getCode' at thirdparty/oidn/mkl-dnn/src/cpu/jit_generator.hpp:760:37,
    inlined from '__ct ' at thirdparty/oidn/mkl-dnn/src/cpu/jit_avx512_common_conv_kernel.hpp:43:56,
    inlined from '__ct ' at thirdparty/oidn/mkl-dnn/src/cpu/jit_avx512_common_conv_kernel.hpp:191:31,
    inlined from '__ct_base ' at thirdparty/oidn/mkl-dnn/src/cpu/jit_avx512_common_convolution.hpp:80:19:
thirdparty/oidn/mkl-dnn/src/common/utils.cpp:57:20: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
   57 |             strncpy(buffer, value, value_length);
      |                    ^
thirdparty/oidn/mkl-dnn/src/cpu/jit_avx512_common_convolution.hpp: In member function '__ct_base ':
thirdparty/oidn/mkl-dnn/src/common/utils.cpp:44:46: note: length computed here
   44 |     value_length = value == NULL ? 0 : strlen(value);
      |                                              ^
In function 'getenv',
    inlined from 'getenv_int' at thirdparty/oidn/mkl-dnn/src/common/utils.cpp:73:15,
    inlined from 'dump_jit_code' at thirdparty/oidn/mkl-dnn/src/common/utils.cpp:121:35,
    inlined from 'register_jit_code' at thirdparty/oidn/mkl-dnn/src/cpu/jit_utils/jit_utils.cpp:102:18,
    inlined from 'getCode' at thirdparty/oidn/mkl-dnn/src/cpu/jit_generator.hpp:760:37,
    inlined from '__ct ' at thirdparty/oidn/mkl-dnn/src/cpu/jit_avx512_common_conv_kernel.hpp:43:56,
    inlined from '__ct ' at thirdparty/oidn/mkl-dnn/src/cpu/jit_avx512_common_conv_kernel.hpp:185:31,
    inlined from '__ct_base ' at thirdparty/oidn/mkl-dnn/src/cpu/jit_avx512_common_convolution.hpp:80:19:
thirdparty/oidn/mkl-dnn/src/common/utils.cpp:57:20: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
   57 |             strncpy(buffer, value, value_length);
      |                    ^
thirdparty/oidn/mkl-dnn/src/cpu/jit_avx512_common_convolution.hpp: In member function '__ct_base ':
thirdparty/oidn/mkl-dnn/src/common/utils.cpp:44:46: note: length computed here
   44 |     value_length = value == NULL ? 0 : strlen(value);
      |                                              ^
In function 'getenv',
    inlined from 'getenv_int' at thirdparty/oidn/mkl-dnn/src/common/utils.cpp:73:15,
    inlined from 'dump_jit_code' at thirdparty/oidn/mkl-dnn/src/common/utils.cpp:121:35,
    inlined from 'register_jit_code' at thirdparty/oidn/mkl-dnn/src/cpu/jit_utils/jit_utils.cpp:102:18,
    inlined from 'getCode' at thirdparty/oidn/mkl-dnn/src/cpu/jit_generator.hpp:760:37,
    inlined from '__ct ' at thirdparty/oidn/mkl-dnn/src/cpu/jit_uni_pool_kernel_f32.hpp:41:51,
    inlined from '__ct_base ' at thirdparty/oidn/mkl-dnn/src/cpu/jit_uni_pooling.hpp:77:17:
thirdparty/oidn/mkl-dnn/src/common/utils.cpp:57:20: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
   57 |             strncpy(buffer, value, value_length);
      |                    ^
thirdparty/oidn/mkl-dnn/src/cpu/jit_uni_pooling.hpp: In member function '__ct_base ':
thirdparty/oidn/mkl-dnn/src/common/utils.cpp:44:46: note: length computed here
   44 |     value_length = value == NULL ? 0 : strlen(value);
      |                                              ^
In function 'getenv',
    inlined from 'getenv_int' at thirdparty/oidn/mkl-dnn/src/common/utils.cpp:73:15,
    inlined from 'dump_jit_code' at thirdparty/oidn/mkl-dnn/src/common/utils.cpp:121:35,
    inlined from 'register_jit_code' at thirdparty/oidn/mkl-dnn/src/cpu/jit_utils/jit_utils.cpp:102:18,
    inlined from 'getCode' at thirdparty/oidn/mkl-dnn/src/cpu/jit_generator.hpp:760:37,
    inlined from '__ct ' at thirdparty/oidn/mkl-dnn/src/cpu/jit_avx512_core_fp32_wino_conv_2x3.cpp:403:46,
    inlined from '__ct_base ' at thirdparty/oidn/mkl-dnn/src/cpu/jit_avx512_core_fp32_wino_conv_2x3.cpp:844:38:
thirdparty/oidn/mkl-dnn/src/common/utils.cpp:57:20: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-overflow=]
   57 |             strncpy(buffer, value, value_length);
      |                    ^
thirdparty/oidn/mkl-dnn/src/cpu/jit_avx512_core_fp32_wino_conv_2x3.cpp: In member function '__ct_base ':
thirdparty/oidn/mkl-dnn/src/common/utils.cpp:44:46: note: length computed here
   44 |     value_length = value == NULL ? 0 : strlen(value);
      |                                              ^

[[[ and plenty more like this ]]]
```

### Template 64-bit release

```
g++ -o bin/godot.x11.opt.64 -flto=64 -pipe -no-pie -T platform/x11/pck_embed.ld -static-libgcc -static-libstdc++ platform/x11/godot_x11.x11.opt.64.o platform/x11/context_gl_x11.x11.opt.64.o platform/x11/crash_ha
ndler_x11.x11.opt.64.o platform/x11/os_x11.x11.opt.64.o platform/x11/key_mapping_x11.x11.opt.64.o platform/x11/joypad_linux.x11.opt.64.o platform/x11/power_x11.x11.opt.64.o platform/x11/detect_prime.x11.opt.64.o
 platform/x11/libudev-so_wrap.x11.opt.64.o -L/root/x86_64-godot-linux-gnu_sdk-buildroot/x86_64-godot-linux-gnu/sysroot/usr/lib main/libmain.x11.opt.64.a modules/libmodules.x11.opt.64.a platform/libplatform.x11.o
pt.64.a drivers/libdrivers.x11.opt.64.a scene/libscene.x11.opt.64.a servers/libservers.x11.opt.64.a core/libcore.x11.opt.64.a modules/freetype/libfreetype_builtin.x11.opt.64.a -lXcursor -lXinerama -lXext -lXrand
r -lXrender -lX11 -lXi -lGL -lpthread -ldl
In member function 'read',
    inlined from 'get_packet' at core/io/packet_peer_udp.cpp:112:9,
    inlined from 'get_packet' at core/io/packet_peer_udp.cpp:99:0:
./core/ring_buffer.h:68:18: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
   68 |     p_buf[dst++] = read[pos + i];
      |                  ^
core/io/packet_peer_udp.cpp: In member function 'get_packet':
core/io/packet_peer_udp.h:52: note: at offset 0 to object 'packet_port' with size 4 declared here
   52 |  int packet_port;
      | 
In member function 'read',
    inlined from 'get_packet' at core/io/packet_peer_udp.cpp:112:9,
    inlined from 'get_packet' at core/io/packet_peer_udp.cpp:99:0:
./core/ring_buffer.h:68:18: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
   68 |     p_buf[dst++] = read[pos + i];
      |                  ^
core/io/packet_peer_udp.cpp: In member function 'get_packet':
core/io/packet_peer_udp.h:52: note: at offset 0 to object 'packet_port' with size 4 declared here
   52 |  int packet_port;
      | 
In member function 'read',
    inlined from 'get_packet' at core/io/packet_peer_udp.cpp:112:9,
    inlined from 'get_packet' at core/io/packet_peer_udp.cpp:99:0:
./core/ring_buffer.h:68:18: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
   68 |     p_buf[dst++] = read[pos + i];
      |                  ^
core/io/packet_peer_udp.cpp: In member function 'get_packet':
core/io/packet_peer_udp.h:52: note: at offset 0 to object 'packet_port' with size 4 declared here
   52 |  int packet_port;
      |
```

### Template 32-bit release

```
g++ -o bin/godot.x11.opt.tools.32 -flto=64 -pipe -no-pie -m32 -L/usr/lib/i386-linux-gnu -static-libgcc -static-libstdc++ platform/x11/godot_x11.x11.opt.tools.32.o platform/x11/context_gl_x11.x11.opt.tools.32.o p
latform/x11/crash_handler_x11.x11.opt.tools.32.o platform/x11/os_x11.x11.opt.tools.32.o platform/x11/key_mapping_x11.x11.opt.tools.32.o platform/x11/joypad_linux.x11.opt.tools.32.o platform/x11/power_x11.x11.opt
.tools.32.o platform/x11/detect_prime.x11.opt.tools.32.o platform/x11/libudev-so_wrap.x11.opt.tools.32.o -L/root/i686-godot-linux-gnu_sdk-buildroot/i686-godot-linux-gnu/sysroot/usr/lib main/libmain.x11.opt.tools
.32.a main/tests/libtests.x11.opt.tools.32.a modules/libmodules.x11.opt.tools.32.a platform/libplatform.x11.opt.tools.32.a drivers/libdrivers.x11.opt.tools.32.a editor/libeditor.x11.opt.tools.32.a scene/libscene
.x11.opt.tools.32.a servers/libservers.x11.opt.tools.32.a core/libcore.x11.opt.tools.32.a modules/freetype/libfreetype_builtin.x11.opt.tools.32.a -lXcursor -lXinerama -lXext -lXrandr -lXrender -lX11 -lXi -lGL -l
pthread -ldl
g++: WARNING: unsafe header/library path used in cross-compilation: '-L/usr/lib/i386-linux-gnu'
/root/i686-godot-linux-gnu_sdk-buildroot/bin/../lib/gcc/i686-godot-linux-gnu/10.2.0/../../../../i686-godot-linux-gnu/bin/ld: warning: library search path "/usr/lib/i386-linux-gnu" is unsafe for cross-compilation
./thirdparty/minizip/unzip.h:404: warning: type of 'unztell' does not match original declaration [-Wlto-type-mismatch]
  404 | extern z_off_t ZEXPORT unztell OF((unzFile file));
      | 
thirdparty/minizip/unzip.c:1999: note: return value type mismatch
 1999 | extern z_off_t ZEXPORT unztell (unzFile file)
      | 
thirdparty/minizip/unzip.c:1999: note: type 'long int' should match type 'off_t'
thirdparty/minizip/unzip.c:1999: note: 'unztell' was previously declared here
thirdparty/minizip/unzip.c:1999: note: code may be misoptimized unless '-fno-strict-aliasing' is used
```

### Steps to reproduce

Build official builds using scripts from https://github.com/godotengine/godot-build-scripts and containers from https://github.com/godotengine/build-containers

Or possibly simpler steps by just reproducing a single build with similar toolchains and build options.

### Minimal reproduction project

_No response_