On Tue, Jul 19, 2022 at 04:56:02PM +0000, Matthias Klose wrote:
> This package currently fails to build (at least on the amd64
> architecture) with link time optimizations enabled.
Hello, I believe we have a gcc bug here.
Try to build libspectrum after applying this patch:
diff -ru libspectrum-1.5.0.orig/szx.c libspectrum-1.5.0/szx.c
--- libspectrum-1.5.0.orig/szx.c 2021-02-27 03:02:21.000000000 +0000
+++ libspectrum-1.5.0/szx.c 2022-07-19 18:56:44.740953365 +0000
@@ -2545,6 +2545,11 @@
error = read_chunk_header( id, &data_length, buffer, end );
if( error ) return error;
+ unsigned l1 = data_length;
+ printf("Data length (unsigned): %u\n", l1);
+ unsigned long l2 = l1;
+ printf("Data length (unsigned long): %lu\n", l2);
+
if( end - *buffer < data_length ) {
libspectrum_print_error(
LIBSPECTRUM_ERROR_CORRUPT,
When the build fails run test/test manually and observe the output:
Data length (unsigned): 4294901760
Data length (unsigned long): 18446744073709486080
GCC is converting 0xFFFF0000 into 0xFFFFFFFFFFFF0000 when casting an
unsigned into an unsigned long.
The problem only happens with -O2, if you put this around that
function...
#pragma GCC push_options
#pragma GCC optimize ("-O2")
/* ... */
#pragma GCC pop_options
...then the problem goes away. GCC in bullseye (4:10.2.1-1) can build
this same package without problems.
Berto