Introduce WITH(OUT)_LTO? (was: Re: svn commit: r362987 - in head: contrib/bc usr.bin/gh-bc)

Stefan Eßer se at freebsd.org
Wed Jul 8 08:28:56 UTC 2020


Am 08.07.20 um 09:01 schrieb Mark Millard:
> The following is more informational than anything as far
> as I'm concerned. But there may be implications that I'm
> unaware of. (I sometimes experiment with toolchain use
> to see what the current status is for such use.)
> 
> I attempted to build a system for 32-bit powerpc using clang
> and binutils, building head -r363000 ( from -r363000 ). (This
> was a cross build, amd64 -> powerpc.) It got a new type of
> failure, compared to my past experience:

Hi Mark,

thank you for the report. I have tested with "make universe" (with
default settings) that this version builds on all architectures,
but Ed Maste has already disabled -flto for powerpc64, due to run
time issues (floating point exception, IIRC).

I know that you are actively working on PowerPC and I'd appreciate,
if you could provide me with information on which parameters cause
breakage and which work for you. The combination of CLANG with LTO
and GNU binutils cannot work - CLANG and GCC use incompatible file
formats to represent the intermediate object files.

This version of bc uses advanced algorithms (compared to the one
it replaced) for much reduced time complexity (a factor of more
than 100 for large numbers has been observed). It uses layering
for correctness, e.g. a set of "vector" management functions, that
are built as a separate compile unit. Compiling with -flto lets the
linker replace many function calls with constant parameters with
much more efficient inline instructions, resulting in 30% higher
performance. The code could be re-arranged to use inline functions
instead of relying on -flto, but this would be a lot of effort and
might make the code much harder to maintain.

If there is a condition that could be added to the Makefile to not
enable LTO if CLANG+binutils or GCC+LLD are mixed, then I'm willing
to add it. If more programs were to be built with LTO for performance
reasons, then it might be a good idea to have a global parameter that
controls whether lTO may be used, though.


TL;DR

Perhaps we could add a WITH(OUT)_LTO option that only affects specific
programs that get a significant performance boost from building with
LTO. IMHO, using LTO is preferable to the introduction of inline
functions in source files that fall into that category.

WITHOUT_LTO could be implied on platforms that are known to not fully
support -flto with default their compiler and linker. And it could be
set by the user when non-default build tools are used.

This would allow to use -flto for specific programs without the need
to make this optimization conditional on compilers or architectures.

Best regards, STefan

