Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails with LTO #468

Closed
eli-schwartz opened this issue Mar 27, 2024 · 16 comments
Closed

Build fails with LTO #468

eli-schwartz opened this issue Mar 27, 2024 · 16 comments

Comments

@eli-schwartz
Copy link

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:

LD_RUN_PATH="/usr/lib/gcc/x86_64-pc-linux-gnu/13" x86_64-pc-linux-gnu-gcc  -shared -O2 -pipe -march=x86-64-v3 -fno-strict-aliasing -Wl,-O1 -Wl,--as-needed  Minuit.o pp-mninit.o pp-mn_abre.o pp-mn_cierra.o pp-mnparm.o pp-mnexcm.o pp-mnpout.o pp-mnstat.o pp-mnemat.o pp-mnerrs.o pp-mncont.o FCN.o minuitlib/futils.o minuitlib/minuit.o minuitlib/intracfalse.o -Wl,-O1 -Wl,--as-needed -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 -o ../../blib/arch/auto/PDL/Minuit/Minuit.so  \
   -L/usr/lib/gcc/x86_64-pc-linux-gnu/13 -L/usr/lib -lgfortran -lm   \
  
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libm.so when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libm.a when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc
minuitlib/minuit.f:3567:10: error: type of ‘intrac’ does not match original declaration [-Werror=lto-type-mismatch]
 3567 |       if (intrac(dummy))  isw(6) = 1
      |          ^
minuitlib/intracfalse.f:1:30: note: type mismatch in parameter 1
    1 |        logical function intrac()
      |                              ^
minuitlib/intracfalse.f:1:30: note: ‘intrac’ was previously declared here
FCN.h:33:13: error: type of ‘mnpout_’ does not match original declaration [-Werror=lto-type-mismatch]
   33 | extern void MNPOUT(int*,char*,double*,double*,double*,double*,int*,int);
      |             ^
minuitlib/minuit.f:5306:23: note: type mismatch in parameter 8
 5306 |       subroutine mnpout(iuext,chnam,val,err,xlolim,xuplim,iuint)
      |                       ^
minuitlib/minuit.f:5306:23: note: type ‘long int’ should match type ‘int’
minuitlib/minuit.f:5306:23: note: ‘mnpout’ was previously declared here
minuitlib/minuit.f:5306:23: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
FCN.h:32:13: error: type of ‘mnexcm_’ does not match original declaration [-Werror=lto-type-mismatch]
   32 | extern void MNEXCM(void* f,char*,double*,int*,int*,double* futil,int);
      |             ^
minuitlib/minuit.f:2035:23: note: type mismatch in parameter 1
 2035 |       subroutine mnexcm(fcn,comand,plist,llist,ierflg,futil)
      |                       ^
minuitlib/minuit.f:2035:23: note: ‘mnexcm’ was previously declared here
minuitlib/minuit.f:2035:23: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
FCN.h:31:13: error: type of ‘mnparm_’ does not match original declaration [-Werror=lto-type-mismatch]
   31 | extern void MNPARM(int*,char*,double*,double*,double*,double*,int*,int);
      |             ^
minuitlib/minuit.f:4794:23: note: type mismatch in parameter 8
 4794 |       subroutine mnparm(k,cnamj,uk,wk,a,b,ierflg)
      |                       ^
minuitlib/minuit.f:4794:23: note: type ‘long int’ should match type ‘int’
minuitlib/minuit.f:4794:23: note: ‘mnparm’ was previously declared here
minuitlib/minuit.f:4794:23: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
FCN.h:39:13: error: type of ‘abre_’ does not match original declaration [-Werror=lto-type-mismatch]
   39 | extern void ABRE(int*,char*,char*,int,int);
      |             ^
minuitlib/futils.f:1:21: note: type mismatch in parameter 4
    1 |       subroutine abre(n,nombre,mode)
      |                     ^
minuitlib/futils.f:1:21: note: type ‘long int’ should match type ‘int’
minuitlib/futils.f:1:21: note: ‘abre’ was previously declared here
minuitlib/futils.f:1:21: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
FCN.h:30:13: error: type of ‘mnseti_’ does not match original declaration [-Werror=lto-type-mismatch]
   30 | extern void MNSETI(char*,int);
      |             ^
minuitlib/minuit.f:6986:23: note: type mismatch in parameter 2
 6986 |       subroutine mnseti(tit)
      |                       ^
