diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef6d518f..bb95b4bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,26 +1,42 @@ -{ - "name": "pull-request", - "on": { - "push": { "branches": "main" }, - "pull_request": { "branches": "main" }, - }, - "jobs": { - "linux": { - "runs-on": "ubuntu-latest", - "strategy": { - "fail-fast": false, - "matrix": { - "container": [ - "f33", "f34", "f35", "f36", "centos8", "centos9", - ], - }, - }, - "container": "vathpela/efi-ci:${{ matrix.container }}-x64", - "steps": [ - { "uses": "actions/checkout@v2" }, - { "run": "make all test" }, - { "run": "make abicheck" }, - ], - }, - }, -} +name: ci_meson + +on: + workflow_dispatch: + push: + paths: + - "**.c" + - "**.h" + - "tests/**" + - "**/meson.build" + - "src/abignore" + - "src/*.abixml" + - "src/*.map" + pull_request: + paths: + - "**.c" + - "**.h" + - "tests/**" + - "**/meson.build" + - "src/abignore" + - "src/*.abixml" + - "src/*.map" + +jobs: + main: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v1 + with: + python-version: '3.x' + - run: sudo apt-get update && sudo apt-get install -y abigail-tools + - run: pip install meson ninja + - run: meson setup -Dtest_abi_compat=enabled -Dgenerate_abi_xml=enabled -Dconvert_mandocs=disabled builddir/ + env: + CC: gcc + - run: meson test -C builddir/ -v + - uses: actions/upload-artifact@v1 + with: + name: Linux_Meson_Testlog + path: builddir/meson-logs/testlog.txt + diff --git a/Makefile b/Makefile deleted file mode 100644 index c896fc38..00000000 --- a/Makefile +++ /dev/null @@ -1,86 +0,0 @@ -export TOPDIR = $(realpath $(dir $(firstword $(MAKEFILE_LIST)))) - -include $(TOPDIR)/src/include/deprecated.mk -include $(TOPDIR)/src/include/version.mk -include $(TOPDIR)/src/include/rules.mk -include $(TOPDIR)/src/include/defaults.mk -include $(TOPDIR)/src/include/coverity.mk -include $(TOPDIR)/src/include/scan-build.mk - -SUBDIRS := src docs - -all : | efivar.spec src/include/version.mk prep -all clean install prep : - @set -e ; for x in $(SUBDIRS) ; do \ - $(MAKE) -C $$x $@ ; \ - done - -abicheck abidw efisecdb efisecdb-static efivar efivar-static static : | all - $(MAKE) -C src $@ - -abiupdate : - $(MAKE) clean all - $(MAKE) -C src abiclean abixml - -$(SUBDIRS) : - $(MAKE) -C $@ all - -brick : all - @echo -n $(info this is the rule for brick PWD:$(PWD) MAKECMDGOALS:$(MAKECMDGOALS)) - @set -e ; for x in $(SUBDIRS) ; do \ - $(MAKE) -C $${x} test ; \ - done - -a : - @if [ $${EUID} != 0 ]; then \ - echo no 1>&2 ; \ - exit 1 ; \ - fi - -GITTAG = $(shell bash -c "echo $$(($(VERSION) + 1))") - -efivar.spec : | Makefile src/include/version.mk - -clean : clean-toplevel -clean-toplevel: - @rm -vf efivar.spec vgcore.* core.* - @$(MAKE) -C tests clean - -test : all - @$(MAKE) -C tests - -test-archive: abicheck efivar.spec - @rm -rf /tmp/efivar-$(GITTAG) /tmp/efivar-$(GITTAG)-tmp - @mkdir -p /tmp/efivar-$(GITTAG)-tmp - @git archive --format=tar $(shell git branch | awk '/^*/ { print $$2 }') | ( cd /tmp/efivar-$(GITTAG)-tmp/ ; tar x ) - @git diff | ( cd /tmp/efivar-$(GITTAG)-tmp/ ; patch -s -p1 -b -z .gitdiff ) - @mv /tmp/efivar-$(GITTAG)-tmp/ /tmp/efivar-$(GITTAG)/ - @cp efivar.spec /tmp/efivar-$(GITTAG)/ - @dir=$$PWD; cd /tmp; tar -c --bzip2 -f $$dir/efivar-$(GITTAG).tar.bz2 efivar-$(GITTAG) - @rm -rf /tmp/efivar-$(GITTAG) - @echo "The archive is in efivar-$(GITTAG).tar.bz2" - -bumpver : - @echo VERSION=$(GITTAG) > src/include/version.mk - @git add src/include/version.mk - git commit -m "Bump version to $(GITTAG)" -s - -tag: - git tag -s $(GITTAG) refs/heads/master - -archive: abicheck bumpver abidw tag efivar.spec - @rm -rf /tmp/efivar-$(GITTAG) /tmp/efivar-$(GITTAG)-tmp - @mkdir -p /tmp/efivar-$(GITTAG)-tmp - @git archive --format=tar $(GITTAG) | ( cd /tmp/efivar-$(GITTAG)-tmp/ ; tar x ) - @mv /tmp/efivar-$(GITTAG)-tmp/ /tmp/efivar-$(GITTAG)/ - @cp efivar.spec /tmp/efivar-$(GITTAG)/ - @dir=$$PWD; cd /tmp; tar -c --bzip2 -f $$dir/efivar-$(GITTAG).tar.bz2 efivar-$(GITTAG) - @rm -rf /tmp/efivar-$(GITTAG) - @echo "The archive is in efivar-$(GITTAG).tar.bz2" - -.PHONY: $(SUBDIRS) -.PHONY: a abiclean abicheck abidw abiupdate all archive -.PHONY: brick bumpver clean clean-toplevel -.PHONY: efivar efivar-static -.PHONY: install prep tag test test-archive -.NOTPARALLEL: diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index c9bf585f..00000000 --- a/docs/Makefile +++ /dev/null @@ -1,58 +0,0 @@ -SRCDIR = $(realpath .) - -include $(TOPDIR)/src/include/deprecated.mk -include $(TOPDIR)/src/include/version.mk -include $(TOPDIR)/src/include/rules.mk -include $(TOPDIR)/src/include/defaults.mk - -MAN1TARGETS = efisecdb.1 \ - efivar.1 - -MAN3TARGETS = efi_append_variable.3 \ - efi_del_variable.3 \ - efi_get_next_variable_name.3 \ - efi_get_variable.3 \ - efi_get_variable_attributes.3 \ - efi_get_variable_size.3 \ - efi_guid_to_id_guid.3 \ - efi_guid_to_name.3 \ - efi_guid_to_str.3 \ - efi_guid_to_symbol.3 \ - efi_name_to_guid.3 \ - efi_set_variable.3 \ - efi_str_to_guid.3 \ - efi_symbol_to_guid.3 \ - efi_variables_supported.3 \ - efi_variable_t.3 \ - efi_variable_import.3 \ - efi_variable_export.3 \ - efi_variable_alloc.3 \ - efi_variable_free.3 \ - efi_variable_set_name.3 \ - efi_variable_get_name.3 \ - efi_variable_set_guid.3 \ - efi_variable_get_guid.3 \ - efi_variable_set_data.3 \ - efi_variable_get_data.3 \ - efi_variable_get_attributes.3 \ - efi_variable_set_attributes.3 \ - efi_variable_realize.3 - -all : $(MAN1TARGETS) $(MAN3TARGETS) - -clean : - @rm -f efisecdb.1 - -prep : - -test : - -install : $(MAN1TARGETS) $(MAN3TARGETS) - $(INSTALL) -d -m 755 $(DESTDIR)$(MANDIR)/man1 - $(foreach x, $(MAN1TARGETS), $(INSTALL) -m 644 $(x) $(DESTDIR)/$(MANDIR)/man1/;) - $(INSTALL) -d -m 755 $(DESTDIR)$(MANDIR)/man3 - $(foreach x, $(MAN3TARGETS), $(INSTALL) -m 644 $(x) $(DESTDIR)/$(MANDIR)/man3/;) - -.PHONY: all clean install - -include $(TOPDIR)/src/include/rules.mk diff --git a/docs/meson.build b/docs/meson.build new file mode 100644 index 00000000..4c623c7c --- /dev/null +++ b/docs/meson.build @@ -0,0 +1,29 @@ +mans = ['efi_append_variable.3', 'efi_del_variable.3', 'efidp_make_generic.3', 'efi_get_next_variable_name.3', 'efi_get_variable.3', 'efi_get_variable_attributes.3', 'efi_get_variable_size.3', 'efi_guid_to_id_guid.3', 'efi_guid_to_name.3', 'efi_guid_to_str.3', 'efi_guid_to_symbol.3', 'efi_id_guid_to_guid.3', 'efi_name_to_guid.3', 'efi_set_variable.3', 'efi_str_to_guid.3', 'efi_symbol_to_guid.3', 'efivar.1', 'efi_variable_alloc.3', 'efi_variable_export.3', 'efi_variable_free.3', 'efi_variable_get_attributes.3', 'efi_variable_get_data.3', 'efi_variable_get_guid.3', 'efi_variable_get_name.3', 'efi_variable_import.3', 'efi_variable_realize.3', 'efi_variable_set_attributes.3', 'efi_variable_set_data.3', 'efi_variable_set_guid.3', 'efi_variable_set_name.3', 'efi_variables_supported.3', 'efi_variable_t.3'] + +mdocs = ['efisecdb.1.mdoc'] + +foreach man : mans + install_man(man) +endforeach + +mandoc = find_program('mandoc', required : get_option('convert_mandocs')) + +foreach mdoc : mdocs + if mandoc.found() + # Unfortunately install_man won't take target or generator output: meson bug #1550 + man = custom_target(mdoc.substring(0, -5), + input : mdoc, + output : mdoc.substring(0, -5), + command : [mandoc, '-mdoc', '-Tman', + '-Ios=Linux', '@INPUT@'], + capture : true, + install : true, + install_dir : join_paths(get_option('mandir'), 'man' + mdoc[-6])) + else + # configure_file is used to remove .mdoc extension + man = configure_file(input : mdoc, + output : mdoc.substring(0, -5), + copy : true) + install_man(man) + endif +endforeach diff --git a/efivar.spec.in b/efivar.spec.in index e1f44ff9..982ee18e 100644 --- a/efivar.spec.in +++ b/efivar.spec.in @@ -1,5 +1,5 @@ Name: efivar -Version: @@VERSION@@ +Version: @version@ Release: 1%{?dist} Summary: Tools to manage UEFI variables License: LGPL-2.1-only @@ -13,7 +13,7 @@ BuildRequires: git BuildRequires: glibc-static BuildRequires: libabigail BuildRequires: mandoc -BuildRequires: make +BuildRequires: meson # please don't fix this to reflect github's incomprehensible url that goes # to a different tarball. Source0: https://github.com/rhboot/efivar/releases/download/%{version}/efivar-%{version}.tar.bz2 @@ -48,15 +48,16 @@ git config --unset user.name %build %define _lto_cflags %{nil} -make LIBDIR=%{_libdir} BINDIR=%{_bindir} CFLAGS="$RPM_OPT_FLAGS" LDFLAGS="$RPM_LD_FLAGS" +%meson -Dconvert_mandocs=enabled -Dtest_abi_compat=enabled +%meson_build %install -%makeinstall +%meson_install install -m 0644 src/abignore %{buildroot}%{_includedir}/efivar/.abignore %check %ifarch x86_64 -make abicheck +%meson_test %endif %ldconfig_scriptlets libs diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..7282a850 --- /dev/null +++ b/meson.build @@ -0,0 +1,15 @@ +project('efivar', 'c', license: 'LGPL-2.1-only', version: '38') + +lib_ver = '1.@0@'.format(meson.project_version()) +add_project_arguments('-DLIBEFIVAR_VERSION=@0@'.format(meson.project_version()), language : 'c') + +configure_file(input : 'efivar.spec.in', output : 'efivar.spec', configuration : {'version' : meson.project_version()}) + +subdir('src') +subdir('docs') + +if meson.can_run_host_binaries() + subdir('tests') +else + warning('Your build machine cannot run target binaries: Disabling tests.\n\tIf you are cross compiling, ensure the exe_wrapper option is set.') +endif diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 00000000..0fe73617 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,4 @@ +option('convert_mandocs', type : 'feature', value : 'auto', description : 'Convert man pages in mdoc format to man format.') +option('generate_abi_xml', type : 'feature', value : 'disabled', description : 'Generate ABI XML files with abidw') +option('test_abi_compat', type : 'feature', value : 'disabled', description : 'Test ABI compatibility with abidiff') +option('test_with_grubenv', type : 'feature', value : 'auto', description : 'Enable testing with grubenv') diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index 0e423c44..00000000 --- a/src/Makefile +++ /dev/null @@ -1,166 +0,0 @@ -SRCDIR = $(realpath .) - -include $(TOPDIR)/src/include/deprecated.mk -include $(TOPDIR)/src/include/version.mk -include $(TOPDIR)/src/include/rules.mk -include $(TOPDIR)/src/include/defaults.mk -include $(TOPDIR)/src/include/workarounds.mk - -LIBTARGETS=libefivar.so libefiboot.so libefisec.so -STATICLIBTARGETS=libefivar.a libefiboot.a libefisec.a -BINTARGETS=efivar efisecdb thread-test -STATICBINTARGETS=efivar-static efisecdb-static -PCTARGETS=efivar.pc efiboot.pc efisec.pc -TARGETS=$(LIBTARGETS) $(BINTARGETS) $(PCTARGETS) -STATICTARGETS=$(STATICLIBTARGETS) $(STATICBINTARGETS) - -LIBEFISEC_SOURCES = sec.c secdb.c esl-iter.c util.c -LIBEFISEC_OBJECTS = $(patsubst %.c,%.o,$(LIBEFISEC_SOURCES)) -LIBEFIBOOT_SOURCES = crc32.c creator.c disk.c gpt.c loadopt.c path-helpers.c \ - linux.c $(sort $(wildcard linux-*.c)) -LIBEFIBOOT_OBJECTS = $(patsubst %.c,%.o,$(LIBEFIBOOT_SOURCES)) -LIBEFIVAR_SOURCES = crc32.c dp.c dp-acpi.c dp-hw.c dp-media.c dp-message.c \ - efivarfs.c error.c export.c guid.c guid-symbols.c \ - lib.c vars.c time.c -LIBEFIVAR_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(LIBEFIVAR_SOURCES))) -EFIVAR_SOURCES = efivar.c guid.c util.c -EFIVAR_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(EFIVAR_SOURCES))) -EFISECDB_SOURCES = efisecdb.c guid-symbols.c secdb-dump.c util.c -EFISECDB_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(EFISECDB_SOURCES))) -GENERATED_SOURCES = include/efivar/efivar-guids.h guid-symbols.c -MAKEGUIDS_SOURCES = makeguids.c util.c -MAKEGUIDS_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(MAKEGUIDS_SOURCES))) -MAKEGUIDS_OUTPUT = $(GENERATED_SOURCES) guids.lds - -ALL_SOURCES=$(LIBEFISEC_SOURCES) $(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES) \ - $(MAKEGUIDS_SOURCES) $(GENERATED_SOURCES) $(EFIVAR_SOURCES) \ - $(sort $(wildcard include/efivar/*.h)) - -ifneq ($(MAKECMDGOALS),clean) -$(call deps-of,$(ALL_SOURCES)) : | deps --include $(call deps-of,$(ALL_SOURCES)) -endif - -all : $(TARGETS) - -static : $(STATICTARGETS) - -$(BINTARGETS) : | $(LIBTARGETS) $(PCTARGETS) -$(STATICTARGETS) : | $(STATICLIBTARGETS) $(PCTARGETS) - -abiclean : - @rm -vf $(patsubst %.so,%.abixml,$@) - -abixml : | $(LIBTARGETS) -abixml : $(patsubst %.so,%.abixml,$(LIBTARGETS)) - -abidw : $(patsubst %.so,%.abixml,$(LIBTARGETS)) - git commit -s --amend $^ - -abicheck : $(patsubst %.so,%.abicheck,$(LIBTARGETS)) - -makeguids : CPPFLAGS=$(HOST_CPPFLAGS) -makeguids : LIBS=dl -makeguids : CC=$(HOSTCC) -makeguids : CCLD=$(HOSTCCLD) -makeguids : CFLAGS=$(HOST_CFLAGS) -makeguids : LDFLAGS=$(HOST_LDFLAGS) -makeguids : CCLDFLAGS=$(HOST_CCLDFLAGS) -makeguids : $(MAKEGUIDS_OBJECTS) - -$(MAKEGUIDS_OUTPUT) : makeguids -$(MAKEGUIDS_OUTPUT) : guids.txt - @set -e ; \ - missing=no ; \ - for x in $$(cat guids.txt | awk '{ print $$2 }' | grep -v ^zz) ; do \ - if ! grep -q "efi_guid_$${x}" libefivar.map.in ; then \ - echo missing symbol "efi_guid_$${x}" ; \ - missing=yes ; \ - fi ; \ - done ; \ - if [ "$${missing}" != "no" ]; then \ - exit 1 ; \ - fi - ./makeguids $(LD_DASH_T) guids.txt guid-symbols.c include/efivar/efivar-guids.h guids.lds - -prep : makeguids $(GENERATED_SOURCES) - -$(LIBEFIVAR_OBJECTS) $(LIBEFIBOOT_OBJECTS) : prep - -libefivar.a : | $(GENERATED_SOURCES) -libefivar.a : $(patsubst %.o,%.static.o,$(LIBEFIVAR_OBJECTS)) - -libefivar.so : $(LIBEFIVAR_OBJECTS) -libefivar.so : | $(GENERATED_SOURCES) libefivar.map -libefivar.so : LIBS=dl -libefivar.so : LDSCRIPTS=guids.lds -libefivar.so : MAP=libefivar.map - -efivar : $(EFIVAR_OBJECTS) | libefivar.so -efivar : LIBS=efivar dl - -efivar-static : $(EFIVAR_OBJECTS) $(patsubst %.o,%.static.o,$(LIBEFIVAR_OBJECTS)) -efivar-static : | $(GENERATED_SOURCES) -efivar-static : LIBS=dl - -libefiboot.a : $(patsubst %.o,%.static.o,$(LIBEFIBOOT_OBJECTS)) - -libefiboot.so : $(LIBEFIBOOT_OBJECTS) -libefiboot.so : | libefiboot.map libefivar.so -libefiboot.so : LIBS=efivar -libefiboot.so : MAP=libefiboot.map - -libefisec.a : $(patsubst %.o,%.static.o,$(LIBEFISEC_OBJECTS)) - -libefisec.so : $(LIBEFISEC_OBJECTS) -libefisec.so : | libefisec.map -libefisec.so : MAP=libefisec.map - -efisecdb : $(EFISECDB_OBJECTS) | libefisec.so -efisecdb : LIBS=efivar efisec dl - -efisecdb-static : $(EFISECDB_OBJECTS) -efisecdb-static : $(patsubst %.o,%.static.o,$(LIBEFISEC_OBJECTS) $(LIBEFIVAR_OBJECTS)) -efisecdb-static : | $(GENERATED_SOURCES) -efisecdb-static : LIBS=dl - -thread-test : libefivar.so -thread-test : CFLAGS=$(HOST_CFLAGS) -I$(TOPDIR)/src/include/efivar -thread-test : LIBS=pthread efivar - -deps : $(ALL_SOURCES) - @$(MAKE) -f $(SRCDIR)/include/deps.mk deps SOURCES="$(ALL_SOURCES)" - -clean : - @rm -rfv *~ *.o *.a *.E *.so *.so.* *.pc *.bin .*.d *.map \ - makeguids guid-symbols.c include/efivar/efivar-guids.h \ - guids.lds \ - $(TARGETS) $(STATICTARGETS) - @# remove the deps files we used to create, as well. - @rm -rfv .*.P .*.h.P *.S.P include/efivar/.*.h.P - -install : all - $(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR) - $(foreach x,$(LIBTARGETS), \ - $(INSTALL) -m 755 $(x) $(DESTDIR)$(LIBDIR)/$(x).1.$(VERSION) ;\ - ln -fs $(x).1.$(VERSION) $(DESTDIR)$(LIBDIR)/$(x).1 ;\ - ln -fs $(x).1.$(VERSION) $(DESTDIR)$(LIBDIR)/$(x) ;\ - ) - $(INSTALL) -d -m 755 $(DESTDIR)$(PCDIR) - $(foreach x, $(PCTARGETS), $(INSTALL) -m 644 $(x) $(DESTDIR)$(PCDIR) ;) - $(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/efivar - $(foreach x, $(sort $(wildcard $(TOPDIR)/src/include/efivar/*.h)), $(INSTALL) -m 644 $(x) $(DESTDIR)$(INCLUDEDIR)/efivar/$(notdir $(x));) - $(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR) - $(foreach x, $(filter-out %-test,$(BINTARGETS)), $(INSTALL) -m 755 $(x) $(DESTDIR)$(BINDIR);) - -test : all - $(MAKE) -C test $@ - -.PHONY: abiclean abicheck abidw abixml all -.PHONY: clean deps install test -.SECONDARY : libefivar.so.1.$(VERSION) libefivar.so.1 -.SECONDARY : libefiboot.so.1.$(VERSION) libefiboot.so.1 -.SECONDARY : libefisec.so.1.$(VERSION) libefisec.so.1 -.SECONDARY : $(GENERATED_SOURCES) -.INTERMEDIATE : guids.bin names.bin -.PRECIOUS : makeguids diff --git a/src/abignore b/src/abignore index 527d141a..14b7f136 100644 --- a/src/abignore +++ b/src/abignore @@ -51,3 +51,9 @@ change_kind = added-variable soname_regexp = libefi(var|boot|sec)\\.so\\..* symbol_name_regexp = ^(efidp_|efi_)[[:alnum:]_]+ + +# suppress efi_well_known_*_end variables +[suppress_variable] + change_kind = deleted-variable + soname_regexp = libefivar\\.so\\..* + symbol_name_regexp = ^efi_well_known_[[:alnum:]_]+_end$ diff --git a/src/compiler.h b/src/compiler.h index d95fb014..f00e514b 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -53,15 +53,6 @@ #define PRINTF(...) __attribute__((__format__(printf, __VA_ARGS__))) #define FLATTEN __attribute__((__flatten__)) #define PACKED __attribute__((__packed__)) -#if defined(__clang__) -# define VERSION(sym, ver) -#else -# if GNUC_PREREQ(10,0) -# define VERSION(sym, ver) __attribute__ ((symver (# ver))) -# else -# define VERSION(sym, ver) __asm__(".symver " # sym "," # ver); -# endif -#endif #define NORETURN __attribute__((__noreturn__)) #define ALIGNED(n) __attribute__((__aligned__(n))) #define CLEANUP_FUNC(x) __attribute__((__cleanup__(x))) diff --git a/src/efiboot.pc.in b/src/efiboot.pc.in deleted file mode 100644 index 94cace49..00000000 --- a/src/efiboot.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@@PREFIX@@ -exec_prefix=@@EXEC_PREFIX@@ -libdir=@@LIBDIR@@ -includedir=@@INCLUDEDIR@@ - -Name: efiboot -Description: UEFI Boot variable support -Version: @@VERSION@@ -Requires.private: efivar -Libs: -L${libdir} -lefiboot -Cflags: -I${includedir}/efivar diff --git a/src/efisec.pc.in b/src/efisec.pc.in deleted file mode 100644 index d3d75aac..00000000 --- a/src/efisec.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@@PREFIX@@ -exec_prefix=@@EXEC_PREFIX@@ -libdir=@@LIBDIR@@ -includedir=@@INCLUDEDIR@@ - -Name: efisec -Description: UEFI Security Features -Version: @@VERSION@@ -Libs: -L${libdir} -lefivar -lefisec -Libs.private: -ldl -Cflags: -I${includedir}/efivar diff --git a/src/efivar.c b/src/efivar.c index 09f85edd..7f50c1fa 100644 --- a/src/efivar.c +++ b/src/efivar.c @@ -24,7 +24,7 @@ extern char *optarg; extern int optind, opterr, optopt; #include "efivar.h" -#include "efivar/efivar-guids.h" +#include "efivar-guids.h" #define ACTION_USAGE 0x00 #define ACTION_LIST 0x01 diff --git a/src/efivar.pc.in b/src/efivar.pc.in deleted file mode 100644 index a7f9a39a..00000000 --- a/src/efivar.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@@PREFIX@@ -exec_prefix=@@EXEC_PREFIX@@ -libdir=@@LIBDIR@@ -includedir=@@INCLUDEDIR@@ - -Name: efivar -Description: UEFI Variable Management -Version: @@VERSION@@ -Libs: -L${libdir} -lefivar -Libs.private: -ldl -Cflags: -I${includedir}/efivar diff --git a/src/include/coverity.mk b/src/include/coverity.mk deleted file mode 100644 index 2e7024b9..00000000 --- a/src/include/coverity.mk +++ /dev/null @@ -1,43 +0,0 @@ -COV_EMAIL=$(call get-config,coverity.email) -COV_TOKEN=$(call get-config,coverity.token) -COV_URL=$(call get-config,coverity.url) -COV_FILE=$(NAME)-coverity-$(VERSION)-$(COMMIT_ID).tar.bz2 - -cov-int : clean - cov-build --dir cov-int make all - -cov-clean : - @rm -vf $(NAME)-coverity-*.tar.* - @if [[ -d cov-int ]]; then rm -rf cov-int && echo "removed 'cov-int'"; fi - -cov-file : | $(COV_FILE) - -$(COV_FILE) : cov-int - tar caf $@ cov-int - -cov-upload : - @if [[ -n "$(COV_URL)" ]] && \ - [[ -n "$(COV_TOKEN)" ]] && \ - [[ -n "$(COV_EMAIL)" ]] ; \ - then \ - echo curl --form token=$(COV_TOKEN) --form email="$(COV_EMAIL)" --form file=@"$(COV_FILE)" --form version=$(VERSION).1 --form description="$(COMMIT_ID)" "$(COV_URL)" ; \ - curl --form token=$(COV_TOKEN) --form email="$(COV_EMAIL)" --form file=@"$(COV_FILE)" --form version=$(VERSION).1 --form description="$(COMMIT_ID)" "$(COV_URL)" ; \ - else \ - echo Coverity output is in $(COV_FILE) ; \ - fi - -coverity : | cov-test -coverity : cov-file cov-upload - -clean : | cov-clean - -COV_BUILD ?= $(shell x=$$(which --skip-alias --skip-functions cov-build 2>/dev/null) ; [ -n "$$x" ] && echo 1) -ifeq ($(COV_BUILD),) - COV_BUILD_ERROR = $(error cov-build not found) -endif - -cov-test : ; $(COV_BUILD_ERROR) - -.PHONY : coverity cov-upload cov-clean cov-file cov-test - -# vim:ft=make diff --git a/src/include/defaults.mk b/src/include/defaults.mk deleted file mode 100644 index b8cc590c..00000000 --- a/src/include/defaults.mk +++ /dev/null @@ -1,126 +0,0 @@ -PREFIX ?= /usr -EXEC_PREFIX ?= $(PREFIX) -LIBDIR ?= $(PREFIX)/lib64 -DATADIR ?= $(PREFIX)/share -MANDIR ?= $(DATADIR)/man -INCLUDEDIR ?= $(PREFIX)/include -BINDIR ?= $(EXEC_PREFIX)/bin -PCDIR ?= $(LIBDIR)/pkgconfig -DESTDIR ?= -PKGS ?= - -CROSS_COMPILE ?= -COMPILER ?= gcc -ifeq ($(origin CC),command line) -override COMPILER := $(CC) -override CC := $(CROSS_COMPILE)$(COMPILER) -endif -$(call set-if-undefined,CC,$(CROSS_COMPILE)$(COMPILER)) -$(call set-if-undefined,CCLD,$(CC)) -$(call set-if-undefined,HOSTCC,$(COMPILER)) -$(call set-if-undefined,HOSTCCLD,$(HOSTCC)) - -# temporary, see https://sourceware.org/bugzilla/show_bug.cgi?id=28264 -#OPTIMIZE_GCC = -flto -OPTIMIZE_GCC = -OPTIMIZE ?= -Og $(call family,OPTIMIZE) -DEBUGINFO ?= -g3 -WARNINGS_GCC ?= -WARNINGS_CCC_ANALYZER ?= $(WARNINGS_GCC) -WARNINGS ?= -Wall -Wextra $(call family,WARNINGS) -ERRORS_GCC ?= -ERRORS ?= -Werror $(call family,ERRORS) -CPPFLAGS ?= -override _CPPFLAGS := $(CPPFLAGS) -override CPPFLAGS = $(_CPPFLAGS) -DLIBEFIVAR_VERSION=$(VERSION) \ - -D_GNU_SOURCE \ - -I$(TOPDIR)/src/include/ -CFLAGS ?= $(OPTIMIZE) $(DEBUGINFO) $(WARNINGS) $(ERRORS) -CFLAGS_GCC ?= -specs=$(TOPDIR)/src/include/gcc.specs \ - -fno-merge-constants -override _CFLAGS := $(CFLAGS) -override CFLAGS = $(_CFLAGS) \ - -std=gnu11 \ - -funsigned-char \ - -fvisibility=hidden \ - $(call family,CFLAGS) \ - $(call pkg-config-cflags) -LDFLAGS_CLANG ?= -rtlib=compiler-rt -CCLDFLAGS ?= -LDFLAGS ?= -override _CCLDFLAGS := $(CCLDFLAGS) -override _LDFLAGS := $(LDFLAGS) -override LDFLAGS = $(CFLAGS) -L. $(_LDFLAGS) $(_CCLDFLAGS) \ - -Wl,--add-needed \ - -Wl,--build-id \ - -Wl,--no-allow-shlib-undefined \ - -Wl,--no-undefined-version \ - -Wl,-z,now \ - -Wl,-z,muldefs \ - -Wl,-z,relro \ - -Wl,--fatal-warnings \ - $(call family,LDFLAGS) $(call family,CCLDFLAGS) \ - $(call pkg-config-ccldflags) -override CCLDFLAGS = $(LDFLAGS) -SOFLAGS_GCC = -SOFLAGS_CLANG = -SOFLAGS ?= -override _SOFLAGS := $(SOFLAGS) -override SOFLAGS = $(_SOFLAGS) \ - -shared -Wl,-soname,$@.1 \ - -Wl,--version-script=$(MAP) \ - $(call family,SOFLAGS) - -HOST_ARCH=$(shell uname -m) -ifneq ($(HOST_ARCH),ia64) -ifneq ($(HOST_ARCH),riscv64) - HOST_MARCH=-march=native -else - HOST_MARCH= -endif -else - HOST_MARCH= -endif -HOST_CPPFLAGS ?= $(CPPFLAGS) -override _HOST_CPPFLAGS := $(HOST_CPPFLAGS) -override HOST_CPPFLAGS = $(_HOST_CPPFLAGS) \ - -DEFIVAR_BUILD_ENVIRONMENT $(HOST_MARCH) -HOST_CFLAGS_GCC ?= -HOST_CFLAGS_CLANG ?= -HOST_CFLAGS ?= $(CFLAGS) $(call family,HOST_CFLAGS) -override _HOST_CFLAGS := $(HOST_CFLAGS) -override HOST_CFLAGS = $(_HOST_CFLAGS) -HOST_LDFLAGS_CLANG ?= -Wl,--fatal-warnings,-z,relro -rtlib=compiler-rt -HOST_LDFLAGS_GCC ?= -Wl,--no-undefined-version -HOST_LDFLAGS ?= -HOST_CCLDFLAGS ?= -override _HOST_LDFLAGS := $(HOST_LDFLAGS) -override _HOST_CCLDFLAGS := $(HOST_CCLDFLAGS) -override HOST_LDFLAGS = $(HOST_CFLAGS) -L. \ - $(_HOST_LDFLAGS) $(_HOST_CCLDFLAGS) \ - -Wl,--add-needed \ - -Wl,--build-id \ - -Wl,--no-allow-shlib-undefined \ - -Wl,-z,now \ - -Wl,-z,muldefs \ - $(call family,HOST_LDFLAGS) \ - $(call family,HOST_CCLDFLAGS) \ - $(call pkg-config-ccldflags) -override HOST_CCLDFLAGS = $(HOST_LDFLAGS) - -PKG_CONFIG = $(shell if [ -e "$$(env $(CROSS_COMPILE)pkg-config 2>&1)" ]; then echo $(CROSS_COMPILE)pkg-config ; else echo pkg-config ; fi) -INSTALL ?= install -AR := $(CROSS_COMPILE)$(COMPILER)-ar -NM := $(CROSS_COMPILE)$(COMPILER)-nm -RANLIB := $(CROSS_COMPILE)$(COMPILER)-ranlib -ABIDW := abidw -ABIDIFF := abidiff -MANDOC := mandoc - -LDLIBS=$(foreach lib,$(LIBS),-l$(lib)) $(call pkg-config-ldlibs) - -COMMIT_ID=$(shell git log -1 --pretty=%H 2>/dev/null || echo master) - -NAME=efivar - -# vim:ft=make diff --git a/src/include/deprecated.mk b/src/include/deprecated.mk deleted file mode 100644 index 00abc8c8..00000000 --- a/src/include/deprecated.mk +++ /dev/null @@ -1,52 +0,0 @@ -# -# This is all stuff pjones should not have done the way he did initially, and -# it's deprecated and will eventually go away. -# - -ifneq ($(origin prefix),undefined) - ifeq ($(origin PREFIX),undefined) - override PREFIX = $(prefix) - endif -endif -ifneq ($(origin exec_prefix),undefined) - ifeq ($(origin EXEC_PREFIX),undefined) - override EXEC_PREFIX = $(exec_prefix) - endif -endif -ifneq ($(origin libdir),undefined) - ifeq ($(origin LIBDIR),undefined) - override LIBDIR = $(libdir) - endif -endif -ifneq ($(origin datadir),undefined) - ifeq ($(origin DATADIR),undefined) - override DATADIR = $(datadir) - endif -endif -ifneq ($(origin mandir),undefined) - ifeq ($(origin MANDIR),undefined) - override MANDIR = $(mandir) - endif -endif -ifneq ($(origin includedir),undefined) - ifeq ($(origin INCLUDEDIR),undefined) - override INCLUDEDIR = $(includedir) - endif -endif -ifneq ($(origin bindir),undefined) - ifeq ($(origin BINDIR),undefined) - override BINDIR = $(bindir) - endif -endif -ifneq ($(origin CC_FOR_BUILD),undefined) - ifeq ($(origin HOSTCC),file) - override HOSTCC = $(CC_FOR_BUILD) - endif -endif -ifneq ($(origin CCLD_FOR_BUILD),undefined) - ifeq ($(origin HOSTCCLD),file) - override HOSTCCLD = $(CCLD_FOR_BUILD) - endif -endif - -# vim:ft=make diff --git a/src/include/deps.mk b/src/include/deps.mk deleted file mode 100644 index b33a926f..00000000 --- a/src/include/deps.mk +++ /dev/null @@ -1,21 +0,0 @@ -SRCDIR = $(realpath .) - -all : deps - -include $(TOPDIR)/src/include/version.mk -include $(TOPDIR)/src/include/rules.mk -include $(TOPDIR)/src/include/defaults.mk - -.%.d : %.c - @$(CC) $(CFLAGS) $(CPPFLAGS) -MM -MG -MF $@ $^ - @sed -i 's/:/: |/g' $@ - -.%.d : %.S - @$(CC) $(CFLAGS) $(CPPFLAGS) -MM -MG -MF $@ $^ - @sed -i 's/:/: |/g' $@ - -SOURCES ?= - -deps : $(call deps-of,$(filter-out %.h,$(SOURCES))) - -.PHONY: deps diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h index 91a83234..386392ce 100644 --- a/src/include/efivar/efivar.h +++ b/src/include/efivar/efivar.h @@ -21,7 +21,7 @@ #include #ifndef EFIVAR_BUILD_ENVIRONMENT -#include +#include #endif #ifdef __cplusplus diff --git a/src/include/gcc.specs b/src/include/gcc.specs deleted file mode 100644 index ef28e2bb..00000000 --- a/src/include/gcc.specs +++ /dev/null @@ -1,8 +0,0 @@ -*cc1_options: -+ %{!r:%{!fpie:%{!fPIE:%{!fpic:%{!fPIC:%{!fno-pic:-fPIE}}}}}} -grecord-gcc-switches - -*self_spec: -+ %{!shared:%{!static:%{!r:-pie}}} %{static:-Wl,-no-fatal-warnings -Wl,-static -static -Wl,-z,relro,-z,now} -grecord-gcc-switches - -*link: -+ %{!static:--fatal-warnings} --no-undefined-version --no-allow-shlib-undefined --add-needed -z now --build-id %{!static:%{!shared:-pie}} %{shared:-z relro} %{static:% $@ - -%.3 : %.3.mdoc - $(MANDOC) -mdoc -Tman -Ios=Linux $^ > $@ - -% : %.c - -% : %.o - $(CCLD) $(CCLDFLAGS) $(CPPFLAGS) -o $@ $(sort $^) $(LDLIBS) - -%-static : CCLDFLAGS+=-static -%-static : %.o - $(CCLD) $(CCLDFLAGS) $(CPPFLAGS) -o $@ $(sort $^) $(LDLIBS) - -%.so : - $(CCLD) $(CCLDFLAGS) $(CPPFLAGS) $(SOFLAGS) \ - $(foreach LDS,$(LDSCRIPTS),$(LD_DASH_T) $(LDS)) \ - -o $@ $^ $(LDLIBS) - ln -vfs $@ $@.1 - -%.abixml : %.so - $(ABIDW) --headers-dir $(TOPDIR)/src/include/efivar/ --out-file $@ $^ - @sed -i -s 's,$(TOPDIR)/,,g' $@ - -%.abicheck : %.so - $(ABIDIFF) \ - --suppr abignore \ - --headers-dir2 $(TOPDIR)/src/include/efivar/ \ - $(patsubst %.so,%.abixml,$<) \ - $< - -%.o : %.c - $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^) - -%.static.o : %.c - $(CC) $(CFLAGS) -fPIE $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^) - -%.o : %.S - $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^) - -%.static.o : %.S - $(CC) $(CFLAGS) -fPIE $(CPPFLAGS) -c -o $@ $(filter %.c %.o %.S,$^) - -%.S: %.c - $(CC) $(CFLAGS) $(CPPFLAGS) -S $< -o $@ - -%.E: %.c - $(CC) $(CFLAGS) $(CPPFLAGS) -E $< -o $@ - -%.c : %.h - -define substitute-version - sed \ - -e "s,@@VERSION@@,$(VERSION),g" \ - -e "s,@@LIBDIR@@,$(LIBDIR),g" \ - -e "s,@@PREFIX@@,$(PREFIX),g" \ - -e "s,@@EXEC_PREFIX@@,$(EXEC_PREFIX),g" \ - -e "s,@@INCLUDEDIR@@,$(INCLUDEDIR),g" \ - $(1) > $(2) -endef - -%.pc : %.pc.in - @$(call substitute-version,$<,$@) -%.spec : %.spec.in - @$(call substitute-version,$<,$@) -%.map : %.map.in - @$(call substitute-version,$<,$@) - -pkg-config-cflags = $(if $(PKGS),$(shell $(PKG_CONFIG) --cflags $(PKGS))) -pkg-config-ccldflags = $(if $(PKGS),$(shell $(PKG_CONFIG) --libs-only-L --libs-only-other $(PKGS))) -pkg-config-ldlibs = $(if $(PKGS),$(shell $(PKG_CONFIG) --libs-only-l $(PKGS))) - -deps-of = $(foreach src,$(filter %.c,$(1)),$(patsubst %.c,.%.d,$(src))) \ - $(foreach src,$(filter %.S,$(1)),$(patsubst %.S,.%.d,$(src))) - -get-config = $(shell git config --local --get "efivar.$(1)") - -# vim:ft=make diff --git a/src/include/scan-build.mk b/src/include/scan-build.mk deleted file mode 100644 index 19da90cd..00000000 --- a/src/include/scan-build.mk +++ /dev/null @@ -1,21 +0,0 @@ -SCAN_BUILD ?= $(shell x=$$(which --skip-alias --skip-functions scan-build 2>/dev/null) ; [ -n "$$x" ] && echo 1) -ifeq ($(SCAN_BUILD),) - SCAN_BUILD_ERROR = $(error scan-build not found) -endif - -scan-test : ; $(SCAN_BUILD_ERROR) - -scan-clean : clean - @if [[ -d scan-results ]]; then rm -rf scan-results && echo "removed 'scan-results'"; fi - -scan-build : | scan-test -scan-build : clean - $(MAKE) -C src makeguids - scan-build -o scan-results make $(DASHJ) CC=clang all - -scan-build-all: | scan-build -scan : | scan-build - -.PHONY : scan-build scan-clean scan-build-all scan - -# vim:ft=make diff --git a/src/include/version.mk b/src/include/version.mk deleted file mode 100644 index eeaf6c59..00000000 --- a/src/include/version.mk +++ /dev/null @@ -1 +0,0 @@ -VERSION=38 diff --git a/src/include/workarounds.mk b/src/include/workarounds.mk deleted file mode 100644 index 143e7902..00000000 --- a/src/include/workarounds.mk +++ /dev/null @@ -1,24 +0,0 @@ -# SPDX-License-Identifier: SPDX-License-Identifier: LGPL-2.1-or-later -# -# workarounds.mk - workarounds for weird stuff behavior - -LD_FLAVOR := $(shell $(LD) --version | grep -E '^(LLD|GNU ld)'|sed 's/ .*//g') -LD_VERSION := $(shell $(LD) --version | grep -E '^(LLD|GNU ld)'|sed 's/.* //') -# 2.35 is definitely broken and 2.36 seems to work -LD_DASH_T := $(shell \ - if [ "x${LD_FLAVOR}" = xLLD ] ; then \ - echo '-T' ; \ - elif [ "x${LD_FLAVOR}" = xGNU ] ; then \ - if echo "${LD_VERSION}" | grep -q -E '^2\.3[6789]|^2\.[456789]|^[3456789]|^[[:digit:]][[:digit:]]' ; then \ - echo '-T' ; \ - else \ - echo "" ; \ - fi ; \ - else \ - echo "Your linker is not supported" ; \ - exit 1 ; \ - fi) - -export LD_DASH_T - -# vim:ft=make diff --git a/src/lib.c b/src/lib.c index 1592cdf9..8f6dcb5d 100644 --- a/src/lib.c +++ b/src/lib.c @@ -28,7 +28,6 @@ struct efi_var_operations default_ops = { struct efi_var_operations *ops = NULL; -VERSION(_efi_set_variable, _efi_set_variable@libefivar.so.0) int NONNULL(2, 3) PUBLIC _efi_set_variable(efi_guid_t guid, const char *name, uint8_t *data, size_t data_size, uint32_t attributes) @@ -45,7 +44,6 @@ _efi_set_variable(efi_guid_t guid, const char *name, uint8_t *data, return rc; } -VERSION(_efi_set_variable_variadic, efi_set_variable@libefivar.so.0) int NONNULL(2, 3) PUBLIC _efi_set_variable_variadic(efi_guid_t guid, const char *name, uint8_t *data, size_t data_size, uint32_t attributes, ...) @@ -62,7 +60,6 @@ _efi_set_variable_variadic(efi_guid_t guid, const char *name, uint8_t *data, return rc; } -VERSION(_efi_set_variable_mode,efi_set_variable@@LIBEFIVAR_0.24) int NONNULL(2, 3) PUBLIC _efi_set_variable_mode(efi_guid_t guid, const char *name, uint8_t *data, size_t data_size, uint32_t attributes, mode_t mode) diff --git a/src/libefiboot.map.in b/src/libefiboot.map similarity index 100% rename from src/libefiboot.map.in rename to src/libefiboot.map diff --git a/src/libefisec.map.in b/src/libefisec.map similarity index 100% rename from src/libefisec.map.in rename to src/libefisec.map diff --git a/src/libefivar.map.in b/src/libefivar.map similarity index 100% rename from src/libefivar.map.in rename to src/libefivar.map diff --git a/src/makeguids.c b/src/makeguids.c index 376bffba..9cea21bc 100644 --- a/src/makeguids.c +++ b/src/makeguids.c @@ -77,7 +77,7 @@ static void make_aliases(FILE *symout, FILE *header, static void write_guidnames(FILE *out, const char *listname, - struct efivar_guidname *guidnames, size_t n, const char *symver) + struct efivar_guidname *guidnames, size_t n) { size_t i; @@ -107,6 +107,12 @@ write_guidnames(FILE *out, const char *listname, gn->symbol, gn->name, gn->description); } fprintf(out, "};\n"); + fprintf(out, + "extern const struct efivar_guidname\n" + "\t%s[%zd]\n" + "\t__attribute__((__visibility__(\"default\")))\n" + "\t__attribute__((alias(\"%s_\")));\n\n", + listname, n, listname); } int @@ -114,15 +120,11 @@ main(int argc, char *argv[]) { int rc; int argstart = 0; - FILE *symout, *header, *ldsout; - int dash_t = 0; + FILE *symout, *header; - if (argc < 5) { + if (argc < 4) { errx(1, "Not enough arguments.\n"); - } else if (argc > 5 && !strcmp(argv[1],"-T")) { - argstart = 1; - dash_t = 1; - } else if (argc > 5) { + } else if (argc > 4) { errx(1, "Too many arguments.\n"); } @@ -140,13 +142,6 @@ main(int argc, char *argv[]) if (rc < 0) warn("chmod(%s, 0644)", argv[argstart + 3]); - ldsout = fopen(argv[argstart + 4], "w"); - if (ldsout == NULL) - err(1, "could not open \"%s\"", argv[argstart + 4]); - rc = chmod(argv[argstart + 4], 0644); - if (rc < 0) - warn("chmod(%s, 0644)", argv[argstart + 4]); - struct guidname_index *guidnames = NULL; rc = read_guids_at(AT_FDCWD, argv[argstart + 1], &guidnames); @@ -245,6 +240,11 @@ struct efivar_guidname {\n\ "\t__attribute__((__visibility__ (\"default\")))\n" "\tefi_well_known_guids[%d];\n", i); + fprintf(header, + "extern const struct efivar_guidname\n" + "\t__attribute__((__visibility__ (\"default\")))\n" + "\tefi_well_known_guids_[%d];\n", + i); fprintf(header, "extern const struct efivar_guidname\n" "\t__attribute__((__visibility__ (\"default\")))\n" @@ -258,6 +258,11 @@ struct efivar_guidname {\n\ "\t__attribute__((__visibility__ (\"default\")))\n" "\tefi_well_known_names[%d];\n", i); + fprintf(header, + "extern const struct efivar_guidname\n" + "\t__attribute__((__visibility__ (\"default\")))\n" + "\tefi_well_known_names_[%d];\n", + i); fprintf(header, "extern const struct efivar_guidname\n" "\t__attribute__((__visibility__ (\"default\")))\n" @@ -303,30 +308,13 @@ struct efivar_guidname {\n\ "} __attribute__((__aligned__(16)));\n\n"); qsort(outbuf, line, sizeof(struct efivar_guidname), cmpguidp); - write_guidnames(symout, "efi_well_known_guids", outbuf, line, "libefivar.so.0"); + write_guidnames(symout, "efi_well_known_guids", outbuf, line); qsort(outbuf, line, sizeof(struct efivar_guidname), cmpnamep); - write_guidnames(symout, "efi_well_known_names", outbuf, line, "LIBEFIVAR_1.38"); + write_guidnames(symout, "efi_well_known_names", outbuf, line); fclose(symout); - fprintf(ldsout, - "SECTIONS\n" - "{\n" - " .data :\n" - " {\n" - " efi_well_known_guids = efi_well_known_guids_;\n" - " efi_well_known_guids_end = efi_well_known_guids_ + %zd;\n" - " efi_well_known_names = efi_well_known_names_;\n" - " efi_well_known_names_end = efi_well_known_names_ + %zd;\n" - " }\n" - "}%s;\n", - (line - 1) * sizeof(struct efivar_guidname), - (line - 1) * sizeof(struct efivar_guidname), - dash_t ? " INSERT AFTER .data" : ""); - - fclose(ldsout); - free(guidnames->strtab); free(guidnames); diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 00000000..aaaf6b85 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,99 @@ +incdir = include_directories('include') + + +makeguids_sources = ['makeguids.c', 'util.c'] +makeguids = executable('makeguids', makeguids_sources, c_args : ['-DEFIVAR_BUILD_ENVIRONMENT'], native : true, include_directories : incdir) + +headers = files('include/efivar/efiboot-creator.h', 'include/efivar/efiboot.h', 'include/efivar/efiboot-loadopt.h', 'include/efivar/efisec.h', 'include/efivar/efisec-secdb.h', 'include/efivar/efisec-types.h', 'include/efivar/efivar-dp.h', 'include/efivar/efivar.h', 'include/efivar/efivar-time.h', 'include/efivar/efivar-types.h') + +gen_guids = custom_target('gen-guids', + input : ['guids.txt'], + output : ['guid-symbols.c', 'efivar-guids.h'], + command : [makeguids, '@INPUT@', '@OUTPUT0@', '@OUTPUT1@'], + install : true, + install_dir : [false, join_paths(get_option('includedir'), 'efivar')]) + + +install_headers(headers, subdir : 'efivar') + + +abidw = find_program('abidw', disabler : true, required : get_option('generate_abi_xml')) +abidw_command = [abidw, '--headers-dir', join_paths(meson.source_root(), 'src/include/efivar/'), + '--suppr', files('abignore'), + '--out-file', '@OUTPUT@', '@INPUT@'] + + +c = meson.get_compiler('c') + +has_ver_script = c.has_link_argument('-Wl,--version-script=' + join_paths(meson.source_root(), 'src/libefivar.map')) + +abidiff = find_program('abidiff', disabler : true, required : get_option('test_abi_compat')) +abidiff_wrapper = find_program('../tests/abidiff_wrapper.py', required : get_option('test_abi_compat')) +abidiff_wrapper_args = [abidiff.full_path(), '--suppr', files('abignore'), '--headers-dir2', join_paths(meson.source_root(), 'src/include/efivar/')] + +if abidiff.found() + if has_ver_script + else + warning('The test_abi_compat option was enabled but the linker doesn\'t support --version-script! Skipping...') + abidiff = disabler() + endif +endif + + +if has_ver_script + link_arg = '-Wl,--version-script=' + join_paths(meson.source_root(), 'src/lib@0@.map') +else + link_arg = '' +endif + +if meson.version().version_compare('>=0.62.0') + dl = dependency('dl') +else + dl = c.find_library('dl', required : false) +endif + + +lib_targets = {} +xml_targets = [] +lib_sources = { + 'efivar' : ['crc32.c', 'dp.c', 'dp-acpi.c', 'dp-hw.c', 'dp-media.c', 'dp-message.c', 'efivarfs.c', 'error.c', 'export.c', 'guid.c', 'lib.c', 'vars.c', 'time.c'], + 'efiboot' : ['crc32.c', 'creator.c', 'disk.c', 'gpt.c', 'loadopt.c', 'path-helpers.c', 'linux.c', 'linux-acpi.c', 'linux-acpi-root.c', 'linux-ata.c', 'linux-emmc.c', 'linux-i2o.c', 'linux-md.c', 'linux-nvme.c', 'linux-pci.c', 'linux-pci-root.c', 'linux-pmem.c', 'linux-sas.c', 'linux-sata.c', 'linux-scsi.c', 'linux-soc-root.c', 'linux-virtblk.c', 'linux-virtual-root.c'], + 'efisec' : ['sec.c', 'secdb.c', 'esl-iter.c', 'util.c'] +} +lib_deps = { + 'efivar' : dl +} + + + +foreach libname : ['efivar', 'efiboot', 'efisec'] + lib = library(libname, lib_sources[libname], gen_guids, version : lib_ver, + link_with : lib_targets.get('efivar', []), install : true, + link_args : link_arg.format(libname), include_directories : incdir, + dependencies : lib_deps.get(libname, [])) + lib_xml = custom_target(libname + '_xml', input : [lib], output: ['lib' + libname + '.abixml'], + command : abidw_command) + test(libname + '_abi', abidiff_wrapper, args : abidiff_wrapper_args + [files('lib' + libname + '.abixml'), lib]) + lib_targets += {libname : lib} + xml_targets += lib_xml +endforeach + + + +alias_target('abixml', xml_targets) + + +efivar_sources = ['efivar.c', 'guid.c', 'util.c'] +efivar = executable('efivar', efivar_sources, gen_guids, install : true, link_with : [lib_targets['efivar']], include_directories : incdir, dependencies : dl) + +efisecdb_sources = ['efisecdb.c', 'secdb-dump.c', 'util.c'] +efisecdb = executable('efisecdb', efisecdb_sources, gen_guids, install : true, link_with : [lib_targets['efivar'], lib_targets['efisec']], include_directories : incdir) + +thread_test_sources = ['thread-test.c'] +thread_test = executable('thread-test', thread_test_sources, gen_guids[1], link_with : lib_targets['efivar'], include_directories : incdir) + +pkg = import('pkgconfig') + +pkg.generate(lib_targets['efivar'], description : 'UEFI Variable Management', subdirs : ['efivar']) +pkg.generate(lib_targets['efiboot'], description : 'UEFI Boot variable support', subdirs : ['efivar']) +pkg.generate(lib_targets['efisec'], description : 'UEFI Security Features', subdirs : ['efivar']) diff --git a/src/test/Makefile b/src/test/Makefile deleted file mode 100644 index 7a2aa496..00000000 --- a/src/test/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -SRCDIR = $(realpath .) - -include $(TOPDIR)/src/include/defaults.mk -include $(TOPDIR)/src/include/version.mk - -CCLDFLAGS += -L$(TOPDIR)/src/ -Wl,-rpath=$(TOPDIR)/src/ -LIBS=efivar - -all : tester - -install : - -clean : - @rm -rfv tester *.o *.E *.S - -test : tester - ./tester - -tester :: tester.o - $(CC) $(cflags) $(LDFLAGS) -Wl,-rpath,$(TOPDIR)/src -L$(TOPDIR)/src -o $@ $^ -lefivar -ldl - -.PHONY: all clean install test - -include $(TOPDIR)/src/include/rules.mk diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index 4b1e62a5..00000000 --- a/tests/Makefile +++ /dev/null @@ -1,287 +0,0 @@ -# -# Makefile -# Peter Jones, 2019-06-18 11:10 -# - -TESTS = test.dmpstore.export \ - test.efivar.export \ - test.grubenv.var \ - test.bootorder.var \ - test.conin.var \ - test.efivar.threading \ - test.parse.db \ - test.esl.annotation \ - test.esl.sha256.unsorted \ - test.esl.sha256.ascending \ - test.esl.sha256.removal.descending \ - test.esl.sha256.addition.unsorted \ - test.esl.cert.addition \ - test.esl.cert.removal - -all: clean $(TESTS) - -GRUB_PREFIX ?= grub2 -VALGRIND ?= - -V ?= 0 -ifeq ($(V),0) - quiet=@ - rmverbose= -else - quiet= - rmverbose=-v -endif -ifeq ($(V),2) - loud=-vvvv -else - loud= -endif - -EFIVAR ?= $(VALGRIND) $(TOPDIR)/src/efivar $(loud) -EFISECDB ?= $(VALGRIND) $(TOPDIR)/src/efisecdb $(loud) - -EFIVAR ?= $(VALGRIND) $(TOPDIR)/src/efivar $(loud) - -clean: - $(quiet)rm $(rmverbose) -f test.*.result* \ - test.esl.annotation.esl.result \ - test.esl.cert.addition.esl.goal.txt \ - test.esl.cert.removal.esl.goal.txt \ - test.esl.sha256.addition.unsorted.esl.goal.txt \ - test.esl.sha256.ascending.esl.goal.txt \ - test.esl.sha256.removal.descending.esl.goal.txt \ - test.esl.sha256.unsorted.esl.goal.txt - -test.dmpstore.export: - $(quiet)echo testing export to DMPSTORE format - $(quiet)$(GRUB_PREFIX)-editenv test.dmpstore.export.result.env create - $(quiet)$(GRUB_PREFIX)-editenv test.dmpstore.export.result.env set debug=all,-scripting,-lexer - $(quiet)truncate -s 512 test.dmpstore.export.result.env - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n {grub}-GRUB_ENV -f test.dmpstore.export.result.env -D -e test.dmpstore.export.result.var - $(quiet)@if grep -q "Do not edit" test.dmpstore.export.result.env ; then \ - cmp test.dmpstore.export.result.var test.dmpstore.export.new.goal.var ; \ - else \ - cmp test.dmpstore.export.result.var test.dmpstore.export.old.goal.var ; \ - fi - $(quiet)rm -f test.dmpstore.export.result.* - $(quiet)echo passed - -test.efivar.export: - $(quiet)echo testing export to libefivar format - $(quiet)$(GRUB_PREFIX)-editenv test.efivar.export.result.env create - $(quiet)$(GRUB_PREFIX)-editenv test.efivar.export.result.env set debug=all,-scripting,-lexer - $(quiet)truncate -s 512 test.efivar.export.result.env - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n {grub}-GRUB_ENV -f test.efivar.export.result.env -e test.efivar.export.result.var - $(quiet)if grep -q "Do not edit" test.efivar.export.result.env ; then \ - cmp test.efivar.export.result.var test.efivar.export.new.goal.var ; \ - else \ - cmp test.efivar.export.result.var test.efivar.export.old.goal.var ; \ - fi - $(quiet)rm -f test.efivar.export.result.* - $(quiet)echo passed - -test.grubenv.var: - $(quiet)$(GRUB_PREFIX)-editenv test.grubenv.var.result.env create - $(quiet)$(GRUB_PREFIX)-editenv test.grubenv.var.result.env set debug=all,-scripting,-lexer - $(quiet)truncate -s 512 test.grubenv.var.result.env - $(quiet)echo test importing from DMPSTORE and exporting to DMPSTORE and symbolic guid-name validation - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n {grub}-GRUB_ENV -f test.grubenv.var.result.env -D -e test.grubenv.var.0.export.var - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.grubenv.var.0.export.var -e test.grubenv.var.0.result.var -D - $(quiet)if grep -q "Do not edit" test.grubenv.var.result.env ; then \ - cmp test.grubenv.var.0.result.var test.grubenv.var.0.new.goal.var ; \ - else \ - cmp test.grubenv.var.0.result.var test.grubenv.var.0.old.goal.var ; \ - fi - $(quiet)rm test.grubenv.var.0.result.* - $(quiet)echo passed - $(quiet)echo test importing from DMPSTORE and exporting to libefivar - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n {grub}-GRUB_ENV -f test.grubenv.var.result.env -D -e test.grubenv.var.1.export.var - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.grubenv.var.1.export.var -e test.grubenv.var.1.result.var - $(quiet)if grep -q "Do not edit" test.grubenv.var.result.env ; then \ - cmp test.grubenv.var.1.result.var test.grubenv.var.1.new.goal.var ; \ - else \ - cmp test.grubenv.var.1.result.var test.grubenv.var.1.old.goal.var ; \ - fi - $(quiet)rm test.grubenv.var.1.result.* - $(quiet)echo passed - $(quiet)echo test importing from libefivar and exporting to DMPSTORE and mixed-case guid-name validation - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n 91376aff-cBa6-42bE-949d-06fde81128e8-GRUB_ENV -f test.grubenv.var.result.env -e test.grubenv.var.2.export.var - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.grubenv.var.2.export.var -e test.grubenv.var.2.result.var -D - $(quiet)if grep -q "Do not edit" test.grubenv.var.result.env ; then \ - cmp test.grubenv.var.2.result.var test.grubenv.var.2.new.goal.var ; \ - else \ - cmp test.grubenv.var.2.result.var test.grubenv.var.2.old.goal.var ; \ - fi - $(quiet)rm test.grubenv.var.2.result.* - $(quiet)echo passed - $(quiet)echo test importing from libefivar and exporting to libefivar and guid-name validation - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -n 91376aff-cba6-42be-949d-06fde81128e8-GRUB_ENV -f test.grubenv.var.result.env -e test.grubenv.var.3.export.var - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.grubenv.var.3.export.var -e test.grubenv.var.3.result.var - $(quiet)if grep -q "Do not edit" test.grubenv.var.result.env ; then \ - cmp test.grubenv.var.3.result.var test.grubenv.var.3.new.goal.var ; \ - else \ - cmp test.grubenv.var.3.result.var test.grubenv.var.3.old.goal.var ; \ - fi - $(quiet)rm -f test.grubenv.var.3.result.* test.grubenv.var.result.env test.grubenv.var.3.goal.var - $(quiet)echo passed - $(quiet)echo testing efivar -L - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -L | \ - grep -q '^{91376aff-cba6-42be-949d-06fde81128e8} {grub} efi_guid_grub GRUB$$' - $(quiet)echo passed - -test.bootorder.var: - $(quiet)echo testing with BootOrder variable dmpstore generated - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.bootorder.var.goal.var -e test.bootorder.var.0.result.var - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.bootorder.var.0.result.var -e test.bootorder.var.1.result.var -D - $(quiet)cmp test.bootorder.var.goal.var test.bootorder.var.1.result.var - $(quiet)echo passed - -test.conin.var: - $(quiet)echo testing with ConIn variable dmpstore generated - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.conin.var.goal.var -e test.conin.var.0.result.var - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFIVAR) -i test.conin.var.0.result.var -e test.conin.var.1.result.var -D - $(quiet)cmp test.conin.var.goal.var test.conin.var.1.result.var - $(quiet)echo passed - -test.efivar.threading: - $(quiet)echo testing threading in libefivar - $(quiet)TOPDIR=$(TOPDIR) $(TOPDIR)/tests/test-threading - -test.esl.dump.x509.sha256: - $(quiet)echo testing ESL dumping with x509 + sha256 sums - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFISECDB) \ - -i test.esl.sha256.addition.unsorted.esl.goal -A > test.esl.dump.x509.sha256.result.txt - $(quiet)cmp test.esl.dump.x509.sha256.goal.txt test.esl.sha256.addition.unsorted.result.txt - $(quiet)echo passed - -%.goal.txt : %.goal - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src ../src/efisecdb --dump --annotate \ - -s none -i $< > $@ - -%.result.txt : %.result - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src ../src/efisecdb --dump --annotate \ - -s none -i $< > $@ - -%.var.result.txt : %.var - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src ../src/efisecdb --dump --annotate \ - -s none -i $< > $@ - -test.parse.db: test.parse.db.var.result.txt - $(quiet)echo testing parsing db variable - $(quiet)if ! cmp test.parse.db.var.goal.txt test.parse.db.var.result.txt ; then \ - diff -U 200 test.parse.db.var.goal.txt test.parse.db.var.result.txt ; \ - exit 1 ; \ - fi - $(quiet)echo passed - -test.esl.annotation.esl.result : test.esl.annotation.esl - $(quiet)cp $(rmverbose) $< $@ - -test.esl.annotation: test.esl.annotation.esl.goal.txt -test.esl.annotation: test.esl.annotation.esl.result.txt - $(quiet)echo testing ESL annotation with x509 + sha256 sums - $(quiet)if ! cmp $@.esl.goal.txt $@.esl.result.txt ; then \ - diff -U 200 $@.esl.goal.txt $@.esl.result.txt ; \ - exit 1 ; \ - fi - $(quiet)echo passed - -test.esl.sha256.unsorted.esl.result: - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFISECDB) -g {redhat} -t sha256 -a \ - -h 87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7 \ - -h 0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f \ - -h a3a5e715f0cc574a73c3f9bebb6bc24f32ffd5b67b387244c2c909da779a1478 \ - -h 8d74beec1be996322ad76813bafb92d40839895d6dd7ee808b17ca201eac98be \ - -s none -f -o $@ - -test.esl.sha256.unsorted: test.esl.sha256.unsorted.esl.result.txt test.esl.sha256.unsorted.esl.goal.txt - $(quiet)echo testing ESL creation with sha256 sums '(unsorted)' - $(quiet)if ! cmp $@.esl.goal $@.esl.result ; then \ - diff -U 200 $@.esl.goal.txt $@.esl.result.txt ; \ - exit 1 ; \ - fi - $(quiet)echo passed - -test.esl.sha256.ascending.esl.result: - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFISECDB) -g {redhat} -t sha256 -a \ - -h 87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7 \ - -h 0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f \ - -h a3a5e715f0cc574a73c3f9bebb6bc24f32ffd5b67b387244c2c909da779a1478 \ - -h 8d74beec1be996322ad76813bafb92d40839895d6dd7ee808b17ca201eac98be \ - -s data -s ascending -f -o $@ - -test.esl.sha256.ascending: test.esl.sha256.ascending.esl.goal.txt test.esl.sha256.ascending.esl.result.txt - $(quiet)echo testing ESL creation with sha256 sums '(ascending)' - $(quiet)if ! cmp $@.esl.goal $@.esl.result ; then \ - diff -U 200 $@.esl.goal.txt $@.esl.result.txt ; \ - exit 1 ; \ - fi - $(quiet)echo passed - -test.esl.sha256.removal.descending.esl.result: - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFISECDB) -g {redhat} -t sha256 \ - -i test.esl.sha256.unsorted.esl.goal -r \ - -h a3a5e715f0cc574a73c3f9bebb6bc24f32ffd5b67b387244c2c909da779a1478 \ - -s data -s descending -f -o $@ - -test.esl.sha256.removal.descending: test.esl.sha256.removal.descending.esl.result.txt -test.esl.sha256.removal.descending: test.esl.sha256.removal.descending.esl.goal.txt - $(quiet)echo testing ESL entry removal with sha256 sums '(descending)' - $(quiet)if ! cmp $@.esl.goal $@.esl.result ; then \ - diff -U 200 $@.esl.goal.txt $@.esl.result.txt ; \ - exit 1 ; \ - fi - $(quiet)echo passed - -test.esl.sha256.addition.unsorted.esl.result: - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFISECDB) -g {redhat} -t sha256 \ - -i test.esl.sha256.addition.unsorted.esl.goal -a \ - -h a3a5e715f0cc574a73c3f9bebb6bc24f32ffd5b67b387244c2c909da779a1478 \ - -s none -f -o test.esl.sha256.addition.unsorted.esl.result - -test.esl.sha256.addition.unsorted: test.esl.sha256.addition.unsorted.esl.result.txt -test.esl.sha256.addition.unsorted: test.esl.sha256.addition.unsorted.esl.goal.txt - $(quiet)echo testing adding a sha256 sum to an existing ESL '(unsorted)' - $(quiet)if ! cmp $@.esl.goal $@.esl.result ; then \ - diff -U 200 $@.esl.goal.txt $@.esl.result.txt ; \ - exit 1 ; \ - fi - $(quiet)echo passed - -test.esl.cert.addition.esl.result: - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFISECDB) -g {redhat} -t sha256 \ - -i test.esl.sha256.unsorted.esl.goal -a -c test.esl.cert.addition.cert.cer \ - -f -o test.esl.cert.addition.esl.result - -test.esl.cert.addition: - $(quiet)echo testing ESL entry addition with x509 cert - $(quiet)$(MAKE) test.esl.cert.addition.esl.result.txt test.esl.cert.addition.esl.goal.txt - $(quiet)if ! cmp test.esl.cert.addition.esl.goal test.esl.cert.addition.esl.result ; then \ - diff -U 200 test.esl.cert.addition.esl.goal.txt test.esl.cert.addition.esl.result.txt ; \ - exit 1 ; \ - fi - $(quiet)rm -f test.esl.cert.addition.esl.result test.esl.cert.addition.*.esl.txt - $(quiet)echo passed - -test.esl.cert.removal.esl.goal.txt : test.esl.cert.removal.esl.goal - -test.esl.cert.removal.esl.result: - $(quiet)LD_LIBRARY_PATH=$(TOPDIR)/src $(EFISECDB) -g {redhat} -t sha256 \ - -i test.esl.cert.addition.cert.esl.goal -r -c test.esl.cert.addition.cert.cer \ - -f -o test.esl.cert.removal.esl.result - -test.esl.cert.removal: - $(quiet)echo testing ESL entry removal with x509 cert - $(quiet)$(MAKE) test.esl.cert.removal.esl.goal.txt test.esl.cert.removal.esl.result.txt - $(quiet)if ! cmp test.esl.cert.removal.esl.goal test.esl.cert.removal.esl.result ; then \ - diff -U 200 test.esl.cert.removal.esl.goal.txt test.esl.cert.removal.esl.result.txt ; \ - exit 1 ; \ - fi - $(quiet)cmp test.esl.cert.removal.esl.goal test.esl.cert.removal.esl.result - $(quiet)rm -f test.esl.cert.removal.esl.result - $(quiet)echo passed - -.PHONY: all clean $(TESTS) - -# vim:ft=make -# diff --git a/tests/abidiff_wrapper.py b/tests/abidiff_wrapper.py new file mode 100755 index 00000000..53273fba --- /dev/null +++ b/tests/abidiff_wrapper.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +import subprocess +import sys + +ABIDIFF_ERROR = 1 +ABIDIFF_USAGE_ERROR = 2 +ABIDIFF_ABI_CHANGE = 4 +ABIDIFF_ABI_INCOMPATIBLE_CHANGE = 8 + + +pr = subprocess.run(sys.argv[1:]) +ret = pr.returncode + +# An error code of 4 means there is a change but it is not a necessarily a breaking change. +if ret == ABIDIFF_ABI_CHANGE: + sys.stderr.write("WARNING! abidiff reports there is an abi change but isn't sure if it is breaking.\nPlease check this manually!\n") + exit(77) +else: + exit(ret) diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 00000000..9d5176f7 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,162 @@ +grubenv_tests = { + 'test.dmpstore.export' : ['testing export to DMPSTORE format', + '@0@ -n {grub}-GRUB_ENV -f test.dmpstore.export.result.env -D -e test.dmpstore.export.result.var'], + 'test.efivar.export' : ['testing export to libefivar format', + '@0@ -n {grub}-GRUB_ENV -f test.efivar.export.result.env -e test.efivar.export.result.var'], + 'test.grubenv.var.0' : ['test importing from DMPSTORE and exporting to DMPSTORE and symbolic guid-name validation', + ''' + @0@ -n {grub}-GRUB_ENV -f test.grubenv.var.0.result.env -D -e test.grubenv.var.0.export.var + @0@ -i test.grubenv.var.0.export.var -e test.grubenv.var.0.result.var -D + '''], + 'test.grubenv.var.1' : ['test importing from DMPSTORE and exporting to libefivar', + ''' + @0@ -n {grub}-GRUB_ENV -f test.grubenv.var.1.result.env -D -e test.grubenv.var.1.export.var + @0@ -i test.grubenv.var.1.export.var -e test.grubenv.var.1.result.var + '''], + 'test.grubenv.var.2' : ['test importing from libefivar and exporting to DMPSTORE and mixed-case guid-name validation', + ''' + @0@ -n 91376aff-cBa6-42bE-949d-06fde81128e8-GRUB_ENV -f test.grubenv.var.2.result.env -e test.grubenv.var.2.export.var + @0@ -i test.grubenv.var.2.export.var -e test.grubenv.var.2.result.var -D + '''], + 'test.grubenv.var.3' : ['test importing from libefivar and exporting to libefivar and guid-name validation', + ''' + @0@ -n 91376aff-cba6-42be-949d-06fde81128e8-GRUB_ENV -f test.grubenv.var.3.result.env -e test.grubenv.var.3.export.var + @0@ -i test.grubenv.var.3.export.var -e test.grubenv.var.3.result.var + '''], +} + +grub_wrapper = find_program('sh/_grubenv-test.sh') +grub_editenv = find_program('grub-editenv', disabler : true, required : get_option('test_with_grubenv')) +foreach grubtest, testinfo : grubenv_tests + # TODO full_path should not be needed for either, report upstream + # "You should not need to use this method. Passing the object itself should work in all cases." + # and "In most cases using the object itself will do the same job as this and will also allow Meson to setup inter-target dependencies correctly. Please file a bug if that doesn't work for you." + test(testinfo[0], grub_wrapper, args : [grub_editenv.full_path(), meson.current_source_dir(), grubtest, testinfo[1].format(efivar.full_path())]) +endforeach + + +efivar_tests = { + 'test.efivar.l' : 'testing efivar -L', + 'test.bootorder.var' : 'testing with BootOrder variable dmpstore generated', + 'test.conin.var' : 'testing with ConIn variable dmpstore generated', +} + +foreach efivartest, testname : efivar_tests + testprog = find_program('sh/' + efivartest + '.sh') + test(testname, testprog, args: [efivar, meson.current_source_dir()]) +endforeach + + +# build_by_default is ignored for now, see meson #2518 and #6511 +efisecdb_tests = { + 'test.parse.db.var' : [ + 'testing parsing db variable', + custom_target( + 'test.parse.db.var_result', output : 'test.parse.db.var.result.txt', input : 'test.parse.db.var', + build_by_default : false, + command : [efisecdb, '--dump', '--annotate', '-s', 'none', '-i', '@INPUT@'], capture : true) + ], + + 'test.esl.annotation.esl' : [ + 'testing ESL annotation with x509 + sha256 sums', + custom_target( + 'test.esl.annotation.esl.var_result', output : 'test.esl.annotation.esl.result.txt', input : 'test.esl.annotation.esl', + build_by_default : false, + command : [efisecdb, '--dump', '--annotate', '-s', 'none', '-i', '@INPUT@'], capture : true) + ], + + 'test.esl.sha256.unsorted.esl' : [ + 'testing ESL creation with sha256 sums (unsorted)', + custom_target( + 'test.esl.sha256.unsorted.esl_result', output : 'test.esl.sha256.unsorted.esl.result', + build_by_default : false, + command : [ + efisecdb, '-g', '{redhat}', '-t', 'sha256', '-a', + '-h', '87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7', + '-h', '0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f', + '-h', 'a3a5e715f0cc574a73c3f9bebb6bc24f32ffd5b67b387244c2c909da779a1478', + '-h', '8d74beec1be996322ad76813bafb92d40839895d6dd7ee808b17ca201eac98be', + '-s', 'none', '-f', '-o', '@OUTPUT@' + ] + ) + ], + + 'test.esl.sha256.ascending.esl' : [ + 'testing ESL creation with sha256 sums (ascending)', + custom_target( + 'test.esl.sha256.ascending.esl_result', output : 'test.esl.sha256.ascending.esl.result', + build_by_default : false, + command : [ + efisecdb, '-g', '{redhat}', '-t', 'sha256', '-a', + '-h', '87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7', + '-h', '0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f', + '-h', 'a3a5e715f0cc574a73c3f9bebb6bc24f32ffd5b67b387244c2c909da779a1478', + '-h', '8d74beec1be996322ad76813bafb92d40839895d6dd7ee808b17ca201eac98be', + '-s', 'data', '-s', 'ascending', '-f', '-o', '@OUTPUT@' + ] + ) + ], + + 'test.esl.sha256.removal.descending.esl' : [ + 'testing ESL entry removal with sha256 sums (descending)', + custom_target( + 'test.esl.sha256.removal.descending.esl_result', output : 'test.esl.sha256.removal.descending.esl.result', input : 'test.esl.sha256.unsorted.esl.goal', + build_by_default : false, + command : [ + efisecdb, '-g', '{redhat}', '-t', 'sha256', + '-i', '@INPUT@', '-r', + '-h', 'a3a5e715f0cc574a73c3f9bebb6bc24f32ffd5b67b387244c2c909da779a1478', + '-s', 'data', '-s', 'descending', '-f', '-o', '@OUTPUT@' + ] + ) + ], + + 'test.esl.sha256.addition.unsorted.esl' : [ + 'testing adding a sha256 sum to an existing ESL (unsorted)', + custom_target( + 'test.esl.sha256.addition.unsorted.esl_result', output : 'test.esl.sha256.addition.unsorted.esl.result', input : 'test.esl.sha256.addition.unsorted.esl.goal', + build_by_default : false, + command : [ + efisecdb, '-g', '{redhat}', '-t', 'sha256', + '-i', '@INPUT@', '-a', + '-h', 'a3a5e715f0cc574a73c3f9bebb6bc24f32ffd5b67b387244c2c909da779a1478', + '-s', 'none', '-f', '-o', '@OUTPUT@' + ] + ) + ], + + 'test.esl.cert.addition.esl' : [ + 'testing ESL entry addition with x509 cert', + custom_target( + 'test.esl.cert.addition.esl_result', output : 'test.esl.cert.addition.esl.result', input : ['test.esl.sha256.unsorted.esl.goal', 'test.esl.cert.addition.cert.cer'], + build_by_default : false, + command : [ + efisecdb, '-g', '{redhat}', '-t', 'sha256', + '-i', '@INPUT0@', '-a', '-c', '@INPUT1@', + '-f', '-o', '@OUTPUT@' + ] + ) + ], + + 'test.esl.cert.removal.esl' : [ + 'testing ESL entry removal with x509 cert', + custom_target( + 'test.esl.cert.removal.esl_result', output : 'test.esl.cert.removal.esl.result', input : ['test.esl.sha256.unsorted.esl.goal', 'test.esl.cert.addition.cert.cer'], + build_by_default : false, + command : [ + efisecdb, '-g', '{redhat}', '-t', 'sha256', + '-i', '@INPUT0@', '-r', '-c', '@INPUT1@', + '-f', '-o', '@OUTPUT@' + ] + ) + ] +} + +secdb_wrapper = find_program('sh/_efisecdb-test.sh') +foreach efisectest, testinfo : efisecdb_tests + test(testinfo[0], secdb_wrapper, args: [files(efisectest + '.goal'), testinfo[1], efisecdb]) +endforeach + +tester_wrapper = find_program('test-threading') + +test('Test threading', tester_wrapper, args : [thread_test]) diff --git a/tests/sh/_efisecdb-test.sh b/tests/sh/_efisecdb-test.sh new file mode 100644 index 00000000..1bcab386 --- /dev/null +++ b/tests/sh/_efisecdb-test.sh @@ -0,0 +1,15 @@ +#!/bin/sh -eu + +# Usage: goal result efisecdb + +if ! cmp "$1" "$2" ; then + if echo "$1" | grep -qE "\.txt$" ; then + diff -U 200 "$1" "$2" + else + "$3" --dump --annotate -s none -i "$1" > "${1}.txt" + "$3" --dump --annotate -s none -i "$2" > "${2}.txt" + diff -U 200 "${1}.txt" "${2}.txt" + rm "${1}.txt" "${2}.txt" + fi + exit 1 +fi diff --git a/tests/sh/_grubenv-test.sh b/tests/sh/_grubenv-test.sh new file mode 100644 index 00000000..6af7df64 --- /dev/null +++ b/tests/sh/_grubenv-test.sh @@ -0,0 +1,14 @@ +#!/bin/sh -eu + +# Usage: editenv dir testname torun + +"$1" "${3}.result.env" create +"$1" "${3}.result.env" set debug=all,-scripting,-lexer +truncate -s 512 "${3}.result.env" +eval "$4" +if grep -q "Do not edit" "${3}.result.env" ; then + cmp "${3}.result.var" "${2}/${3}.new.goal.var" +else + cmp "${3}.result.var" "${2}/${3}.old.goal.var" +fi +rm -f "${3}.result."* diff --git a/tests/sh/test.bootorder.var.sh b/tests/sh/test.bootorder.var.sh new file mode 100644 index 00000000..ef334ac6 --- /dev/null +++ b/tests/sh/test.bootorder.var.sh @@ -0,0 +1,5 @@ +#!/bin/sh -eu + +"$1" -i "${2}/test.bootorder.var.goal.var" -e test.bootorder.var.0.result.var +"$1" -i test.bootorder.var.0.result.var -e test.bootorder.var.1.result.var -D +cmp "${2}/test.bootorder.var.goal.var" test.bootorder.var.1.result.var diff --git a/tests/sh/test.conin.var.sh b/tests/sh/test.conin.var.sh new file mode 100644 index 00000000..773af3cc --- /dev/null +++ b/tests/sh/test.conin.var.sh @@ -0,0 +1,5 @@ +#!/bin/sh -eu + +"$1" -i "${2}/test.conin.var.goal.var" -e test.conin.var.0.result.var +"$1" -i test.conin.var.0.result.var -e test.conin.var.1.result.var -D +cmp "${2}/test.conin.var.goal.var" test.conin.var.1.result.var diff --git a/tests/sh/test.efivar.l.sh b/tests/sh/test.efivar.l.sh new file mode 100644 index 00000000..7be26d59 --- /dev/null +++ b/tests/sh/test.efivar.l.sh @@ -0,0 +1,3 @@ +#!/bin/sh -eu + +"$1" -L | grep -q '^{91376aff-cba6-42be-949d-06fde81128e8} {grub} efi_guid_grub GRUB$' diff --git a/tests/sh/test.esl.dump.x509.sha256.sh b/tests/sh/test.esl.dump.x509.sha256.sh new file mode 100644 index 00000000..12f1e100 --- /dev/null +++ b/tests/sh/test.esl.dump.x509.sha256.sh @@ -0,0 +1,5 @@ +#!/bin/sh -eu + +"$1" -i "${2}/test.esl.sha256.addition.unsorted.esl.goal" -A > test.esl.dump.x509.sha256.result.txt +cmp "${2}/test.esl.dump.x509.sha256.goal.txt" test.esl.sha256.addition.unsorted.result.txt + diff --git a/tests/test-threading b/tests/test-threading index a0740355..92b8f5b3 100755 --- a/tests/test-threading +++ b/tests/test-threading @@ -2,29 +2,26 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # test (some) efivar thread safety # -# Copyright Jonathan Marler +# Copyright Jonathan Marler and contributors -set -e - -if [ "x$TOPDIR" = "x" ] ; then - TOPDIR="$(realpath "$(dirname "$0")/../")" +if [ "$#" -ne 1 ] ; then + echo "Usage: ${0} " + exit 1 fi rm -rf scratch mkdir scratch -EFIVARFS_PATH="" -LD_LIBRARY_PATH="" -LIBEFIVAR_OPS="" +set -eu +TESTERPATH="$1" EFIVARFS_PATH=$(realpath scratch)/ -LD_LIBRARY_PATH="${TOPDIR}/src/" LIBEFIVAR_OPS=efivarfs -export EFIVARFS_PATH LD_LIBRARY_PATH LIBEFIVAR_OPS +export EFIVARFS_PATH LIBEFIVAR_OPS test() { echo -n "testing $1 thread..." - "${TOPDIR}/src/thread-test" -t "$1" + "$TESTERPATH" -t "$1" } test 1 diff --git a/tests/test.esl.annotation.esl.goal.txt b/tests/test.esl.annotation.esl.goal similarity index 100% rename from tests/test.esl.annotation.esl.goal.txt rename to tests/test.esl.annotation.esl.goal diff --git a/tests/test.parse.db.var.goal.txt b/tests/test.parse.db.var.goal similarity index 100% rename from tests/test.parse.db.var.goal.txt rename to tests/test.parse.db.var.goal