gnu-efi/apps/Makefile

102 lines
3.3 KiB
Makefile
Raw Normal View History

2013-01-31 01:25:25 +04:00
#
# Copyright (C) 1999-2001 Hewlett-Packard Co.
# Contributed by David Mosberger <davidm@hpl.hp.com>
# Contributed by Stephane Eranian <eranian@hpl.hp.com>
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
# * Neither the name of Hewlett-Packard Co. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
SRCDIR = .
VPATH = $(SRCDIR)
TOPDIR = $(SRCDIR)/..
2013-01-31 01:25:25 +04:00
include $(SRCDIR)/../Make.defaults
LINUX_HEADERS = /usr/src/sys/build
APPSDIR = $(LIBDIR)/gnuefi/apps
2013-01-31 01:25:25 +04:00
CPPFLAGS += -D__KERNEL__ -I$(LINUX_HEADERS)/include
CRTOBJS = $(TOPDIR)/$(ARCH)/gnuefi/crt0-efi-$(ARCH).o
2013-01-31 01:25:25 +04:00
LDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_efi.lds
- Removes the ElfW() macro usage from reloc_ia32.c and reloc_x86_64.c. These macros only exist in link.h on Linux. On FreeBSD, the equivalent macro is __ElfN(). But the macro usage is redundant. You're only going to compile the ia32 file for IA32 binaries and the x86_64 file for X64 binaries. If you had just one file built for both cases, then using the macro might make more sense. - Removes the "#define foo_t efi_foo_t" macros from reloc_ia32.c and reloc_x86_64.c. - Modifies inc/x86_64/efibind.h and inc/ia32/efibind.h to use the new definitions for uint64_t, int64_t and int8_t. The 64-bit types are now defined as: typedef int __attribute__((__mode__(__DI__))) int64_t; typedef unsigned int __attribute__((__mode__(__DI__))) uint64_t; This removes the conflict between the host types dragged in by elf.h and the type definitions in efibind.h that made the #define foo_t efi_foo_t" hack necessary. Also, int8_t is now defined as signed char instead of just char (assuming char == signed char is apparently not good enough). - Also modifies these files to use stdint.h instead of stdint-gcc.h. It's unclear if this is completely correct, but stdint-gcc.h is not present with all GCC installs, and if you use -std=c99 or later you will force this case to be hit. This also can break clang, which doesn't have a stdint-gcc.h at all. - Removes the #include of <link.h> from reloc_ia32.c and reloc_x86_64.c (since with the previous changes it's not needed anymore). - Places the #include of <elf.h> after #include <efi>/#include <efilib.h> so that we know the types will always be defined properly, in case you build on a system where <elf.h> doesn't automatically pull in the right header files to define all the needed types. (This actually happens on VxWorks. It's harmless elsewhere. If you don't care about VxWorks, you can leave this out.) - Modifies setjmp_ia32.S and setjmp_x86_64.S so to change "function" to @function. The clang compiler doesn't like the former. Clang and GCC both like the latter. - Modifles Make.defaults so that if ARCH is detected as "amd64," it's changed to "x86_64." It happens that uname -m on 64-bit FreeBSD reports the former rather than the latter, which breaks the build. This may also be the case on some other OSes. There's a way to force uname(1) to return x86_64 as the machine type, but this way is a little friendlier. - Creates gnuefi/elf_ia32_fbsd_efi.lds which specifies the object file type as elf-ia32-freebsd. This is required for building on FreeBSD/i386, not just FreeBSD/amd64. - Modifies apps/Makefile to always use $(TOPDIR)/gnuefi/elf_$(ARCH)_fbsd_efi.lds when building on either 32-bit or 64-bit FreeBSD instead of just for the x86_64 case. - Changed LDFLAGS in Make.defaults to include --no-undefined. This will cause linking to fail if there are any unsatisfied symbols when creating foo.so during any of the app builds, as opposed to just silently succeeding and producing an unusable binary. - Changed CFLAGS to include -ffreestanding -fno-stack-protector -fno-stack- check. This prevents clang from inserting a call to memset() when compiling the RtZeroMem() and RtSetMem() routines in lib/runtime/efirtlib.c and guards against the native compiler in some Linux distros from adding in stack checking code which relies on libc help that isn't present in the EFI runtime environment. This does the following: - Cleans up the ia32 and x86-64 relocation code a bit (tries to break the dependency between the host ELF headers and the EFI runtime environment) - Avoids the dependency on stdint-gcc.h which may not always be available - Allows GNU EFI to build out of the box on both FreeBSD/i386 and FreeBSD/amd64 - Allows GNU EFI to build out of the box with either GCC or clang on FreeBSD/i386 and FreeBSD/amd64 9.0 and later. - Makes things a little easier to port to VxWorks - Avoids creating un-runable binaries with unresolved symbol definitions (which can be very confusing to debug)
2013-05-15 23:26:16 +04:00
ifneq (,$(findstring FreeBSD,$(OS)))
2013-01-31 01:25:25 +04:00
LDSCRIPT = $(TOPDIR)/gnuefi/elf_$(ARCH)_fbsd_efi.lds
endif
LDFLAGS += -shared -Bsymbolic -L$(TOPDIR)/$(ARCH)/lib -L$(TOPDIR)/$(ARCH)/gnuefi $(CRTOBJS)
LOADLIBES += -lefi -lgnuefi
LOADLIBES += $(LIBGCC)
LOADLIBES += -T $(LDSCRIPT)
TARGET_APPS = t.efi t2.efi t3.efi t4.efi t5.efi t6.efi \
printenv.efi t7.efi t8.efi tcc.efi modelist.efi \
route80h.efi drv0_use.efi AllocPages.efi exit.efi \
FreePages.efi setjmp.efi debughook.efi debughook.efi.debug \
Make ELF constructors and destructors work This makes setup and teardown functions defined with __attribute__((__constructor__) and __attribute__((__destructor__)) work in normal circumstances in EFI binaries. A couple of notes: - it implements both the old-style .ctors/.dtors methods and the newer style .init_array/.fini_array ELF constructor and destructor arrays, processed in the order: .init_array[] .ctors[] efi_main() .dtors[] .fini_array[] - Destructors will only be called if efi_main() exits using "return"; any call to Exit() will still longjmp() past them. - InitializeLib() has already been called before constructors run, so they don't need to call it (and neither does anything else.) For compatibility, it has been altered so calling it more than once is safe. - No attempt is made to handle any constructor or destructor with a prototype other than "void func(void);", but note that InitializeLib has been called, so LibImageHandle, ST, BS, and RT are set. - The init_array/ctor/dtor/fini_array lists aren't the using the GNU "CONSTRUCTOR" output section command, so they don't start with a size. - The lists are individually sorted during the link stage via SORT_BY_NAME() in the linker script. - The default (empty) init_array/ctor/dtor/fini_array lists are padded out to 8-byte alignment with ".p2align 3, 0", and each list always has at least one ".long 0" at the end of it (even if it's completely empty). As a result, they can have NULLs that need to be skipped. The sections they're in are mergeable, so the NULLs don't have to be exclusively at the end. - The ia64 and mips64el arches have not been tested. Signed-off-by: Peter Jones <pjones@redhat.com>
2023-03-28 15:28:40 +03:00
bltgrid.efi lfbgrid.efi setdbg.efi unsetdbg.efi \
ctors_test.efi ctors_dtors_priority_test.efi
TARGET_BSDRIVERS = drv0.efi
TARGET_RTDRIVERS =
ifneq ($(HAVE_EFI_OBJCOPY),)
FORMAT := --target efi-app-$(ARCH)
$(TARGET_BSDRIVERS): FORMAT=--target efi-bsdrv-$(ARCH)
$(TARGET_RTDRIVERS): FORMAT=--target efi-rtdrv-$(ARCH)
else
SUBSYSTEM := 0xa
$(TARGET_BSDRIVERS): SUBSYSTEM = 0xb
$(TARGET_RTDRIVERS): SUBSYSTEM = 0xc
FORMAT := -O binary
LDFLAGS += --defsym=EFI_SUBSYSTEM=$(SUBSYSTEM)
endif
TARGETS = $(TARGET_APPS) $(TARGET_BSDRIVERS) $(TARGET_RTDRIVERS)
2013-01-31 01:25:25 +04:00
all: $(TARGETS)
Make ELF constructors and destructors work This makes setup and teardown functions defined with __attribute__((__constructor__) and __attribute__((__destructor__)) work in normal circumstances in EFI binaries. A couple of notes: - it implements both the old-style .ctors/.dtors methods and the newer style .init_array/.fini_array ELF constructor and destructor arrays, processed in the order: .init_array[] .ctors[] efi_main() .dtors[] .fini_array[] - Destructors will only be called if efi_main() exits using "return"; any call to Exit() will still longjmp() past them. - InitializeLib() has already been called before constructors run, so they don't need to call it (and neither does anything else.) For compatibility, it has been altered so calling it more than once is safe. - No attempt is made to handle any constructor or destructor with a prototype other than "void func(void);", but note that InitializeLib has been called, so LibImageHandle, ST, BS, and RT are set. - The init_array/ctor/dtor/fini_array lists aren't the using the GNU "CONSTRUCTOR" output section command, so they don't start with a size. - The lists are individually sorted during the link stage via SORT_BY_NAME() in the linker script. - The default (empty) init_array/ctor/dtor/fini_array lists are padded out to 8-byte alignment with ".p2align 3, 0", and each list always has at least one ".long 0" at the end of it (even if it's completely empty). As a result, they can have NULLs that need to be skipped. The sections they're in are mergeable, so the NULLs don't have to be exclusively at the end. - The ia64 and mips64el arches have not been tested. Signed-off-by: Peter Jones <pjones@redhat.com>
2023-03-28 15:28:40 +03:00
ctors_test.so : ctors_fns.o ctors_test.o
2013-01-31 01:25:25 +04:00
clean:
@rm -vf $(TARGETS) *~ *.o *.so
2013-01-31 01:25:25 +04:00
install:
mkdir -p $(INSTALLROOT)$(APPSDIR)
$(INSTALL) -m 644 $(TARGETS) $(INSTALLROOT)$(APPSDIR)
2013-01-31 01:25:25 +04:00
.PHONY: install
include $(SRCDIR)/../Make.rules