freebsd-dev/share/mk
Alex Richardson 0e1e341b48 Stop using lorder and ranlib when building libraries
Use of ranlib or lorder is no longer necessary with current linkers
(probably anything newer than ~1990) and ar's ability to create an object
index and symbol table in the archive.
Currently the build system uses lorder+tsort to sort the .o files in
dependency order so that a single-pass linker can use them. However,
we can use the -s flag to ar to add an index to the .a file which makes
lorder unnecessary.
Running ar -s is equivalent to running ranlib afterwards, so we can also
skip the ranlib invocation.

Similarly, we don't have to pass the .o files for shared libraries in
dependency order since both ld.bfd and ld.lld will correctly resolve
references between the .o files.

This removes many fork()+execve calls for each library so should speed up
builds a bit. Additionally lorder.sh uses a regular expression that is not
supported by the macOS libc or glibc and results in many warnings when
cross-building (see D25989).

There is one functional change: lorder.sh removed duplicated .o files
from the linker command line which now no longer happens. I fixed the duplicates
in the base system in r364649. I also checked the ports tree for uses of
bsd.lib.mk and found one duplicate source file which I fixed in r548168.
Most ports use CMake/autotools rather than bsd.lib.mk but if this breaks any
ports that I missed in my search please let me know.

Avoiding the shell script actually speeds up the linking step noticeably: I
measured how long it takes to rebuild the .a and .so files for lib/libc using a
basic benchmark: `rm $LIBC_OBJDIR/*.so* $LIBC_OBJDIR/*.a* && /usr/bin/time make -DWITHOUT_TESTS -s > /dev/null`
Without this change ~4.5 seconds and afterwards ~3.1 seconds.
Looking at truss -cf output we can see that the number fork() system
calls goes down from 27 to 12 (and the speedup while tracing is more
noticeable: 81 seconds -> 65 seconds).

See also https://www.gnu.org/software/coreutils/manual/html_node/tsort-background.html
for some more background:
This whole procedure has been obsolete since about 1980, because Unix
archives now contain a symbol table (traditionally built by ranlib, now
generally built by ar itself), and the Unix linker uses the symbol table
to effectively make multiple passes over an archive file.

Or alternatively https://www.unix.com/man-page/osf1/1/lorder/:
The lorder command is essentially obsolete.  Use the following command in
its place: % ar -ts file.a

