ssinger / slony1-engine

Slony replication system for Postgresql
http://www.slony.info
Other
39 stars 19 forks source link

Build fails with LTO #21

Open eli-schwartz opened 8 months ago

eli-schwartz commented 8 months ago

I tried to build with the following *FLAGS to optimize the build: -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing

Note the -Werror=* flags are used to help detect cases where the compiler tries to optimize by assuming UB cannot exist in the source code -- if it does exist, ordinarily the code would be miscompiled, and this says to make the miscompilation a fatal error.

I got this error:

x86_64-pc-linux-gnu-gcc -I/usr/include/postgresql-14/ -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=incompatible-pointer-types -Wall -Wmissing-prototypes -Wmissing-declarations -fno-common -Wl,-O1 -Wl,--as-needed -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 -L/usr/lib64/postgresql-14/lib64/ -lpq  -Wl,-rpath,/usr/lib64/postgresql-14/lib64/ -o test-scanner test-scanner.c scanner.o
test-scanner.c: In function ‘main’:
test-scanner.c:18:9: warning: ignoring return value of ‘fread’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |         fread(foo, sizeof(char), 65536, stdin);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test-scanner.c:6:17: error: type of ‘STMTS’ does not match original declaration [-Werror=lto-type-mismatch]
    6 | extern int      STMTS[1024];
      |                 ^
scanner.c:5:25: note: array types have different bounds
    5 | int                     STMTS[MAXSTATEMENTS];
      |                         ^
scanner.c:5:25: note: ‘STMTS’ was previously declared here
lto1: some warnings being treated as errors
lto-wrapper: fatal error: x86_64-pc-linux-gnu-gcc returned 1 exit status
compilation terminated.
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:19: test-scanner] Error 1

Downstream report: https://bugs.gentoo.org/855251 Full build log: build.log

ssinger commented 8 months ago

Did the above patch address the issue?

eli-schwartz commented 8 months ago
>>> Preparing source in /var/tmp/portage/dev-db/slony1-2.2.10-r1/work/slony1-2.2.10 ...
 * ================================================================================================================================================================================================================
 * Applying user patches from /etc/portage/patches ...
 * Applying 22.patch ...                                                                                                                                                                                    [ ok ]
 * User patches applied.
 * ================================================================================================================================================================================================================

[...]

x86_64-pc-linux-gnu-gcc -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=incompatible-pointer-types -Wall -Wmissing-prototypes -Wmissing-declarations -fno-common -I/usr/include/postgresql-14/ -c -o test-scanner.o test-scanner.c
x86_64-pc-linux-gnu-gcc -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=incompatible-pointer-types -Wall -Wmissing-prototypes -Wmissing-declarations -fno-common -I/usr/include/postgresql-14/ -c -o scanner.o scanner.c
test-scanner.c: In function ‘main’:
test-scanner.c:18:9: warning: ignoring return value of ‘fread’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |         fread(foo, sizeof(char), 65536, stdin);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
x86_64-pc-linux-gnu-gcc -I/usr/include/postgresql-14/ -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=incompatible-pointer-types -Wall -Wmissing-prototypes -Wmissing-declarations -fno-common -Wl,-O1 -Wl,--as-needed -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 -L/usr/lib64/postgresql-14/lib64/ -lpq  -Wl,-rpath,/usr/lib64/postgresql-14/lib64/ -o test-scanner test-scanner.c scanner.o
test-scanner.c: In function ‘main’:
test-scanner.c:18:9: warning: ignoring return value of ‘fread’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |         fread(foo, sizeof(char), 65536, stdin);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./test-scanner < /dev/null > emptytestresult.log
./test-scanner < ./test_sql.sql > test_sql.log
./test-scanner < ./cstylecomments.sql > cstylecomments.log
make[2]: Leaving directory '/var/tmp/portage/dev-db/slony1-2.2.10-r1/work/slony1-2.2.10-14/src/parsestatements'

Looks good to me, thanks for the quick fix.