Solved Has anyone successfully built Kodi using -flto
#1
Is it possible to build Kodi using the -flto switch?  When I tried doing so, my build ended in multiple errors.

Just a sampling:
Code:
...
/tmp/kodi-x11.6b8G37.ltrans103.ltrans.o:<artificial>:function lpc_apply_welch_window_sse2: error: undefined reference to 'pd_1'
/tmp/kodi-x11.6b8G37.ltrans103.ltrans.o:<artificial>:function lpc_apply_welch_window_sse2: error: undefined reference to 'pd_2'
/tmp/kodi-x11.6b8G37.ltrans103.ltrans.o:<artificial>:function lpc_compute_autocorr_sse2: error: undefined reference to 'pd_1'
/tmp/kodi-x11.6b8G37.ltrans103.ltrans.o:<artificial>:function lpc_compute_autocorr_sse2: error: undefined reference to 'pd_1'
/tmp/kodi-x11.6b8G37.ltrans103.ltrans.o:<artificial>:function lpc_compute_autocorr_sse2: error: undefined reference to 'pd_1'
/tmp/kodi-x11.6b8G37.ltrans120.ltrans.o:<artificial>:function yuv2rgb565_X_ar_mmx: error: undefined reference to 'bF8'
/tmp/kodi-x11.6b8G37.ltrans120.ltrans.o:<artificial>:function yuv2rgb565_X_ar_mmx: error: undefined reference to 'bFC'
/tmp/kodi-x11.6b8G37.ltrans120.ltrans.o:<artificial>:function yuv2rgb565_X_ar_mmx: error: undefined reference to 'bF8'
/tmp/kodi-x11.6b8G37.ltrans120.ltrans.o:<artificial>:function yuv2rgb565_X_mmx: error: undefined reference to 'bF8'
/tmp/kodi-x11.6b8G37.ltrans120.ltrans.o:<artificial>:function yuv2rgb565_X_mmx: error: undefined reference to 'bFC'
/tmp/kodi-x11.6b8G37.ltrans120.ltrans.o:<artificial>:function yuv2rgb565_X_mmx: error: undefined reference to 'bF8'
/tmp/kodi-x11.6b8G37.ltrans120.ltrans.o:<artificial>:function yuv2rgb565_2_mmx: error: undefined reference to 'bFC'
/tmp/kodi-x11.6b8G37.ltrans120.ltrans.o:<artificial>:function yuv2rgb565_1_mmx: error: undefined reference to 'bFC'
...

Complete build log: https://gist.github.com/graysky2/951bb36...c75ba99dd3
Need help programming a Streamzap remote?
Reply
#2
I've been building v19 with lto for months.
These errors seems to come from linking to ffmpeg libs.
However my buildsystem and tuning is quite different (tuned for ryzen).
I build ffmpeg separately without lto because I've stumbled into issues with ltoed ffmpeg before.

Where does -fno-plt comes from? I'm not familiar with what this flag actually may do.

As a wild guess try building with ld.bfd as opposed to gold.
-DENABLE_LDGOLD=OFF
AFAIK gold is (almost) dead and not being actively developed.

You also have a lot of nasm warnings (nasm 2.15.x) which can be fixed with a patch from upstream ffmpeg.
Reply
#3
@asavah - Thanks for the reply.

Firstly, the -fno-plt flag is an Arch Linux default:
Code:
CFLAGS="-march=x86-64 -O2 -pipe -fno-plt"

I tried removing it and using this as the CFLAGS but it ended in the same errors (undefined reference to xxx).
Code:
-march=haswell -mtune=haswell -O2 -pipe -flto

Next I tried adding the alternative linker you mentioned but that too ended in errors.

Can you provide a link to the upstream patch to which you referred to silence or fix underlying problem with the nasm 2.15.x warns?
Need help programming a Streamzap remote?
Reply
#4
See https://trac.ffmpeg.org/ticket/8771 , the last post has link to the relevant commits, you need all 3 of them, all apply fine to kodi ffmpeg fork.
But I don't think these patches will fix your linking issue.
Try (no idea how and where) preventing injection of -flto into ffmpeg cflags.

I'll try building both ffmpeg and kodi with lto and see if I can reproduce this.

Update: nope, could not reproduce.
Reply
#5
Thanks for the link to the patches.

To simplify things, I just tried building ffmpeg alone since it is a smaller project/faster to build.
I used these:
Code:
 
  unset CFLAGS CXXFLAGS
  export CFLAGS=" -march=haswell -mtune=haswell -O2 -pipe -fno-plt -fdiagnostics-color -flto"
  export CXXFLAGS="${CFLAGS}"

I was able to successfully build ffmpeg.  I wonder if something in the kodi cmake stuff some how causes differences when building kodi vs just building ffmpeg alone?