minuitlib/minuit.f:6986:23: note: type ‘long int’ should match type ‘int’
minuitlib/minuit.f:6986:23: note: ‘mnseti’ was previously declared here
minuitlib/minuit.f:6986:23: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
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:472: ../../blib/arch/auto/PDL/Minuit/Minuit.so] Error 1

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

@eli-schwartz
Copy link
Author

The bug was originally reported with 2.63.0 which is also the latest version available in Gentoo. I cannot figure out how to try updating the package to test the new version -- perl version numbers have defeated me.

But: the code with the LTO issue hasn't changed since that release anyway, so it shouldn't matter.

@mohawk2
Copy link
Member

mohawk2 commented Mar 27, 2024

PDL 2.063 was released in Nov 2021, is that what you mean by "2.63.0"? Is there some reason that Gentoo is that far behind?

2.069, released in Jan 2022, had various Fortran-module 64-bit updates (Slatec and Minuit), which is likely to have fixed this. Could you try it? Or indeed the latest PDL, either the latest released one, or the latest dev-release?

@eli-schwartz
Copy link
Author

eli-schwartz commented Mar 27, 2024

I'm no maven when it comes to packaging perl modules, so I'm not entirely sure of the answers to any of that. However, I did figure out how to reverse engineer and reproduce it outside of the package manager.

$  git clone https://github.com/PDLPorters/pdl/ && cd pdl

# no --enable-foo style flags, so edit configure options to successfully configure
$ vim perldl.conf

# Makefile.PL doesn't respect standard CFLAGS / LDFLAGS / FFLAGS, but does inject
# whatever perl itself was built with. Override some Makefile variables that aren't
# actually intended to work this way, but are inserted in the right places. In particular,
# this is egregious misuse of OPTIMIZE, but do it anyway since fortran code actually
# gets compiled with it.

$ perl Makefile.PL
$ make \
    OTHERLDFLAGS="-flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -fstrict-aliasing" \
    OPTIMIZE="-O2 -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -fstrict-aliasing"

It failed:

make[2]: Entering directory '/tmp/pdl/Libtmp/Minuit'
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Minuit.bs ../../blib/arch/auto/PDL/Minuit/Minuit.bs 644
rm -f ../../blib/arch/auto/PDL/Minuit/Minuit.so
LD_RUN_PATH="/usr/lib/gcc/x86_64-pc-linux-gnu/13" x86_64-pc-linux-gnu-gcc  -shared -O2 -pipe -march=x86-64-v3 -fno-strict-aliasing -Wl,-O1 -Wl,--as-needed  Minuit.o pp-mninit.o pp-mn_abre.o pp-mn_cierra.o pp-mnparm.o pp-mnexcm.o pp-mnpout.o pp-mnstat.o pp-mnemat.o pp-mnerrs.o pp-mncont.o FCN.o minuitlib/futils.o minuitlib/minuit.o minuitlib/intracfalse.o -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -fstrict-aliasing -o ../../blib/arch/auto/PDL/Minuit/Minuit.so  \
   -L/usr/lib/gcc/x86_64-pc-linux-gnu/13 -L/usr/lib -lgfortran -lm   \
  
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libm.so when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libm.a when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc
minuitlib/minuit.f:3567:10: error: type of ‘intrac’ does not match original declaration [-Werror=lto-type-mismatch]
 3567 |       if (intrac(dummy))  isw(6) = 1
      |          ^
minuitlib/intracfalse.f:1:30: note: type mismatch in parameter 1
    1 |        logical function intrac()
      |                              ^
minuitlib/intracfalse.f:1:30: note: ‘intrac’ was previously declared here
FCN.h:40:13: error: type of ‘cierra_’ does not match original declaration [-Werror=lto-type-mismatch]
   40 | extern void CIERRA(PDL_LongLong*);
      |             ^
minuitlib/futils.f:11:23: note: ‘cierra’ was previously declared here
   11 |       subroutine cierra(n)
      |                       ^
minuitlib/futils.f:11:23: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
FCN.h:39:13: error: type of ‘abre_’ does not match original declaration [-Werror=lto-type-mismatch]
   39 | extern void ABRE(PDL_LongLong*,char*,char*,PDL_Indx,PDL_Indx);
      |             ^
minuitlib/futils.f:1:21: note: ‘abre’ was previously declared here
    1 |       subroutine abre(n,nombre,mode)
      |                     ^
