diff --git a/Makefile b/Makefile index 66c89ca..699d9d3 100644 --- a/Makefile +++ b/Makefile @@ -14,8 +14,7 @@ # along with this program; see the file COPYING. If not see # . -MAKE ?= make -DESTDIR ?= /opt/ps5-payload-sdk +include common.mk TOPTARGETS := all clean install SUBDIRS := crt sce_stubs libc libufs include host diff --git a/common.mk b/common.mk new file mode 100644 index 0000000..a4df914 --- /dev/null +++ b/common.mk @@ -0,0 +1,34 @@ +MAKE ?= make +PYTHON ?= python3 + +DESTDIR ?= /opt/ps5-payload-sdk + +LLVM_CONFIG_CANDIDATES := llvm-config-21 \ + llvm-config-20 llvm-config-19 llvm-config-18 \ + llvm-config-17 llvm-config-16 llvm-config-15 \ + llvm-config +LLVM_CONFIG_CANDIDATES := $(foreach LCC,$(LLVM_CONFIG_CANDIDATES), \ + $(if $(shell command -v $(LCC) 2>/dev/null), $(LCC))) + +LLVM_CONFIG ?= $(firstword $(LLVM_CONFIG_CANDIDATES)) +ifndef LLVM_CONFIG + $(error Unable to find llvm-config) +endif + +LLVM_BINDIR := $(shell $(LLVM_CONFIG) --bindir) +CC := $(LLVM_BINDIR)/clang +AR := $(LLVM_BINDIR)/llvm-ar +LD := $(LLVM_BINDIR)/ld.lld + +# ld is moved out of llvm on MacOS +ifeq ($(shell command -v $(LD) 2>/dev/null),) +OS := $(shell uname -s) +ifeq ($(OS),Darwin) +BREW := $(shell command -v brew 2>/dev/null) +ifneq ($(BREW),) +LD := $(shell $(BREW) --prefix lld 2>/dev/null)/bin/ld.lld +else + $(error Unable to find Homebrew) +endif +endif +endif diff --git a/crt/Makefile b/crt/Makefile index 80f72c0..acbdcd1 100644 --- a/crt/Makefile +++ b/crt/Makefile @@ -14,24 +14,7 @@ # along with this program; see the file COPYING. If not see # . -DESTDIR ?= /opt/ps5-payload-sdk - -LLVM_CONFIG_CANDIDATES := llvm-config-21 \ - llvm-config-20 llvm-config-19 llvm-config-18 \ - llvm-config-17 llvm-config-16 llvm-config-15 \ - llvm-config -LLVM_CONFIG_CANDIDATES := $(foreach LCC,$(LLVM_CONFIG_CANDIDATES), \ - $(if $(shell command -v $(LCC) 2>/dev/null), $(LCC))) - -LLVM_CONFIG ?= $(firstword $(LLVM_CONFIG_CANDIDATES)) -ifndef LLVM_CONFIG - $(error Unable to find llvm-config) -endif - -LLVM_BINDIR := $(shell $(LLVM_CONFIG) --bindir) -CC := $(LLVM_BINDIR)/clang -AR := $(LLVM_BINDIR)/llvm-ar -LD := $(LLVM_BINDIR)/ld.lld +include ../common.mk CFLAGS += -ffreestanding -fno-builtin -nostdlib -fPIC CFLAGS += -target x86_64-sie-ps5 -fno-plt -fno-stack-protector diff --git a/host/bin/prospero-lld b/host/bin/prospero-lld index 15dd58e..abf2df7 100755 --- a/host/bin/prospero-lld +++ b/host/bin/prospero-lld @@ -26,21 +26,35 @@ LDSCRIPT="-T${PS5_PAYLOAD_SDK}/ldscripts/elf_x86_64.x" for ARG in "$@"; do if [[ "$ARG" == "--shared" ]]; then - PIE="" + PIE="" fi if [[ "$ARG" == "-r" ]]; then - PIE="" + PIE="" fi if [[ "$ARG" == "--static" ]]; then - PIE="" + PIE="" fi if [[ "$ARG" == "--script" || "$ARG" == "-T" ]]; then - LDSCRIPT="" + LDSCRIPT="" fi done LLVM_BINDIR=$("${SCRIPT_DIR}/prospero-llvm-config" --bindir) BIN_PATH="${LLVM_BINDIR}/ld.lld" + +# ld is moved out of llvm on macOS +if ! command -v "${BIN_PATH}" >/dev/null 2>&1; then + if [ "$(uname -s)" = "Darwin" ]; then + BREW="$(command -v brew 2>/dev/null)" + if [ -n "${BREW}" ]; then + BIN_PATH="$("${BREW}" --prefix lld 2>/dev/null)/bin/ld.lld" + else + echo "Unable to find Homebrew" >&2 + exit 1 + fi + fi +fi + exec "${BIN_PATH}" \ -m elf_x86_64 $PIE $LDSCRIPT --eh-frame-hdr \ -z max-page-size=0x4000 -mllvm -emulated-tls \ diff --git a/libc/Makefile b/libc/Makefile index 97103b3..5120a6d 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -14,23 +14,7 @@ # along with this program; see the file COPYING. If not see # . -DESTDIR ?= /opt/ps5-payload-sdk - -LLVM_CONFIG_CANDIDATES := llvm-config-21 \ - llvm-config-20 llvm-config-19 llvm-config-18 \ - llvm-config-17 llvm-config-16 llvm-config-15 \ - llvm-config -LLVM_CONFIG_CANDIDATES := $(foreach LCC,$(LLVM_CONFIG_CANDIDATES), \ - $(if $(shell command -v $(LCC) 2>/dev/null), $(LCC))) - -LLVM_CONFIG ?= $(firstword $(LLVM_CONFIG_CANDIDATES)) -ifndef LLVM_CONFIG - $(error Unable to find llvm-config) -endif - -LLVM_BINDIR := $(shell $(LLVM_CONFIG) --bindir) -CC := $(LLVM_BINDIR)/clang -AR := $(LLVM_BINDIR)/llvm-ar +include ../common.mk CFLAGS := -target x86_64-sie-ps5 -fPIC -fno-plt -fno-stack-protector CFLAGS += -nobuiltininc -isystem ../include/freebsd diff --git a/libufs/Makefile b/libufs/Makefile index df6df21..b8cddc4 100644 --- a/libufs/Makefile +++ b/libufs/Makefile @@ -14,23 +14,7 @@ # along with this program; see the file COPYING. If not see # . -DESTDIR ?= /opt/ps5-payload-sdk - -LLVM_CONFIG_CANDIDATES := llvm-config-21 \ - llvm-config-20 llvm-config-19 llvm-config-18 \ - llvm-config-17 llvm-config-16 llvm-config-15 \ - llvm-config -LLVM_CONFIG_CANDIDATES := $(foreach LCC,$(LLVM_CONFIG_CANDIDATES), \ - $(if $(shell command -v $(LCC) 2>/dev/null), $(LCC))) - -LLVM_CONFIG ?= $(firstword $(LLVM_CONFIG_CANDIDATES)) -ifndef LLVM_CONFIG - $(error Unable to find llvm-config) -endif - -LLVM_BINDIR := $(shell $(LLVM_CONFIG) --bindir) -CC := $(LLVM_BINDIR)/clang -AR := $(LLVM_BINDIR)/llvm-ar +include ../common.mk CFLAGS := -target x86_64-sie-ps5 -fPIC -fno-plt -fno-stack-protector CFLAGS += -nobuiltininc -isystem ../include/freebsd diff --git a/sce_stubs/Makefile b/sce_stubs/Makefile index 784f055..08fd4e6 100644 --- a/sce_stubs/Makefile +++ b/sce_stubs/Makefile @@ -14,24 +14,7 @@ # along with this program; see the file COPYING. If not see # . -PYTHON ?= python3 -DESTDIR ?= /opt/ps5-payload-sdk - -LLVM_CONFIG_CANDIDATES := llvm-config-21 \ - llvm-config-20 llvm-config-19 llvm-config-18 \ - llvm-config-17 llvm-config-16 llvm-config-15 \ - llvm-config -LLVM_CONFIG_CANDIDATES := $(foreach LCC,$(LLVM_CONFIG_CANDIDATES), \ - $(if $(shell command -v $(LCC) 2>/dev/null), $(LCC))) - -LLVM_CONFIG ?= $(firstword $(LLVM_CONFIG_CANDIDATES)) -ifndef LLVM_CONFIG - $(error Unable to find llvm-config) -endif - -LLVM_BINDIR := $(shell $(LLVM_CONFIG) --bindir) -CC := $(LLVM_BINDIR)/clang -LD := $(LLVM_BINDIR)/ld.lld +include ../common.mk CFLAGS := -ffreestanding -fno-builtin -nostdlib -fPIC CFLAGS += -target x86_64-sie-ps5 -fno-plt -fno-stack-protector