Here is the build log building ffmpeg: https://gist.github.com/graysky2/ee4452c...804774fa55
Need help programming a Streamzap remote?
Reply
#6
But did kodi build succeed with "standalone" ffmpeg build?
Reply
#7
kodi has native support for building with lto for a while now.

option(USE_LTO "Enable link time optimization. Specify an int for number of parallel jobs" OFF)
Reply
#8
@asavah - I did not try building kodi without ffmpeg.  I just built ffmpeg (totally separate package).

@wsnipex - I added -DENABLE_USE_LTO=ON to my cmake stanza but found this in the output:
Code:
CMake Warning:
  Manually-specified variables were not used by the project:

    ENABLE_USE_LTO

As well, the build failed at the linking step as before.  Here is the build log if there is something diagnostic in there: https://gist.github.com/graysky2/a484fb9...7f2945e939

EDIT: did you intend me to build with the cmake option enabled but without the hardcoded make flag?
Need help programming a Streamzap remote?
Reply
#9
@graysky it's -DUSE_LTO=ON or even better -DUSE_LTO=$AMOUNT_OF_CPU_CORES, my bad I assumed you were using it already so I didn't check cmake output for it.
Reply
#10
Thanks for the tip.  Removing -flto from my CFLAGS and adding -DUSE_LTO=8 to my cmake stanza worked.  I understand there are some secondary benefits of minor speed increases so this is nice.  I did notice a 9% size reduction (overall package).
Code:
# pacman -U kodi-haswell-19.0b2.56932.962f842855-1-x86_64.pkg.tar.zst
loading packages...
resolving dependencies...
looking for conflicting packages...

Packages (1) kodi-haswell-19.0b2.56932.962f842855-1

Total Installed Size:  82.12 MiB
Net Upgrade Size:      -8.24 MiB

:: Proceed with installation? [Y/n]
Need help programming a Streamzap remote?
Reply
#11
size should decrease even more if you use internal ffmpeg.
Reply
#12
(2021-01-15, 08:55)wsnipex Wrote: size should decrease even more if you use internal ffmpeg.

I am using internal ffmpeg.  Here is my cmake stanza:
Code:
  _args=(
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_INSTALL_LIBDIR=/usr/lib
    -DUSE_LTO=8
    -DENABLE_EVENTCLIENTS=ON
    -DENABLE_INTERNAL_FFMPEG=ON
    -DENABLE_INTERNAL_FMT=ON
    -DENABLE_INTERNAL_CROSSGUID=ON
    -DENABLE_INTERNAL_FSTRCMP=ON
    -DENABLE_INTERNAL_FLATBUFFERS=ON
    -DENABLE_INTERNAL_SPDLOG=ON
    -DENABLE_MYSQLCLIENT=ON
    -Dlibdvdcss_URL="/libdvdcss-1.4.2-Leia-Beta-5.tar.gz"
    -Dlibdvdnav_URL="/libdvdnav-6.0.0-Leia-Alpha-3.tar.gz"
    -Dlibdvdread_URL="/libdvdread-6.0.0-Leia-Alpha-3.tar.gz"
    -DFFMPEG_URL="/ffmpeg-4.3.1-Matrix-Beta1.tar.gz"
    -DFMT_URL="/fmt-6.1.2.tar.gz"
    -DCROSSGUID_URL="/crossguid-8f399e8bd4.tar.gz"
    -DFSTRCMP_URL="/fstrcmp-0.7.D001.tar.gz"
    -DFLATBUFFERS_URL="/flatbuffers-1.11.0.tar.gz"
    -DSPDLOG_URL="/spdlog-1.5.0.tar.gz"
    -DCORE_PLATFORM_NAME=x11
    -DAPP_RENDER_SYSTEM=gl
  )

cmake "${_args[@]}" ../xbmc
Need help programming a Streamzap remote?
Reply
#13
ok, for reference: this is the binary from our ubuntu PPA:
-rwxr-xr-x 1 root root 55M Mai 12  2013 /usr/lib/x86_64-linux-gnu/kodi/kodi.bin
Reply
#14
My build of kodi (lto, ld.bfd), external ffmpeg (static libs, no lto), multi-windowing (xorg + wayland + gbm).

-rwxr-xr-x 1 root root 45M Jan 13 21:04 /usr/lib/kodi/kodi.bin
Reply
#15
(2021-01-15, 15:04)wsnipex Wrote: ok, for reference: this is the binary from our ubuntu PPA:
-rwxr-xr-x 1 root root 55M Mai 12  2013 /usr/lib/x86_64-linux-gnu/kodi/kodi.bin

I do not have a kodi.bin but I do have:
Code:
-rwxr-xr-x 1 root root 45M Jan 14 13:03 /usr/lib/kodi/kodi-x11
Need help programming a Streamzap remote?
Reply

Logout Mark Read Team Forum Stats Members Help
Has anyone successfully built Kodi using -flto0