Reviewed By:	 emaste, imp, dim
Differential Revision: https://reviews.freebsd.org/D26044
2020-09-17 15:07:25 +00:00
..
atf.test.mk Another round of attempting to squelch -Wdeprecated-declarations, which 2019-09-17 06:07:08 +00:00
auto.obj.mk Ensure .OBJDIR has known value 2017-11-04 21:02:26 +00:00
bsd.arch.inc.mk
bsd.clang-analyze.mk Move all sources from the llvm project into contrib/llvm-project. 2019-12-20 19:53:05 +00:00
bsd.compat.mk Move -L${LIBCOMPATTMP}/usr/lib${libcompat} from CFLAGS to LDFLAGS. 2020-08-17 17:17:33 +00:00
bsd.compiler.mk Avoid recomputing COMPILER_/LINKER_ variables when set explicitly 2020-08-26 10:21:38 +00:00
bsd.confs.mk pkgbase: Create a FreeBSD-utilities package and make it the default one 2019-09-05 14:15:47 +00:00
bsd.cpu.mk When CPUTYPE is an architecture name use -march 2020-09-02 11:53:26 +00:00
bsd.crunchgen.mk rescue: Restore 'make depend' call to fix WITH_META_MODE after r334008. 2018-05-24 18:49:19 +00:00
bsd.dep.mk Allow per-file lex and yacc options. 2019-11-15 21:19:06 +00:00
bsd.dirs.mk pkgbase: Create a FreeBSD-utilities package and make it the default one 2019-09-05 14:15:47 +00:00
bsd.doc.mk pkgbase: Create a FreeBSD-utilities package and make it the default one 2019-09-05 14:15:47 +00:00
bsd.dtb.mk Introduce bsd.sysdir.mk to consolidate looking for the kernel. 2019-11-21 15:59:33 +00:00
bsd.endian.mk Use MACHINE_CPUARCH when checking for arm64 2020-09-14 16:12:28 +00:00
bsd.files.mk Use ${.ALLSRC:Ninstalldirs-*} instead of assuming order of .ALLSRC 2019-12-10 12:12:48 +00:00
bsd.incs.mk pkgbase: use -dev,-dbg instead of -development,-debug 2020-05-20 19:45:22 +00:00
bsd.info.mk Revert r301079. 2016-06-03 19:25:36 +00:00
bsd.init.mk NO_OBJ: Always fix .OBJDIR regardless of AUTO_OBJ. 2020-04-07 17:07:04 +00:00
bsd.kmod.mk Introduce bsd.sysdir.mk to consolidate looking for the kernel. 2019-11-21 15:59:33 +00:00
bsd.lib.mk Stop using lorder and ranlib when building libraries 2020-09-17 15:07:25 +00:00
bsd.libnames.mk lib: add libnetmap 2020-08-28 20:03:54 +00:00
bsd.linker.mk Avoid recomputing COMPILER_/LINKER_ variables when set explicitly 2020-08-26 10:21:38 +00:00
bsd.links.mk Reapply r295227: Stop hiding link install commands. 2017-11-06 19:33:50 +00:00
bsd.man.mk Correct link metadata created when installing with -DNO_ROOT. 2018-06-29 16:07:56 +00:00
bsd.mkopt.mk Document logic for __DEFAULT_DEPENDENT_OPTIONS 2019-09-16 00:32:23 +00:00
bsd.nls.mk Move all of the directory path into the DIR part of the component and make the 2018-05-31 13:26:12 +00:00
bsd.obj.mk NO_OBJ: Always fix .OBJDIR regardless of AUTO_OBJ. 2020-04-07 17:07:04 +00:00
bsd.opts.mk Remove the SYMVER build option. 2020-04-30 22:08:40 +00:00
bsd.own.mk Standardize EFI's ESP mount point. 2019-11-20 21:06:29 +00:00
bsd.port.mk
bsd.port.options.mk
bsd.port.post.mk
bsd.port.pre.mk
bsd.port.subdir.mk
bsd.prog.mk bsd.prog.mk: split MK_PIE test for clarity 2020-06-02 00:46:15 +00:00
bsd.progs.mk PROGS: Build common sources before recursed PROGS_TARGETS as well when building. 2019-09-04 18:32:11 +00:00
bsd.README Allow bsd.compat.mk to be reliably included outside Makefile.inc1. 2019-10-31 20:37:19 +00:00
bsd.snmpmod.mk Rework some multi-output target dependency handling. 2019-07-19 00:15:25 +00:00
bsd.subdir.mk Support SUBDIR.${MK_FOO}.${MK_BAR} expresssions. 2020-03-17 18:17:32 +00:00
bsd.suffixes-posix.mk Extract suffix rules into bsd.suffixes[-posix].mk. 2016-10-12 00:42:46 +00:00
bsd.suffixes.mk Similar to r335710 avoid ccache when linking a .cc file directly. 2019-06-15 17:08:18 +00:00
bsd.symver.mk Remove the SYMVER build option. 2020-04-30 22:08:40 +00:00
bsd.sys.mk Use MACHINE_CPUARCH when checking for arm64 2020-09-14 16:12:28 +00:00
bsd.sysdir.mk Introduce bsd.sysdir.mk to consolidate looking for the kernel. 2019-11-21 15:59:33 +00:00
bsd.test.mk Add googletest.test.mk and integrate into bsd.test.mk 2019-02-20 01:09:03 +00:00
dirdeps-options.mk Use .undef per variable 2019-01-15 23:35:53 +00:00
dirdeps-targets.mk Update dirdeps.mk and gendirdeps.mk 2019-12-11 17:38:15 +00:00
dirdeps.mk Update dirdeps.mk and gendirdeps.mk 2019-12-11 17:38:15 +00:00
gendirdeps.mk Update dirdeps.mk and gendirdeps.mk 2019-12-11 17:38:15 +00:00
googletest.test.inc.mk Work around two -Werror warning issues in googletest, which have been 2020-01-31 18:26:23 +00:00
googletest.test.mk Fix a typo 2019-02-21 03:36:09 +00:00
host-target.mk
install-new.mk
kmod.opts.mk Add a kmod.opts.mk. 2019-11-21 18:14:26 +00:00
local.autodep.mk Update dirdeps.mk et al to latest 2018-08-02 21:33:45 +00:00
local.dirdeps-options.mk retire BSD_CRTBEGIN option 2020-01-31 18:04:04 +00:00
local.dirdeps.mk retire the LLVM_LIBUNWIND option 2020-02-29 12:43:43 +00:00
local.gendirdeps.mk retire the LLVM_LIBUNWIND option 2020-02-29 12:43:43 +00:00
local.init.mk Include ${.CURDIR}/local.init.mk if it exists 2020-03-31 15:59:29 +00:00
local.meta.sys.mk Remove sparc64 specific buid-system hacks 2020-02-26 18:49:20 +00:00
local.sys.env.mk AUTO_OBJ: Hide 'creating dirs' output with 'make -s'. 2017-11-08 16:03:58 +00:00
local.sys.mk META_MODE: Delete build targets that fail. 2019-06-15 17:08:28 +00:00
Makefile Install bsd.sysdir.mk. 2019-11-21 19:54:10 +00:00
meta2deps.py Update dirdeps.mk et al to latest 2018-08-02 21:33:45 +00:00
meta2deps.sh retire the LLVM_LIBUNWIND option 2020-02-29 12:43:43 +00:00
meta.autodep.mk Update dirdeps.mk et al to latest 2018-08-02 21:33:45 +00:00
meta.stage.mk Update dirdeps.mk et al to latest 2018-08-02 21:33:45 +00:00
meta.subdir.mk
meta.sys.mk Update dirdeps.mk and gendirdeps.mk 2019-12-11 17:38:15 +00:00
netbsd-tests.test.mk
plain.test.mk Feex a cuple of small typos 2018-07-27 10:44:38 +00:00
src.init.mk
src.libnames.mk libifconfig now depends on libm due to usage of log10(). 2020-09-02 22:10:08 +00:00
src.lua.mk Add flua to the base system, install to /usr/libexec 2019-11-18 23:21:13 +00:00
src.opts.mk [PowerPC] Remove obsolete MK_LOADER_FORCE_LE 2020-09-15 04:22:28 +00:00
src.sys.env.mk META_MODE: Allow 'make all install' to work with filemon. 2020-01-17 14:29:27 +00:00
src.sys.mk userland build: replace -fno-common with ${CFCOMMONFLAG} 2020-04-10 14:01:07 +00:00
src.sys.obj.mk tinderbox: Only build clang/lld once if needed. 2018-06-27 16:58:10 +00:00
src.tools.mk Normalize deployment tools usage and definitions by putting into one place 2020-04-07 02:46:22 +00:00
stage-install.sh
suite.test.mk In suite.test.mk, test if ${DESTDIR} exists before attempting to run 2019-09-25 17:52:59 +00:00
sys.dependfile.mk
sys.mk Stop using lorder and ranlib when building libraries 2020-09-17 15:07:25 +00:00
tap.test.mk Feex a cuple of small typos 2018-07-27 10:44:38 +00:00
version_gen.awk share and pc-sysinstall: adoption of SPDX licensing ID tags. 2017-11-27 15:28:26 +00:00