minuitlib/futils.f:1:21: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
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:471: ../../blib/arch/auto/PDL/Minuit/Minuit.so] Error 1
make[2]: Leaving directory '/tmp/pdl/Libtmp/Minuit'

mohawk2 referenced this issue Mar 31, 2024
(cd Libtmp/Minuit/;
  rm minuitlib/bigun.f;
  (for x in minuitlib/*.f; do echo "#line 1 \"$x\""; cat $x; done) >bigun.f;
  mv bigun.f minuitlib/;
  time make test)

and replace in the Makefile the OBJECT line minuitlib/*.o with
minuitlib/bigun.o, and the compile line at end
@mohawk2
Copy link
Member

mohawk2 commented Mar 31, 2024

Using a similar trick to #369 caught the intrac one. A lighter-weight way to trigger the problem with the others is to edit Libtmp/Minuit/Makefile and edit the two vars manually.

@mohawk2
Copy link
Member

mohawk2 commented Mar 31, 2024

Clearly you're much more of a maven than me! Thank you for the report. I don't know if this will benefit Gentoo, since they're so far behind already?

@eli-schwartz
Copy link
Author

Thanks, it gets much further.

Still from my git clone:

$  git clone https://github.com/PDLPorters/pdl/ && cd pdl

# no --enable-foo style flags, so edit configure options to successfully configure
$ vim perldl.conf

# Makefile.PL doesn't respect standard CFLAGS / LDFLAGS / FFLAGS, but does inject
# whatever perl itself was built with. Override some Makefile variables that aren't
# actually intended to work this way, but are inserted in the right places. In particular,
# this is egregious misuse of OPTIMIZE, but do it anyway since fortran code actually
# gets compiled with it.

$ perl Makefile.PL
$ make \
    OTHERLDFLAGS="-flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -fstrict-aliasing" \
    OPTIMIZE="-O2 -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -fstrict-aliasing"

Yields the following errors:

rm -f ../../blib/arch/auto/PDL/Slatec/Slatec.so
LD_RUN_PATH="/usr/lib/gcc/x86_64-pc-linux-gnu/13" x86_64-pc-linux-gnu-gcc  -shared -O2 -pipe -march=x86-64-v3 -fno-strict-aliasing -Wl,-O1 -Wl,--as-needed  Slatec.o pp-svdc.o pp-poco.o pp-geco.o pp-gefa.o pp-podi.o pp-gedi.o pp-gesl.o pp-rs.o pp-ezffti.o pp-ezfftf.o pp-ezfftb.o pp-pcoef.o pp-pvalue.o pp-chim.o pp-chic.o pp-chsp.o pp-chfd.o pp-chfe.o pp-chia.o pp-chid.o pp-chcm.o pp-chbs.o pp-polfit.o barf.o slatec/chfcm.o slatec/chfdv.o slatec/chfev.o slatec/chfie.o slatec/d1mach.o slatec/dasum.o slatec/daxpy.o slatec/dchfcm.o slatec/dchfdv.o slatec/dchfev.o slatec/dchfie.o slatec/ddot.o slatec/dgeco.o slatec/dgedi.o slatec/dgefa.o slatec/dgesl.o slatec/dp1vlu.o slatec/dpchbs.o slatec/dpchce.o slatec/dpchci.o slatec/dpchcm.o slatec/dpchcs.o slatec/dpchdf.o slatec/dpchfd.o slatec/dpchfe.o slatec/dpchia.o slatec/dpchic.o slatec/dpchid.o slatec/dpchim.o slatec/dpchkt.o slatec/dpchsp.o slatec/dpchst.o slatec/dpchsw.o slatec/dpcoef.o slatec/dpoco.o slatec/dpodi.o slatec/dpofa.o slatec/dpolft.o slatec/dscal.o slatec/dswap.o slatec/ezfft1.o slatec/ezfftb.o slatec/ezfftf.o slatec/ezffti.o slatec/fdump.o slatec/i1mach.o slatec/idamax.o slatec/isamax.o slatec/j4save.o slatec/pchbs.o slatec/pchce.o slatec/pchci.o slatec/pchcm.o slatec/pchcs.o slatec/pchdf.o slatec/pchfd.o slatec/pchfe.o slatec/pchia.o slatec/pchic.o slatec/pchid.o slatec/pchim.o slatec/pchkt.o slatec/pchsp.o slatec/pchst.o slatec/pchsw.o slatec/pcoef.o slatec/polfit.o slatec/pvalue.o slatec/pythag.o slatec/r1mach.o slatec/radb2.o slatec/radb3.o slatec/radb4.o slatec/radb5.o slatec/radbg.o slatec/radf2.o slatec/radf3.o slatec/radf4.o slatec/radf5.o slatec/radfg.o slatec/rfftb.o slatec/rfftb1.o slatec/rfftf.o slatec/rfftf1.o slatec/rs.o slatec/sasum.o slatec/saxpy.o slatec/sdot.o slatec/sgeco.o slatec/sgedi.o slatec/sgefa.o slatec/sgesl.o slatec/snrm2.o slatec/spoco.o slatec/spodi.o slatec/spofa.o slatec/srot.o slatec/srotg.o slatec/sscal.o slatec/ssvdc.o slatec/sswap.o slatec/tql2.o slatec/tqlrat.o slatec/tred1.o slatec/tred2.o slatec/xercnt.o slatec/xerhlt.o slatec/xermsg.o slatec/xerprn.o slatec/xersve.o slatec/xgetua.o -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -fstrict-aliasing -o ../../blib/arch/auto/PDL/Slatec/Slatec.so  \
   -L/usr/lib/gcc/x86_64-pc-linux-gnu/13 -L/usr/lib -lgfortran -lm   \
  
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libm.so when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libm.a when searching for -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: skipping incompatible /usr/lib/libc.a when searching for -lc
slatec/rfftf.f:96:72: error: type of ‘rfftf1’ does not match original declaration [-Werror=lto-type-mismatch]
   96 |       CALL RFFTF1 (N,R,WSAVE,WSAVE(N+1),WSAVE(2*N+1))
      |                                                                        ^
slatec/rfftf1.f:2:23: note: ‘rfftf1’ was previously declared here
    2 |       SUBROUTINE RFFTF1 (N, C, CH, WA, IFAC)
      |                       ^
slatec/rfftf1.f:2:23: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
slatec/rfftb.f:95:72: error: type of ‘rfftb1’ does not match original declaration [-Werror=lto-type-mismatch]
   95 |       CALL RFFTB1 (N,R,WSAVE,WSAVE(N+1),WSAVE(2*N+1))
      |                                                                        ^
slatec/rfftb1.f:2:23: note: ‘rfftb1’ was previously declared here
    2 |       SUBROUTINE RFFTB1 (N, C, CH, WA, IFAC)
      |                       ^
slatec/rfftb1.f:2:23: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
slatec/ezffti.f:46:72: error: type of ‘ezfft1’ does not match original declaration [-Werror=lto-type-mismatch]
   46 |       CALL EZFFT1 (N,WSAVE(2*N+1),WSAVE(3*N+1))
      |                                                                        ^
slatec/ezfft1.f:2:23: note: ‘ezfft1’ was previously declared here
    2 |       SUBROUTINE EZFFT1 (N, WA, IFAC)
      |                       ^
slatec/ezfft1.f:2:23: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
pp-chcm.c:91:14: error: type of ‘pchcm_’ does not match original declaration [-Werror=lto-type-mismatch]
   91 | PDL_LongLong PDL_FORTRAN(pchcm)(PDL_LongLong *,PDL_Float *,PDL_Float *,PDL_Float *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *);
      |              ^
slatec/pchcm.f:2:22: note: return value type mismatch
    2 |       SUBROUTINE PCHCM (N, X, F, D, INCFD, SKIP, ISMON, IERR)
      |                      ^
slatec/pchcm.f:2:22: note: type ‘void’ should match type ‘PDL_LongLong’
slatec/pchcm.f:2:22: note: ‘pchcm’ was previously declared here
slatec/pchcm.f:2:22: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
pp-chcm.c:90:14: error: type of ‘dpchcm_’ does not match original declaration [-Werror=lto-type-mismatch]
   90 | PDL_LongLong PDL_FORTRAN(dpchcm)(PDL_LongLong *,PDL_Double *,PDL_Double *,PDL_Double *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *);
      |              ^
slatec/dpchcm.f:2:23: note: return value type mismatch
    2 |       SUBROUTINE DPCHCM (N, X, F, D, INCFD, SKIP, ISMON, IERR)
      |                       ^
slatec/dpchcm.f:2:23: note: type ‘void’ should match type ‘PDL_LongLong’
slatec/dpchcm.f:2:23: note: ‘dpchcm’ was previously declared here
slatec/dpchcm.f:2:23: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
pp-chid.c:89:7: error: type of ‘pchid_’ does not match original declaration [-Werror=lto-type-mismatch]
   89 | float PDL_FORTRAN(pchid)(PDL_LongLong *,PDL_Float *,PDL_Float *,PDL_Float *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *);
      |       ^
slatec/pchid.f:2:25: note: ‘pchid’ was previously declared here
    2 |       REAL FUNCTION PCHID (N, X, F, D, INCFD, SKIP, IA, IB, IERR)
      |                         ^
slatec/pchid.f:2:25: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
pp-chid.c:88:8: error: type of ‘dpchid_’ does not match original declaration [-Werror=lto-type-mismatch]
   88 | double PDL_FORTRAN(dpchid)(PDL_LongLong *,PDL_Double *,PDL_Double *,PDL_Double *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *);
      |        ^
slatec/dpchid.f:2:38: note: ‘dpchid’ was previously declared here
    2 |       DOUBLE PRECISION FUNCTION DPCHID (N, X, F, D, INCFD, SKIP, IA, IB,
      |                                      ^
slatec/dpchid.f:2:38: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
pp-chia.c:87:7: error: type of ‘pchia_’ does not match original declaration [-Werror=lto-type-mismatch]
   87 | float PDL_FORTRAN(pchia)(PDL_LongLong *,PDL_Float *,PDL_Float *,PDL_Float *,PDL_LongLong *,PDL_LongLong *,PDL_Float *,PDL_Float *,PDL_LongLong *);
      |       ^
slatec/pchia.f:2:25: note: ‘pchia’ was previously declared here
    2 |       REAL FUNCTION PCHIA (N, X, F, D, INCFD, SKIP, A, B, IERR)
      |                         ^
slatec/pchia.f:2:25: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
pp-chia.c:86:8: error: type of ‘dpchia_’ does not match original declaration [-Werror=lto-type-mismatch]
   86 | double PDL_FORTRAN(dpchia)(PDL_LongLong *,PDL_Double *,PDL_Double *,PDL_Double *,PDL_LongLong *,PDL_LongLong *,PDL_Double *,PDL_Double *,PDL_LongLong *);
      |        ^
slatec/dpchia.f:2:38: note: ‘dpchia’ was previously declared here
    2 |       DOUBLE PRECISION FUNCTION DPCHIA (N, X, F, D, INCFD, SKIP, A, B,
      |                                      ^
slatec/dpchia.f:2:38: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
pp-chfe.c:85:14: error: type of ‘pchfe_’ does not match original declaration [-Werror=lto-type-mismatch]
   85 | PDL_LongLong PDL_FORTRAN(pchfe)(PDL_LongLong *,PDL_Float *,PDL_Float *,PDL_Float *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *,PDL_Float *,PDL_Float *,PDL_LongLong *);
      |              ^
slatec/pchfe.f:2:22: note: return value type mismatch
    2 |       SUBROUTINE PCHFE (N, X, F, D, INCFD, SKIP, NE, XE, FE, IERR)
      |                      ^
slatec/pchfe.f:2:22: note: type ‘void’ should match type ‘PDL_LongLong’
slatec/pchfe.f:2:22: note: ‘pchfe’ was previously declared here
slatec/pchfe.f:2:22: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
pp-chfe.c:84:14: error: type of ‘dpchfe_’ does not match original declaration [-Werror=lto-type-mismatch]
   84 | PDL_LongLong PDL_FORTRAN(dpchfe)(PDL_LongLong *,PDL_Double *,PDL_Double *,PDL_Double *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *,PDL_Double *,PDL_Double *,PDL_LongLong *);
      |              ^
slatec/dpchfe.f:2:23: note: return value type mismatch
    2 |       SUBROUTINE DPCHFE (N, X, F, D, INCFD, SKIP, NE, XE, FE, IERR)
      |                       ^
slatec/dpchfe.f:2:23: note: type ‘void’ should match type ‘PDL_LongLong’
slatec/dpchfe.f:2:23: note: ‘dpchfe’ was previously declared here
slatec/dpchfe.f:2:23: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
pp-chfd.c:83:14: error: type of ‘pchfd_’ does not match original declaration [-Werror=lto-type-mismatch]
   83 | PDL_LongLong PDL_FORTRAN(pchfd)(PDL_LongLong *,PDL_Float *,PDL_Float *,PDL_Float *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *,PDL_Float *,PDL_Float *,PDL_Float *,PDL_LongLong *);
      |              ^
slatec/pchfd.f:2:22: note: return value type mismatch
    2 |       SUBROUTINE PCHFD (N, X, F, D, INCFD, SKIP, NE, XE, FE, DE, IERR)
      |                      ^
slatec/pchfd.f:2:22: note: type ‘void’ should match type ‘PDL_LongLong’
slatec/pchfd.f:2:22: note: ‘pchfd’ was previously declared here
slatec/pchfd.f:2:22: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
pp-chfd.c:82:14: error: type of ‘dpchfd_’ does not match original declaration [-Werror=lto-type-mismatch]
   82 | PDL_LongLong PDL_FORTRAN(dpchfd)(PDL_LongLong *,PDL_Double *,PDL_Double *,PDL_Double *,PDL_LongLong *,PDL_LongLong *,PDL_LongLong *,PDL_Double *,PDL_Double *,PDL_Double *,PDL_LongLong *);
      |              ^
slatec/dpchfd.f:2:23: note: return value type mismatch
    2 |       SUBROUTINE DPCHFD (N, X, F, D, INCFD, SKIP, NE, XE, FE, DE, IERR)
      |                       ^
slatec/dpchfd.f:2:23: note: type ‘void’ should match type ‘PDL_LongLong’
slatec/dpchfd.f:2:23: note: ‘dpchfd’ was previously declared here
slatec/dpchfd.f:2:23: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
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:473: ../../blib/arch/auto/PDL/Slatec/Slatec.so] Error 1

@mohawk2
Copy link
Member

mohawk2 commented Apr 1, 2024

That last one is because a LOGICAL, despite being apparently the same size as a REAL (i.e. 4 bytes - https://stackoverflow.com/questions/22125504/why-we-need-1-2-4-8-bytes-to-store-logical-variable-in-fortran), isn't recognised as such by the LTO.

@mohawk2
Copy link
Member

mohawk2 commented Apr 1, 2024

The remaining problem is that the FFT routines are a bit of a nightmare because they have a working array of 4-byte floats, the end of which gets used as 4-byte integers, which the LTO doesn't like. Since those routines are largely wrappers to other routines that keep the floats and integers separate, I can switch the PDL binding to just use those directly.

@thesamesam
Copy link

Once this is all sorted, I will look at sorting out the Gentoo packaging too. Thank you very much!

@mohawk2
Copy link
Member

mohawk2 commented Apr 2, 2024

@eli-schwartz I believe the above commit fixes this. Can you confirm you agree?

If you do, then @thesamesam do you need any assistance with that packaging? The latest PDL is having a problem with 32-bit (see #469), so please be aware of that.

@mohawk2
Copy link
Member

mohawk2 commented Apr 2, 2024

Re-opening so @eli-schwartz can close when it's agreed as done.

@mohawk2 mohawk2 reopened this Apr 2, 2024
@eli-schwartz
Copy link
Author

make[2]: Entering directory '/tmp/pdl/Libtmp/Slatec'
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Slatec.bs ../../blib/arch/auto/PDL/Slatec/Slatec.bs 644
make[2]: *** No rule to make target 'slatec/rfftb.f', needed by 'slatec/rfftb.o'.  Stop.

pulling and incrementally building did not manage to recalculate the Makefiles. Doing a scratch build...

@eli-schwartz
Copy link
Author

Yes, everything compiles cleanly with LTO now. :) Thanks!

@mohawk2
Copy link
Member

mohawk2 commented Apr 3, 2024

Thank you for the report, and for your engagement! Slatec's Makefile.PL does a bit of a shotgun approach and generates a target for each .f file that glob shows in the slatec directory. When one gets removed (as I did by obsoleting rfft[fb].f), you need to regenerate the Makefile, as you did.

Will Gentoo's PDL package be getting updated?

@thesamesam
Copy link

thesamesam commented Apr 10, 2024

@mohawk2 I've just updated our package to 2.087 and fixed some other lingering issues on our side so should be able to keep pace better now too. Thank you very much!

@mohawk2
Copy link
Member

mohawk2 commented Apr 10, 2024

@thesamesam Thank you right back! Please let me know if there's anything you need/want from us, and/or any other problems you spot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants