mirror of
https://github.com/wolfcw/libfaketime.git
synced 2026-05-17 08:36:28 +03:00
Particularly we need -fptrauth-calls, so when pthread_once indirectly calls ftpl_really_init, it won't fail PAC.
111 lines
4.1 KiB
Makefile
111 lines
4.1 KiB
Makefile
#
|
|
# Notes:
|
|
#
|
|
# * Compilation Defines:
|
|
#
|
|
# MACOS_DYLD_INTERPOSE
|
|
# - Use dlyd interposing instead of name-based function interception
|
|
# (required since macOS Monterey)
|
|
#
|
|
# FAKE_SLEEP
|
|
# - Also intercept sleep(), nanosleep(), usleep(), alarm(), [p]poll()
|
|
#
|
|
# FAKE_SETTIME
|
|
# - Intercept clock_settime(), settimeofday(), and adjtime()
|
|
#
|
|
# FAKE_PID
|
|
# - Enable faked values for getpid() calls through FAKETIME_FAKEPID
|
|
#
|
|
# FAKE_RANDOM
|
|
# - Intercept getentropy(). Dangerous for production use.
|
|
# See README about FAKE_RANDOM.
|
|
#
|
|
# FAKE_STAT
|
|
# - Enables time faking also for files' timestamps.
|
|
#
|
|
# FAKE_FILE_TIMESTAMPS, FAKE_UTIME
|
|
# - Enables time faking for the utime* functions. If enabled via
|
|
# FAKE_FILE_TIMESTAMPS, the faking is opt-in at runtime using
|
|
# with the FAKE_UTIME environment variable. If enabled via
|
|
# FAKE_UTIME, the faking is opt-out at runtime. Requires FAKE_STAT.
|
|
#
|
|
# PTHREAD
|
|
# - Define this to enable multithreading support.
|
|
#
|
|
# PTHREAD_SINGLETHREADED_TIME
|
|
# - Define this if you want to single-thread time() ... there ARE
|
|
# possible caching side-effects in a multithreaded environment
|
|
# without this, but the performance impact may require you to
|
|
# try it unsynchronized.
|
|
#
|
|
# * Compilation addition: second libMT target added for building the pthread-
|
|
# enabled library as a separate library
|
|
#
|
|
# * Compilation switch change: previous versions compiled using '-nostartfiles'
|
|
# This is no longer the case since there is a 'startup' constructor for the library
|
|
# which is used to activate the start-at times when specified. This also initializes
|
|
# the dynamic disabling of the FAKE_STAT calls.
|
|
#
|
|
# By default, libfaketime will be compiled for your system's default architecture.
|
|
# To build for a different architecture, add -arch flags to CFLAGS and LDFLAGS.
|
|
#
|
|
# default to clang to support thread local variables
|
|
CC ?= clang
|
|
INSTALL ?= install
|
|
|
|
PREFIX ?= /usr/local
|
|
|
|
CFLAGS += -DFAKE_SLEEP -DFAKE_INTERNAL_CALLS -DPREFIX='"'${PREFIX}'"' $(FAKETIME_COMPILE_CFLAGS) -DMACOS_DYLD_INTERPOSE -DFAKE_SETTIME
|
|
LIB_LDFLAGS += -dynamiclib -current_version 0.9.11 -compatibility_version 0.7
|
|
|
|
# From macOS 13 onwards, system binaries are compiled against the new arm64e ABI on Apple Silicon.
|
|
# These arm64e binaries enforce Pointer Authentication Code (PAC), and will refuse to run with
|
|
# "unprotected" arm64 libraries. Meanwhile, older platforms might not recognize the new arm64e ABI.
|
|
|
|
# Therefore, we now compile for two ABIs at the same time, producing a fat library of arm64e and arm64,
|
|
# so in the end the OS gets to pick which architecture it wants at runtime.
|
|
|
|
# In addition, we need to enable signing and authentication of indirect calls (-fptrauth-calls);
|
|
# otherwise in ftpl_init, pthread_once will indirectly call ftpl_really_init, which then fail PAC.
|
|
# Ideally this should be a compiler default for the arm64e ABI, but apparently not.
|
|
|
|
ARCH := $(shell uname -m)
|
|
|
|
ifeq ($(ARCH),arm64)
|
|
CFLAGS += -arch arm64e -arch arm64
|
|
CFLAGS += -fptrauth-calls -fptrauth-returns
|
|
endif
|
|
|
|
SONAME = 1
|
|
LIBS = libfaketime.${SONAME}.dylib
|
|
BINS = faketime
|
|
|
|
all: ${LIBS} ${BINS}
|
|
|
|
libfaketime.${SONAME}.dylib: libfaketime.c
|
|
${CC} -o $@ ${CFLAGS} ${LDFLAGS} ${LIB_LDFLAGS} -install_name ${PREFIX}/lib/faketime/$@ $<
|
|
|
|
faketime: faketime.c
|
|
${CC} -o $@ ${CFLAGS} ${LDFLAGS} $<
|
|
|
|
clean:
|
|
@rm -f ${OBJ} ${LIBS} ${BINS}
|
|
|
|
distclean: clean
|
|
@echo
|
|
|
|
install: ${LIBS} ${BINS}
|
|
@echo
|
|
@echo "Copying the faketime libraries to ${DESTDIR}${PREFIX}/lib/faketime and the faketime wrapper script to ${DESTDIR}${PREFIX}/bin ..."
|
|
$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/lib/faketime/"
|
|
$(INSTALL) -m0644 ${LIBS} "${DESTDIR}${PREFIX}/lib/faketime/"
|
|
$(INSTALL) -dm0755 "${DESTDIR}${PREFIX}/bin"
|
|
$(INSTALL) -m0755 faketime "${DESTDIR}${PREFIX}/bin/faketime"
|
|
|
|
uninstall:
|
|
for f in ${LIBS}; do rm -f "${DESTDIR}${PREFIX}/lib/faketime/$$f"; done
|
|
rmdir "${DESTDIR}${PREFIX}/lib/faketime"
|
|
rm -f "${DESTDIR}${PREFIX}/bin/faketime"
|
|
|
|
.PHONY: all clean distclean install uninstall
|