These options are now only applied if compiling with clang.
While it's possible to use libc++ with gcc, it requires a lot of manual
changes, and basicaly no one does it. (libstdc++ with clang is commonly
done on desktop Linux systems, though.)
Don't -D_LIBCPP_ENABLE_ASSERTIONS on clang-17 or later. It's deprecated,
and may result in a compile error. (...though on Android/Termux with
clang-20.1.3, it didn't...)
Newer compilers usually add more warnings, so having -Werror by default
will most likely result in a compile error when new compiler versions
are released.
MSVC: Remove "-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING". This is no
longer relevant, since we don't support anything older than MSVC 2015.
It seems this was broken since it was initially implemented in v2.0
in commit d732fbc010
([cmake] platform/gcc.cmake: Initial support for detecting DT_RELR.)
because TMP_HAVE_DT_RELR was unset too early.
When compiling with LTO enabled on gcc-14.2.0 (e.g. with Ubuntu 25.04),
the following warning (as error) appeared. Work around it by checking for
str.empty() before resizing the string.
[cmake] gcc.cmake: Remove -Wno-error=aggressive-loop-optimizations, since
it's no longe needed.
In function ‘assign’,
inlined from ‘_S_assign’ at /usr/include/c++/14/bits/basic_string.h:455:23,
inlined from ‘_S_assign’ at /usr/include/c++/14/bits/basic_string.h:450:7,
inlined from ‘_M_replace_aux’ at /usr/include/c++/14/bits/basic_string.tcc:471:17,
inlined from ‘append’ at /usr/include/c++/14/bits/basic_string.h:1499:30,
inlined from ‘resize’ at /usr/include/c++/14/bits/basic_string.tcc:405:14,
inlined from ‘resize’ at /usr/include/c++/14/bits/basic_string.h:1119:21,
inlined from ‘TestBody’ at src/librptext/tests/TextFuncsTest.cpp:513:12:
/usr/include/c++/14/bits/char_traits.h:837:25: error: iteration 9223372036854775807 invokes undefined behavior [-Werror=aggressive-loop-optimizations]
837 | assign(__s[__i], __a);
| ^
/usr/include/c++/14/bits/char_traits.h:836:34: note: within this loop
836 | for (size_t __i = 0; __i < __n; ++__i)
| ^
In function ‘assign’,
inlined from ‘_S_assign’ at /usr/include/c++/14/bits/basic_string.h:455:23,
inlined from ‘_S_assign’ at /usr/include/c++/14/bits/basic_string.h:450:7,
inlined from ‘_M_replace_aux’ at /usr/include/c++/14/bits/basic_string.tcc:471:17,
inlined from ‘append’ at /usr/include/c++/14/bits/basic_string.h:1499:30,
inlined from ‘resize’ at /usr/include/c++/14/bits/basic_string.tcc:405:14,
inlined from ‘resize’ at /usr/include/c++/14/bits/basic_string.h:1119:21,
inlined from ‘TestBody’ at src/librptext/tests/TextFuncsTest.cpp:542:12:
/usr/include/c++/14/bits/char_traits.h:837:25: error: iteration 9223372036854775807 invokes undefined behavior [-Werror=aggressive-loop-optimizations]
837 | assign(__s[__i], __a);
| ^
/usr/include/c++/14/bits/char_traits.h:836:34: note: within this loop
836 | for (size_t __i = 0; __i < __n; ++__i)
| ^
lto1: all warnings being treated as errors
lto-wrapper: fatal error: /usr/bin/c++ returned 1 exit status
compilation terminated.
The same error showed up on armhf and amd64 this time.
Since it's happening in LTO and not the main compiler step, the pragmas
likely aren't working properly. Use -Wno-error=stringop-overread instead.
(cherry picked from commit ec441b4cec)
The Ubuntu 16.04 Launchpad build for armhf failed due to a potential
alignment issue:
/<<PKGBUILDDIR>>/src/kde/AchQtDBus.cpp: In member function ‘int AchQtDBus::notifyFunc(LibRpBase::Achievements::ID)’:
/<<PKGBUILDDIR>>/src/kde/AchQtDBus.cpp:149:59: error: cast from ‘uchar* {aka unsigned char*}’ to ‘LibRpTexture::argb32_t*’ increases required alignment of target type [-Werror=cast-align]
argb32_t *bits = reinterpret_cast<argb32_t*>(icon.bits());
^
This shouldn't be an actual problem, since rp_image's image data is
always 16-byte aligned.
NOTE: Not rebuilding the Ubuntu 16.04 packages for ARM because of this.
(Both the armhf and arm64 builds were cancelled.)
(cherry picked from commit 5a08131311)
clang complains about moc headers due to how automoc handles things:
In file included from build/src/kde/kf5/overlayiconplugin_rom-properties-kf5_autogen/mocs_compilation.cpp:2:
build/src/kde/kf5/overlayiconplugin_rom-properties-kf5_autogen/BKZOEHIFDQ/moc_OverlayIconPluginKF5.cpp:1340:17: error: using namespace directive in global context in header [-Werror,-Wheader-hygiene]
1340 | using namespace RomPropertiesKF5;
| ^
1 error generated.
This clang warning is currently "intentional", though I might rename the
not-virtual open() function later:
In file included from src/libromdata/Handheld/Nintendo3DS.cpp:14:
In file included from src/libromdata/Handheld/Nintendo3DS_p.hpp:19:
src/libromdata/Handheld/../disc/NCCHReader.hpp:193:24: error: 'LibRomData::NCCHReader::open' hides overloaded virtual function [-Werror,-Woverloaded-virtual]
193 | LibRpFile::IRpFilePtr open(int section, const char *filename);
| ^
src/libromdata/../librpbase/disc/IPartition.hpp:104:32: note: hidden overloaded virtual function 'LibRpBase::IPartition::open' declared here: different number of parameters (1 vs 2)
104 | virtual LibRpFile::IRpFilePtr open(const char *filename);
| ^
1 error generated.
Fixes what appears to be a false-positive warning-as-error in the
Release build:
src/librpbase/img/RpPng.cpp: In function ‘LibRpTexture::rp_image_ptr LibRpBase::RpPng::loadPng(png_structp, png_infop)’:
src/librpbase/img/RpPng.cpp:181:42: error: variable ‘color’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered]
181 | argb32_t color;
| ^~~~~
cc1plus: all warnings being treated as errors
This broke the Ubuntu 22.04 AppVeyor build:
extlib/microtar/src/microtar.c: In function ‘mtar_read_header’:
extlib/microtar/src/microtar.c:111:3: error: ‘__builtin_strncpy’ output may be truncated copying 99 bytes from a string of length 99 [-Werror=stringop-truncation]
111 | strncpy(h->name, rh->name, sizeof(h->name));
| ^
extlib/microtar/src/microtar.c:112:3: error: ‘__builtin_strncpy’ output may be truncated copying 99 bytes from a string of length 99 [-Werror=stringop-truncation]
112 | strncpy(h->linkname, rh->linkname, sizeof(h->linkname));
| ^
cc1: all warnings being treated as errors
This fixes the 'negative' errors from lcov's geninfo.
Before:
source files: 600
lines.......: 23.2% (10654 of 45904 lines)
functions...: 22.8% (848 of 3721 functions)
branches....: 15.8% (7572 of 47821 branches)
After:
source files: 600
lines.......: 23.2% (10654 of 45904 lines)
functions...: 22.8% (848 of 3721 functions)
branches....: 15.8% (7572 of 47821 branches)
Effectively no change in coverage, but it's likely more stable.
I'll note that the error was triggering in ASTC decoding, which
uses OpenMP for parallel processing.
Assertions are enabled for libstdc++ (gcc) and libc++ (llvm/clang).
Debug mode is enabled for libstdc++ only.
libc++'s hardened mode is also enabled.
libstdc++'s debug mode has already helped find a few bugs:
- GLenumStrings.cpp: sRGB PVRTC v1 was in the wrong place.
- AmiiboData.cpp: Searching for character variants was incorrect.
Not enabled for Release builds, since the assertions cause the program
to crash with SIGABRT.
gcc-7.1 and later print a lot of annoying warnings on armhf whenever
passing an iterator to a function:
In file included from /usr/include/c++/13/memory:69,
from rom-properties/src/librptexture/stdafx.h:23,
from rom-properties/build/src/librptexture/CMakeFiles/rptexture.dir/cmake_pch.hxx:7,
from <command-line>:
/usr/include/c++/13/bits/stl_uninitialized.h: In function ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = move_iterator<_KTX2_Mipmap_Index*>; _ForwardIterator = _KTX2_Mipmap_Index*; _Allocator = rp::default_init_allocator<_KTX2_Mipmap_Index, allocator<_KTX2_Mipmap_Index> >]’:
/usr/include/c++/13/bits/stl_uninitialized.h:344:5: note: parameter passing for argument of type ‘std::move_iterator<_KTX2_Mipmap_Index*>’ changed in GCC 7.1
344 | __uninitialized_copy_a(_InputIterator __first, _InputIterator __last,
| ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_uninitialized.h:344:5: note: parameter passing for argument of type ‘std::move_iterator<_KTX2_Mipmap_Index*>’ changed in GCC 7.1
/usr/include/c++/13/bits/stl_uninitialized.h: In function ‘_ForwardIterator std::__uninitialized_move_if_noexcept_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = _KTX2_Mipmap_Index*; _ForwardIterator = _KTX2_Mipmap_Index*; _Allocator = rp::default_init_allocator<_KTX2_Mipmap_Index, allocator<_KTX2_Mipmap_Index> >]’:
/usr/include/c++/13/bits/stl_uninitialized.h:399:9: note: parameter passing for argument of type ‘std::move_iterator<_KTX2_Mipmap_Index*>’ changed in GCC 7.1
398 | return std::__uninitialized_copy_a
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
399 | (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__first),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
400 | _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(__last), __result, __alloc);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Available in clang, but not gcc (as of 14.2).
This ensures that header files (including .cpp files used with #include)
do not have global `using` statements.
NintendoDS_p.hpp: Removed unnecessary `using namespace` statements.
Removed global `using` statements from TCreateThumbnail.cpp and
TImageTypesConfig.cpp. Functions now have localized `using` statements.
Updated calling files to add `using` statements where necessary.
TImageTypesConfig.cpp: Also add a static_assert() for conf_imageTypeNames[].
FIXME: The generated moc files for OverlayIconPluginKF5 and
OverlayIconPluginKF6 both have `using namespace` directives, which
causes clang to fail due to -Werror=header-hygiene.
We don't need to check errno for any math functions, and this prevents
certain inlining optimizations. In particular, lrintf() can't be inlined
if we don't specify this, even though glibc's documentation says that
its lrintf() implementation doesn't set errno.
Assembly comparison of manual truncation vs. lrintf() with
-fno-math-errno:
amd64:
- Manual: cvttss2si
- lrintf(): cvtss2si (note the single t)
i386 with SSE disabled:
- Manual: fistp with control word manipulation
- lrintf(): fistp without control word manipulation
Presumably the control word on manipulation changes the rounding mode.
lrintf() without errno doesn't change the rounding mode and relies on
the default rounding, which matches amd64.
TODO: MSVC equivalent, if available.
[libromdata] Nintendo3DSFirm: Fix a strict aliasing error on Ubuntu 16.04. (gcc-5.4.0)
In file included from src/libromdata/stdafx.h:62:0,
from src/libromdata/Handheld/Nintendo3DSFirm.cpp:9:
src/libromdata/Handheld/Nintendo3DSFirm.cpp: In member function ‘virtual int LibRomData::Nintendo3DSFirm::loadFieldData()’:
src/libromdata/Handheld/Nintendo3DSFirm.cpp:369:97: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
const uint32_t first4 = be32_to_cpu(*(reinterpret_cast<const uint32_t*>(firmHeader->signature)));
^
src/libromdata/../librpcpu/byteswap_rp.h:63:52: note: in definition of macro ‘__swab32’
# define __swab32(x) ((uint32_t)__builtin_bswap32(x))
^
src/libromdata/Handheld/Nintendo3DSFirm.cpp:369:27: note: in expansion of macro ‘be32_to_cpu’
const uint32_t first4 = be32_to_cpu(*(reinterpret_cast<const uint32_t*>(firmHeader->signature)));
^
cc1plus: some warnings being treated as errors
CMake 3.1 added CMAKE_<LANG>_STANDARD, which allows CMake to determine
what flags are needed to select a particular language version.
Set it to C17 and C++17. Previously, we were using C11 and C++11,
though gcc11 switched the default C++ version to C++17. The custom
macro handled this by not adding flags for C++, but it still added
the C11 flag, which prevented use of C17.
No code size differences were observed when compiling on gcc-13.2.0
with CMAKE_<LANG>_STANDARD.
On i386, also add -mstackrealign, since i386 was originally defined to
use 4-byte stack alignment. Most programs *should* be updated to use
16-byte stack alignment nowadays, but just in case something isn't,
this will help to prevent alignment exceptions.
The gcc-5 workaround stopped working properly due to some recent change.
I can't be bothered to figure out what broke it, and gcc-5 is rather old.
Just don't allow enabling LTO at all.
Removed the GCC_5xx_LTO_ISSUES workarounds in all CMakeLists files.
Reworked the -lgcc workaround to check the compiler version instead
of GCC_5xx_LTO_ISSUES.
This lets us remove "-lgcov", since gcc will automatically add the
coverage library when linking with coverage.
NOTE: Remember to set LD_LIBRARY_PATH when testing code coverage.
Otherwise, the system-wide libromdata.so.2 will be tested, and
that won't have coverage instrumentation.
Add the following linker options:
- --no-undefined
- --no-allow-shlib-undefined
GTK UI frontends: Link to Pango, GDK, and other libraries directly if
we're using symbols from those libraries.
NOTE: CMake's FindGTK2 seems to do this already, but we'll add the extra
linking ourselves just in case.
This fixes errors similar to the following after adding the
linker options:
/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/../../../../x86_64-pc-linux-gnu/bin/ld:
src/gtk/gtk3/CMakeFiles/rom-properties-gtk3.dir/__/config/CacheTab.cpp.o:
undefined reference to symbol 'gdk_window_set_cursor'
/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/../../../../x86_64-pc-linux-gnu/bin/ld:
/usr/lib64/libgdk-3.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
For some reason, "-Wsuggest-override" is being turned into an error in
the MinGW-w64 build. This breaks Google Test, which is apparently
triggering some "suggest override" warnings.
- Use host gettext executables when cross-compiling with MinGW.
- Change CHECK_GETTEXT() from a macro to a function.
- Disable -Wno-cast-function-type, since it prints warnings every time
we use GetProcAddress().
Reference: https://fedoraproject.org/wiki/Format-Security-FAQ
-Werror=format-nonliteral is *not* enabled because there are some
legitimate uses of non-literal format strings.
Separated the warning flags into multiple variables.
Updated everything to build with this change.
KDE Frameworks 5.85.0 enables this by default. It reduces startup time
by pre-linking global function symbols.
Also, filter out '=' from variable names. This broke the caching of
-Werror=return-type.
msvc.cmake: Copy the '=' change here.
I'm not sure when this started happening, but leaving out a return
value from a non-void function is causing gcc to jump to a semi-random
function instead of simply returning an undefined value.
language_combo_box_set_selected_lc() was calling
language_combo_box_set_property() because of this:
.#4 0x00007fffca11e468 in language_combo_box_set_property(GObject*, guint, GValue const*, GParamSpec*) (object=0x7ffff70d0108, prop_id=1, value=0xa8, pspec=0x1)
at ../../src/gtk/LanguageComboBox.cpp:156
.#5 0x0000555555cf3ad0 in ()
.#6 0x000000000000656e in ()
.#7 0x0000555555cf3ad0 in ()
.#8 0x0000555555c46838 in ()
.#9 0x0000555555e5b6a0 in ()
.#10 0x00007fffca111d0b in rom_data_view_update_multi(RomDataView*, uint32_t) (page=page@entry=0x7fffe8020490 [RomDataView], user_lc=user_lc@entry=0)
at ../../src/gtk/RomDataView.cpp:1554
I set this while testing some refcounting stuff earlier.
This fixes a regression from commit 2b4ada24e4.
([librpbase] IconAnimData: Changed to a reference-counted class.)
Updated all RomData subclasses and UI frontends for this change.
Animated icons now work correctly in UI frontends after e.g. extracting
an SRL from a DSi TAD package or Nintendo 3DS CIA.
Note that we don't need to implement runtime fallbacks to stat():
1. If statx() isn't available at compile time, stat() will be used
regardless.
2. If glibc supports statx() but the kernel doesn't, glibc will
emulate statx(). This might introduce some extra overhead, but
it's easier to work with.
3. The BSDs keep their libc in sync with the kernel, so there's no
possibility that libc will support statx() if the kernel doesn't.
GNU ld treats these as the same, but clang ld requires a value to be
specified.
This fixes a regression on FreeBSD from commit 107224487f.
([cmake] Reworked --compress-debug-sections logic for compatibility with older systems.)
Ubuntu 14.04's ld (binutils-2.24) doesn't have --compress-debug-sections,
which causes travis-ci to fail.
cmake-3.6's try_compile() attempts to build an executable by default,
which *should* test the linker flags, but that isn't working, either.
Ubuntu 14.04 has cmake-3.3, so that wouldn't help anyway.
Instead, check the output of `ld --help` for the various options.
This seems to work for the most part.
Enabled this method for Mac OS X as well.
If the --compress-debug-sections=zlib linker test fails, then we'll
fall back to the old objcopy method. SplitDebugInformation.cmake uses
the same detection method to check if objcopy supports the option,
and if it does, it uses it.