cosmopolitan/third_party/lua/BUILD.mk

311 lines
8.6 KiB
Makefile
Raw Normal View History

#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#── vi: set noet ft=make ts=8 sw=8 fenc=utf-8 :vi ────────────────────┘
PKGS += THIRD_PARTY_LUA
THIRD_PARTY_LUA_COMS = \
o/$(MODE)/third_party/lua/lua.com \
o/$(MODE)/third_party/lua/luac.com
THIRD_PARTY_LUA_BINS = \
$(THIRD_PARTY_LUA_COMS) \
$(THIRD_PARTY_LUA_COMS:%=%.dbg)
THIRD_PARTY_LUA_CHECKS = \
$(THIRD_PARTY_LUA_A).pkg \
$(THIRD_PARTY_LUA_UNIX).pkg \
$(THIRD_PARTY_LUA_HDRS:%=o/$(MODE)/%.ok) \
o/$(MODE)/third_party/lua/lua.com.pkg \
o/$(MODE)/third_party/lua/luac.com.pkg
################################################################################
# lua.a
THIRD_PARTY_LUA = \
$(THIRD_PARTY_LUA_A_DEPS) \
$(THIRD_PARTY_LUA_A)
THIRD_PARTY_LUA_ARTIFACTS += \
THIRD_PARTY_LUA_A
THIRD_PARTY_LUA_A = \
o/$(MODE)/third_party/lua/lua.a
THIRD_PARTY_LUA_A_HDRS = \
third_party/lua/cosmo.h \
third_party/lua/lapi.h \
third_party/lua/lauxlib.h \
third_party/lua/lcode.h \
third_party/lua/lctype.h \
third_party/lua/ldebug.h \
third_party/lua/ldo.h \
third_party/lua/lfunc.h \
third_party/lua/lgc.h \
third_party/lua/llex.h \
third_party/lua/llimits.h \
third_party/lua/lmem.h \
third_party/lua/lobject.h \
third_party/lua/lopcodes.h \
third_party/lua/lparser.h \
third_party/lua/lprefix.h \
third_party/lua/lrepl.h \
third_party/lua/lstate.h \
third_party/lua/lstring.h \
third_party/lua/ltable.h \
third_party/lua/ltests.h \
third_party/lua/ltm.h \
third_party/lua/lua.h \
third_party/lua/luaconf.h \
third_party/lua/lualib.h \
third_party/lua/lundump.h \
third_party/lua/lvm.h \
third_party/lua/lzio.h \
third_party/lua/tms.h \
third_party/lua/visitor.h
THIRD_PARTY_LUA_A_INCS = \
third_party/lua/ljumptab.inc \
third_party/lua/lopnames.inc
THIRD_PARTY_LUA_A_SRCS = \
third_party/lua/lapi.c \
third_party/lua/lauxlib.c \
third_party/lua/lbaselib.c \
third_party/lua/lcode.c \
third_party/lua/lcorolib.c \
third_party/lua/ldblib.c \
third_party/lua/ldebug.c \
third_party/lua/ldo.c \
third_party/lua/ldump.c \
third_party/lua/lfunc.c \
third_party/lua/lgc.c \
third_party/lua/linit.c \
third_party/lua/liolib.c \
third_party/lua/llex.c \
2022-07-09 12:49:19 +00:00
third_party/lua/llock.c \
third_party/lua/lmathlib.c \
third_party/lua/lmem.c \
Release Cosmopolitan v3.3 This change upgrades to GCC 12.3 and GNU binutils 2.42. The GNU linker appears to have changed things so that only a single de-duplicated str table is present in the binary, and it gets placed wherever the linker wants, regardless of what the linker script says. To cope with that we need to stop using .ident to embed licenses. As such, this change does significant work to revamp how third party licenses are defined in the codebase, using `.section .notice,"aR",@progbits`. This new GCC 12.3 toolchain has support for GNU indirect functions. It lets us support __target_clones__ for the first time. This is used for optimizing the performance of libc string functions such as strlen and friends so far on x86, by ensuring AVX systems favor a second codepath that uses VEX encoding. It shaves some latency off certain operations. It's a useful feature to have for scientific computing for the reasons explained by the test/libcxx/openmp_test.cc example which compiles for fifteen different microarchitectures. Thanks to the upgrades, it's now also possible to use newer instruction sets, such as AVX512FP16, VNNI. Cosmo now uses the %gs register on x86 by default for TLS. Doing it is helpful for any program that links `cosmo_dlopen()`. Such programs had to recompile their binaries at startup to change the TLS instructions. That's not great, since it means every page in the executable needs to be faulted. The work of rewriting TLS-related x86 opcodes, is moved to fixupobj.com instead. This is great news for MacOS x86 users, since we previously needed to morph the binary every time for that platform but now that's no longer necessary. The only platforms where we need fixup of TLS x86 opcodes at runtime are now Windows, OpenBSD, and NetBSD. On Windows we morph TLS to point deeper into the TIB, based on a TlsAlloc assignment, and on OpenBSD/NetBSD we morph %gs back into %fs since the kernels do not allow us to specify a value for the %gs register. OpenBSD users are now required to use APE Loader to run Cosmo binaries and assimilation is no longer possible. OpenBSD kernel needs to change to allow programs to specify a value for the %gs register, or it needs to stop marking executable pages loaded by the kernel as mimmutable(). This release fixes __constructor__, .ctor, .init_array, and lastly the .preinit_array so they behave the exact same way as glibc. We no longer use hex constants to define math.h symbols like M_PI.
2024-02-20 19:12:09 +00:00
third_party/lua/lnotice.c \
third_party/lua/loadlib.c \
third_party/lua/lobject.c \
third_party/lua/lopcodes.c \
third_party/lua/loslib.c \
third_party/lua/lparser.c \
third_party/lua/lrepl.c \
third_party/lua/lstate.c \
third_party/lua/lstring.c \
third_party/lua/lstrlib.c \
third_party/lua/ltable.c \
third_party/lua/ltablib.c \
third_party/lua/ltests.c \
third_party/lua/ltm.c \
third_party/lua/luacallwithtrace.c \
third_party/lua/luaencodejsondata.c \
third_party/lua/luaencodeluadata.c \
third_party/lua/luaencodeurl.c \
third_party/lua/luaformatstack.c \
third_party/lua/luaparseurl.c \
third_party/lua/luaprintstack.c \
third_party/lua/luapushheader.c \
third_party/lua/luapushheaders.c \
third_party/lua/luapushlatin1.c \
third_party/lua/luapushurlparams.c \
third_party/lua/lundump.c \
third_party/lua/lutf8lib.c \
third_party/lua/lvm.c \
third_party/lua/lzio.c \
third_party/lua/serialize.c \
third_party/lua/visitor.c
THIRD_PARTY_LUA_A_OBJS = \
$(THIRD_PARTY_LUA_A_SRCS:%.c=o/$(MODE)/%.o)
THIRD_PARTY_LUA_A_DIRECTDEPS = \
LIBC_CALLS \
LIBC_FMT \
LIBC_INTRIN \
LIBC_MEM \
LIBC_NEXGEN32E \
Make improvements - Every unit test now passes on Apple Silicon. The final piece of this puzzle was porting our POSIX threads cancelation support, since that works differently on ARM64 XNU vs. AMD64. Our semaphore support on Apple Silicon is also superior now compared to AMD64, thanks to the grand central dispatch library which lets *NSYNC locks go faster. - The Cosmopolitan runtime is now more stable, particularly on Windows. To do this, thread local storage is mandatory at all runtime levels, and the innermost packages of the C library is no longer being built using ASAN. TLS is being bootstrapped with a 128-byte TIB during the process startup phase, and then later on the runtime re-allocates it either statically or dynamically to support code using _Thread_local. fork() and execve() now do a better job cooperating with threads. We can now check how much stack memory is left in the process or thread when functions like kprintf() / execve() etc. call alloca(), so that ENOMEM can be raised, reduce a buffer size, or just print a warning. - POSIX signal emulation is now implemented the same way kernels do it with pthread_kill() and raise(). Any thread can interrupt any other thread, regardless of what it's doing. If it's blocked on read/write then the killer thread will cancel its i/o operation so that EINTR can be returned in the mark thread immediately. If it's doing a tight CPU bound operation, then that's also interrupted by the signal delivery. Signal delivery works now by suspending a thread and pushing context data structures onto its stack, and redirecting its execution to a trampoline function, which calls SetThreadContext(GetCurrentThread()) when it's done. - We're now doing a better job managing locks and handles. On NetBSD we now close semaphore file descriptors in forked children. Semaphores on Windows can now be canceled immediately, which means mutexes/condition variables will now go faster. Apple Silicon semaphores can be canceled too. We're now using Apple's pthread_yield() funciton. Apple _nocancel syscalls are now used on XNU when appropriate to ensure pthread_cancel requests aren't lost. The MbedTLS library has been updated to support POSIX thread cancelations. See tool/build/runitd.c for an example of how it can be used for production multi-threaded tls servers. Handles on Windows now leak less often across processes. All i/o operations on Windows are now overlapped, which means file pointers can no longer be inherited across dup() and fork() for the time being. - We now spawn a thread on Windows to deliver SIGCHLD and wakeup wait4() which means, for example, that posix_spawn() now goes 3x faster. POSIX spawn is also now more correct. Like Musl, it's now able to report the failure code of execve() via a pipe although our approach favors using shared memory to do that on systems that have a true vfork() function. - We now spawn a thread to deliver SIGALRM to threads when setitimer() is used. This enables the most precise wakeups the OS makes possible. - The Cosmopolitan runtime now uses less memory. On NetBSD for example, it turned out the kernel would actually commit the PT_GNU_STACK size which caused RSS to be 6mb for every process. Now it's down to ~4kb. On Apple Silicon, we reduce the mandatory upstream thread size to the smallest possible size to reduce the memory overhead of Cosmo threads. The examples directory has a program called greenbean which can spawn a web server on Linux with 10,000 worker threads and have the memory usage of the process be ~77mb. The 1024 byte overhead of POSIX-style thread-local storage is now optional; it won't be allocated until the pthread_setspecific/getspecific functions are called. On Windows, the threads that get spawned which are internal to the libc implementation use reserve rather than commit memory, which shaves a few hundred kb. - sigaltstack() is now supported on Windows, however it's currently not able to be used to handle stack overflows, since crash signals are still generated by WIN32. However the crash handler will still switch to the alt stack, which is helpful in environments with tiny threads. - Test binaries are now smaller. Many of the mandatory dependencies of the test runner have been removed. This ensures many programs can do a better job only linking the the thing they're testing. This caused the test binaries for LIBC_FMT for example, to decrease from 200kb to 50kb - long double is no longer used in the implementation details of libc, except in the APIs that define it. The old code that used long double for time (instead of struct timespec) has now been thoroughly removed. - ShowCrashReports() is now much tinier in MODE=tiny. Instead of doing backtraces itself, it'll just print a command you can run on the shell using our new `cosmoaddr2line` program to view the backtrace. - Crash report signal handling now works in a much better way. Instead of terminating the process, it now relies on SA_RESETHAND so that the default SIG_IGN behavior can terminate the process if necessary. - Our pledge() functionality has now been fully ported to AARCH64 Linux.
2023-09-19 03:44:45 +00:00
LIBC_PROC \
LIBC_RUNTIME \
LIBC_STDIO \
LIBC_STR \
LIBC_SYSV \
LIBC_LOG \
LIBC_TIME \
LIBC_X \
LIBC_TINYMATH \
NET_HTTP \
THIRD_PARTY_LINENOISE \
2022-07-09 18:44:19 +00:00
THIRD_PARTY_DOUBLECONVERSION \
THIRD_PARTY_GDTOA
THIRD_PARTY_LUA_A_DEPS := \
$(call uniq,$(foreach x,$(THIRD_PARTY_LUA_A_DIRECTDEPS),$($(x))))
$(THIRD_PARTY_LUA_A): \
third_party/lua/ \
$(THIRD_PARTY_LUA_A).pkg \
$(THIRD_PARTY_LUA_A_OBJS)
$(THIRD_PARTY_LUA_A).pkg: \
$(THIRD_PARTY_LUA_A_OBJS) \
$(foreach x,$(THIRD_PARTY_LUA_A_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/third_party/lua/lmathlib.o \
o//third_party/lua/lgc.o: private \
CFLAGS += \
-O2
o/$(MODE)/third_party/lua/lvm.o: private \
CFLAGS += \
-fno-gcse
$(THIRD_PARTY_LUA_A_OBJS): private \
CFLAGS += \
-ffunction-sections \
-fdata-sections
################################################################################
# lunix.a
THIRD_PARTY_LUA_UNIX = \
$(THIRD_PARTY_LUA_A_DEPS) \
$(THIRD_PARTY_LUA_A)
THIRD_PARTY_LUA_ARTIFACTS += \
THIRD_PARTY_LUA_UNIX
THIRD_PARTY_LUA_UNIX_A = \
o/$(MODE)/third_party/lua/lunix.a
THIRD_PARTY_LUA_UNIX_HDRS = \
third_party/lua/lunix.h
THIRD_PARTY_LUA_UNIX_SRCS = \
third_party/lua/lunix.c
THIRD_PARTY_LUA_UNIX_OBJS = \
$(THIRD_PARTY_LUA_UNIX_SRCS:%.c=o/$(MODE)/%.o)
THIRD_PARTY_LUA_UNIX_DIRECTDEPS = \
LIBC_CALLS \
LIBC_FMT \
LIBC_INTRIN \
LIBC_LOG \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_NT_KERNEL32 \
Make improvements - Every unit test now passes on Apple Silicon. The final piece of this puzzle was porting our POSIX threads cancelation support, since that works differently on ARM64 XNU vs. AMD64. Our semaphore support on Apple Silicon is also superior now compared to AMD64, thanks to the grand central dispatch library which lets *NSYNC locks go faster. - The Cosmopolitan runtime is now more stable, particularly on Windows. To do this, thread local storage is mandatory at all runtime levels, and the innermost packages of the C library is no longer being built using ASAN. TLS is being bootstrapped with a 128-byte TIB during the process startup phase, and then later on the runtime re-allocates it either statically or dynamically to support code using _Thread_local. fork() and execve() now do a better job cooperating with threads. We can now check how much stack memory is left in the process or thread when functions like kprintf() / execve() etc. call alloca(), so that ENOMEM can be raised, reduce a buffer size, or just print a warning. - POSIX signal emulation is now implemented the same way kernels do it with pthread_kill() and raise(). Any thread can interrupt any other thread, regardless of what it's doing. If it's blocked on read/write then the killer thread will cancel its i/o operation so that EINTR can be returned in the mark thread immediately. If it's doing a tight CPU bound operation, then that's also interrupted by the signal delivery. Signal delivery works now by suspending a thread and pushing context data structures onto its stack, and redirecting its execution to a trampoline function, which calls SetThreadContext(GetCurrentThread()) when it's done. - We're now doing a better job managing locks and handles. On NetBSD we now close semaphore file descriptors in forked children. Semaphores on Windows can now be canceled immediately, which means mutexes/condition variables will now go faster. Apple Silicon semaphores can be canceled too. We're now using Apple's pthread_yield() funciton. Apple _nocancel syscalls are now used on XNU when appropriate to ensure pthread_cancel requests aren't lost. The MbedTLS library has been updated to support POSIX thread cancelations. See tool/build/runitd.c for an example of how it can be used for production multi-threaded tls servers. Handles on Windows now leak less often across processes. All i/o operations on Windows are now overlapped, which means file pointers can no longer be inherited across dup() and fork() for the time being. - We now spawn a thread on Windows to deliver SIGCHLD and wakeup wait4() which means, for example, that posix_spawn() now goes 3x faster. POSIX spawn is also now more correct. Like Musl, it's now able to report the failure code of execve() via a pipe although our approach favors using shared memory to do that on systems that have a true vfork() function. - We now spawn a thread to deliver SIGALRM to threads when setitimer() is used. This enables the most precise wakeups the OS makes possible. - The Cosmopolitan runtime now uses less memory. On NetBSD for example, it turned out the kernel would actually commit the PT_GNU_STACK size which caused RSS to be 6mb for every process. Now it's down to ~4kb. On Apple Silicon, we reduce the mandatory upstream thread size to the smallest possible size to reduce the memory overhead of Cosmo threads. The examples directory has a program called greenbean which can spawn a web server on Linux with 10,000 worker threads and have the memory usage of the process be ~77mb. The 1024 byte overhead of POSIX-style thread-local storage is now optional; it won't be allocated until the pthread_setspecific/getspecific functions are called. On Windows, the threads that get spawned which are internal to the libc implementation use reserve rather than commit memory, which shaves a few hundred kb. - sigaltstack() is now supported on Windows, however it's currently not able to be used to handle stack overflows, since crash signals are still generated by WIN32. However the crash handler will still switch to the alt stack, which is helpful in environments with tiny threads. - Test binaries are now smaller. Many of the mandatory dependencies of the test runner have been removed. This ensures many programs can do a better job only linking the the thing they're testing. This caused the test binaries for LIBC_FMT for example, to decrease from 200kb to 50kb - long double is no longer used in the implementation details of libc, except in the APIs that define it. The old code that used long double for time (instead of struct timespec) has now been thoroughly removed. - ShowCrashReports() is now much tinier in MODE=tiny. Instead of doing backtraces itself, it'll just print a command you can run on the shell using our new `cosmoaddr2line` program to view the backtrace. - Crash report signal handling now works in a much better way. Instead of terminating the process, it now relies on SA_RESETHAND so that the default SIG_IGN behavior can terminate the process if necessary. - Our pledge() functionality has now been fully ported to AARCH64 Linux.
2023-09-19 03:44:45 +00:00
LIBC_PROC \
LIBC_RUNTIME \
LIBC_SOCK \
LIBC_STDIO \
LIBC_STR \
LIBC_SYSV \
LIBC_THREAD \
LIBC_TIME \
LIBC_X \
THIRD_PARTY_LUA \
THIRD_PARTY_NSYNC
THIRD_PARTY_LUA_UNIX_DEPS := \
$(call uniq,$(foreach x,$(THIRD_PARTY_LUA_UNIX_DIRECTDEPS),$($(x))))
$(THIRD_PARTY_LUA_A): \
third_party/lua/ \
$(THIRD_PARTY_LUA_UNIX_A).pkg \
$(THIRD_PARTY_LUA_UNIX_OBJS)
$(THIRD_PARTY_LUA_UNIX_A).pkg: \
$(THIRD_PARTY_LUA_UNIX_OBJS) \
$(foreach x,$(THIRD_PARTY_LUA_UNIX_DIRECTDEPS),$($(x)_A).pkg)
################################################################################
# lua.com
THIRD_PARTY_LUA_LUA_DIRECTDEPS = \
LIBC_CALLS \
LIBC_FMT \
LIBC_INTRIN \
LIBC_NEXGEN32E \
LIBC_STDIO \
LIBC_LOG \
LIBC_STR \
LIBC_SYSV \
LIBC_THREAD \
THIRD_PARTY_LINENOISE \
THIRD_PARTY_LUA \
THIRD_PARTY_LUA_UNIX \
TOOL_ARGS
THIRD_PARTY_LUA_LUA_DEPS := \
$(call uniq,$(foreach x,$(THIRD_PARTY_LUA_LUA_DIRECTDEPS),$($(x))))
o/$(MODE)/third_party/lua/lua.com.pkg: \
o/$(MODE)/third_party/lua/lua.main.o \
$(foreach x,$(THIRD_PARTY_LUA_LUA_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/third_party/lua/lua.com.dbg: \
$(THIRD_PARTY_LUA_LUA_DEPS) \
o/$(MODE)/third_party/lua/lua.com.pkg \
o/$(MODE)/third_party/lua/lua.main.o \
$(CRT) \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/third_party/lua/lua2.com: \
o/$(MODE)/third_party/lua/lua.com.dbg \
o/$(MODE)/third_party/zip/zip.com \
o/$(MODE)/tool/build/symtab.com
@$(MAKE_OBJCOPY)
@$(MAKE_SYMTAB_CREATE)
@$(MAKE_SYMTAB_ZIP)
################################################################################
# luac.com
THIRD_PARTY_LUA_LUAC_DIRECTDEPS = \
LIBC_FMT \
LIBC_INTRIN \
LIBC_NEXGEN32E \
LIBC_RUNTIME \
LIBC_STDIO \
LIBC_STR \
LIBC_SYSV \
THIRD_PARTY_LUA \
TOOL_ARGS
THIRD_PARTY_LUA_LUAC_DEPS := \
$(call uniq,$(foreach x,$(THIRD_PARTY_LUA_LUAC_DIRECTDEPS),$($(x))))
o/$(MODE)/third_party/lua/luac.com.pkg: \
o/$(MODE)/third_party/lua/luac.main.o \
$(foreach x,$(THIRD_PARTY_LUA_LUAC_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/third_party/lua/luac.com.dbg: \
$(THIRD_PARTY_LUA_LUAC_DEPS) \
o/$(MODE)/third_party/lua/luac.com.pkg \
o/$(MODE)/third_party/lua/luac.main.o \
$(CRT) \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
################################################################################
Prove that Makefile is fully defined The whole repository is now buildable with GNU Make Landlock sandboxing. This proves that no Makefile targets exist which touch files other than their declared prerequisites. In order to do this, we had to: 1. Stop code morphing GCC output in package.com and instead run a newly introduced FIXUPOBJ.COM command after GCC invocations. 2. Disable all the crumby Python unit tests that do things like create files in the current directory, or rename() files between folders. This ended up being a lot of tests, but most of them are still ok. 3. Introduce an .UNSANDBOXED variable to GNU Make to disable Landlock. We currently only do this for things like `make tags`. 4. This change deletes some GNU Make code that was preventing the execve() optimization from working. This means it should no longer be necessary in most cases for command invocations to be indirected through the cocmd interpreter. 5. Missing dependencies had to be declared in certain places, in cases where they couldn't be automatically determined by MKDEPS.COM 6. The libcxx header situation has finally been tamed. One of the things that makes this difficult is MKDEPS.COM only wants to consider the first 64kb of a file, in order to go fast. But libcxx likes to have #include lines buried after huge documentation. 7. An .UNVEIL variable has been introduced to GNU Make just in case we ever wish to explicitly specify additional things that need to be whitelisted which aren't strictly prerequisites. This works in a manner similar to the recently introduced .EXTRA_PREREQS feature. There's now a new build/bootstrap/make.com prebuilt binary available. It should no longer be possible to write invalid Makefile code.
2022-08-06 10:51:50 +00:00
THIRD_PARTY_LUA_SRCS = \
$(foreach x,$(THIRD_PARTY_LUA_ARTIFACTS),$($(x)_SRCS)) \
third_party/lua/lua.main.c \
third_party/lua/luac.main.c
THIRD_PARTY_LUA_LIBS = $(foreach x,$(THIRD_PARTY_LUA_ARTIFACTS),$($(x)))
THIRD_PARTY_LUA_HDRS = $(foreach x,$(THIRD_PARTY_LUA_ARTIFACTS),$($(x)_HDRS))
THIRD_PARTY_LUA_INCS = $(foreach x,$(THIRD_PARTY_LUA_ARTIFACTS),$($(x)_INCS))
THIRD_PARTY_LUA_OBJS = $(foreach x,$(THIRD_PARTY_LUA_ARTIFACTS),$($(x)_OBJS))
$(THIRD_PARTY_LUA_OBJS): third_party/lua/BUILD.mk
.PHONY: o/$(MODE)/third_party/lua
o/$(MODE)/third_party/lua: \
$(THIRD_PARTY_LUA_LIBS) \
$(THIRD_PARTY_LUA_BINS) \
$(THIRD_PARTY_LUA_CHECKS)