1# Copyright 2016 The Fuchsia Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5LOCAL_DIR := $(GET_LOCAL_DIR) 6 7MODULE := $(LOCAL_DIR) 8 9MODULE_TYPE := driver 10# not really a "driver", but a "driver" is a dso that's not 11# exported via sysroot, which is what userboot is too 12 13MODULE_SRCS += \ 14 $(LOCAL_DIR)/bootdata.c \ 15 $(LOCAL_DIR)/bootfs.c \ 16 $(LOCAL_DIR)/userboot-elf.c \ 17 $(LOCAL_DIR)/option.c \ 18 $(LOCAL_DIR)/start.c \ 19 $(LOCAL_DIR)/loader-service.c \ 20 $(LOCAL_DIR)/util.c 21 22MODULE_NAME := userboot 23MODULE_GROUP := core 24 25# This is built as a shared library, but it gets embedded directly in the 26# kernel image and does not need to be installed in the filesystem at all. 27MODULE_SO_NAME := userboot 28MODULE_SO_INSTALL_NAME := - 29 30# Directly compile in the few functions we need from libc. 31# This doesn't get arch-specific optimized versions, but 32# such optimization isn't very important for userboot. 33userboot-string-functions := memcmp memcpy memset strlen strncmp memmove 34MODULE_SRCS += \ 35 $(userboot-string-functions:%=third_party/ulib/musl/src/string/%.c) 36MODULE_COMPILEFLAGS += -Ithird_party/ulib/musl/src/internal 37 38# Make sure there are never any PLT entries generated. 39MODULE_COMPILEFLAGS += -fvisibility=hidden 40 41ifeq ($(call TOBOOL,$(USE_LTO)),true) 42# Make sure that compiler doesn't replace calls to libc functions with builtins. 43# While inlining these builtins is desirable, it causes LTO to optimize away 44# our own versions of these functions which later causes a link failure. 45# TODO(phosek): https://bugs.llvm.org/show_bug.cgi?id=34169 46MODULE_COMPILEFLAGS += -ffreestanding 47endif 48 49# We don't have normal setup, so safe-stack is a non-starter. 50MODULE_COMPILEFLAGS += $(NO_SAFESTACK) $(NO_SANITIZERS) 51 52# system/ulib/runtime is compiled without safe-stack. We can't use any other 53# static libs, because they might be built with safe-stack or other 54# options that can't be supported in the constrained userboot context. 55MODULE_STATIC_LIBS := system/ulib/runtime 56MODULE_HEADER_DEPS := system/ulib/zircon 57 58# Fortunately, each of these libraries is just a single source file. 59# So we just use their sources directly rather than getting 60# clever with the build system somehow. 61 62MODULE_HEADER_DEPS += system/ulib/elfload 63MODULE_SRCS += system/ulib/elfload/elf-load.c 64 65MODULE_HEADER_DEPS += system/ulib/bootdata 66MODULE_SRCS += system/ulib/bootdata/decompress.c 67 68MODULE_HEADER_DEPS += third_party/ulib/lz4 69MODULE_SRCS += third_party/ulib/lz4/lz4.c 70MODULE_COMPILEFLAGS += -Ithird_party/ulib/lz4/include/lz4 -DWITH_LZ4_NOALLOC 71 72MODULE_HEADER_DEPS += system/ulib/ldmsg 73MODULE_SRCS += system/ulib/ldmsg/ldmsg.c 74 75# This generated header lists all the ABI symbols in the vDSO with their 76# addresses. It's used to generate vdso-syms.ld, below. 77$(BUILDDIR)/$(LOCAL_DIR)/vdso-syms.h: $(BUILDDIR)/system/ulib/zircon/libzircon.so 78 @$(MKDIR) 79 $(call BUILDECHO,generating $@) 80 $(NOECHO)$(SHELLEXEC) scripts/shlib-symbols -a '$(NM)' $< > $@ 81GENERATED += $(BUILDDIR)/$(LOCAL_DIR)/vdso-syms.h 82 83# This generated linker script defines symbols for each vDSO entry point 84# giving the relative address where it will be found at runtime. With 85# this hack, the userboot code doesn't need to do any special work to 86# find the vDSO and its entry points, keeping the code far simpler. 87$(BUILDDIR)/$(LOCAL_DIR)/vdso-syms.ld: \ 88 $(LOCAL_DIR)/vdso-syms.ld.h $(BUILDDIR)/$(LOCAL_DIR)/vdso-syms.h 89 @$(MKDIR) 90 $(call BUILDECHO,generating $@) 91 $(NOECHO)$(CC) -E -P -include $^ > $@ 92GENERATED += $(BUILDDIR)/$(LOCAL_DIR)/vdso-syms.ld.h 93MODULE_EXTRA_OBJS := $(BUILDDIR)/$(LOCAL_DIR)/vdso-syms.ld 94 95# userboot is a reentrant DSO (no writable segment) with an entry point. 96MODULE_LDFLAGS := $(RODSO_LDFLAGS) -e _start 97 98include make/module.mk 99