> --- gh-bc.full ---
> /usr/local/powerpc-unknown-freebsd13.0/bin/ld: /usr/bin/../lib/LLVMgold.so: error loading plugin: Cannot open "/usr/bin/../lib/LLVMgold.so"
> cc: error: linker command failed with exit code 1 (use -v to see invocation)
> *** [gh-bc.full] Error code 1
> 
> Yep: /usr/lib/LLVMgold.so when -B/usr/local/powerpc-unknown-freebsd13.0/bin/
> was in use.
> 
> I turns out that the link of gh-bc used -flto :
> 
> make[4]: stopped in /usr/src/usr.bin/gh-bc
> .ERROR_TARGET='gh-bc.full'
> .ERROR_META_FILE='/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.powerpc/usr.bin/gh-bc/gh-bc.full.meta'
> .MAKE.LEVEL='4'
> MAKEFILE=''
> .MAKE.MODE='meta missing-filemon=yes missing-meta=yes silent=yes verbose'
> _ERROR_CMD='cc -target powerpc-unknown-freebsd13.0 --sysroot=/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.powerpc/tmp -B/usr/local/powerpc-unknown-freebsd13.0/bin/ -O2 -pipe -fno-common -B/usr/local/powerpc-unknown-freebsd13.0/bin/ -DMAINEXEC=bc -DNLSPATH=/usr/share/nls/%L/%N.cat -DBC_ENABLED -DBC_ENABLE_PROMPT -DBC_ENABLE_LONG_OPTIONS -DBC_ENABLE_EXTRA_MATH -DBC_ENABLE_HISTORY -DBC_ENABLE_RAND -DDC_ENABLED -DNDEBUG -DVERSION=3.1.1 -I/usr/src/contrib/bc/include -DBC_ENABLE_NLS=1 -flto -g -std=gnu99 -Wno-format-zero-length -fstack-protector-strong -Wsystem-headers -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -Wold-style-definition -Wno-pointer-sign -Wmissing-variable-declarations -Wthread-safety -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Qunused-arguments  -Wl,--secure-plt  -o gh-bc.full args.o data.o file.o lang.o lex.o main.o num.o parse.o program.o read.o vector.o vm.o bc/bc.o bc/lex.o bc/parse.o dc/dc.o dc/lex.o dc/parse.o history/history.o bc_help.o dc_help.o lib.o lib2.o opt.o rand/rand.o  ;'
> .CURDIR='/usr/src/usr.bin/gh-bc'
> .MAKE='make'
> .OBJDIR='/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.powerpc/usr.bin/gh-bc'
> .TARGETS='all'
> DESTDIR='/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.powerpc/tmp'
> LD_LIBRARY_PATH=''
> MACHINE='powerpc'
> MACHINE_ARCH='powerpc'
> MAKEOBJDIRPREFIX=''
> MAKESYSPATH='/usr/src/share/mk'
> MAKE_VERSION='20200606'
> PATH='/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/usr/sbin:/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/usr/bin:/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/legacy/usr/sbin:/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/legacy/usr/bin:/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/legacy/bin:/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.powerpc/tmp/legacy/usr/libexec::/sbin:/bin:/usr/sbin:/usr/bin'
> SRCTOP='/usr/src'
> OBJTOP='/usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.powerpc'
> .MAKE.MAKEFILES='/usr/src/share/mk/sys.mk /usr/src/share/mk/local.sys.env.mk /usr/src/share/mk/src.sys.env.mk /root/src.configs/src.conf.powerpc-clang_altbinutils-bootstrap.amd64-host /usr/src/share/mk/bsd.mkopt.mk /usr/src/share/mk/src.sys.obj.mk /usr/src/share/mk/auto.obj.mk /usr/src/share/mk/bsd.suffixes.mk /root/src.configs/make.conf /usr/src/share/mk/local.sys.mk /usr/src/share/mk/src.sys.mk /dev/null /usr/src/usr.bin/gh-bc/Makefile /usr/src/share/mk/src.opts.mk /usr/src/share/mk/bsd.own.mk /usr/src/share/mk/bsd.opts.mk /usr/src/share/mk/bsd.cpu.mk /usr/src/share/mk/bsd.compiler.mk /usr/src/share/mk/bsd.linker.mk /usr/src/share/mk/bsd.prog.mk /usr/src/share/mk/bsd.init.mk /usr/src/share/mk/local.init.mk /usr/src/share/mk/src.init.mk /usr/src/usr.bin/gh-bc/../Makefile.inc /usr/src/share/mk/bsd.libnames.mk /usr/src/share/mk/src.libnames.mk /usr/src/share/mk/bsd.nls.mk /usr/src/share/mk/bsd.confs.mk /usr/src/share/mk/bsd.files.mk /usr/src/share/mk/bsd.dirs.mk /usr/src/share/mk/bsd.incs.mk /usr/src/share/mk/bsd.links.mk /usr/src/share/mk/bsd.man.mk /usr/src/share/mk/bsd.dep.mk /usr/src/share/mk/bsd.clang-analyze.mk /usr/src/share/mk/bsd.obj.mk /usr/src/share/mk/bsd.subdir.mk /usr/src/share/mk/bsd.sys.mk'
> .PATH='. /usr/src/usr.bin/gh-bc /usr/src/contrib/bc/src /usr/src/contrib/bc/gen /usr/src/contrib/bc/manuals /usr/obj/powerpcvtsc_clang_altbinutils/powerpc.powerpc/usr/src/powerpc.powerpc/usr.bin/gh-bc'
> 1 error
> 
> ===
> Mark Millard
> marklmi at yahoo.com
> ( dsl-only.net went
> away in early 2018-Mar)
> 


More information about the freebsd-ppc mailing list