Skip to content

Commit

Permalink
src/Makefile: do not override LIBS and CFLAGS for prerequisites
Browse files Browse the repository at this point in the history
Without the change `make --shuffle` build occasionally fails as:

    $ gcc -Og  -g3 -Wall -Wextra  -Werror  -std=gnu11 -funsigned-char -fvisibility=hidden -specs=/build/source/src/include/gcc.specs -fno-merge-constants  -L.   -Wl,--build-id -Wl,--no-allow-shlib-undefined -Wl,--no-undefined-version -Wl,-z,now -Wl,-z,muldefs -Wl,-z,relro -Wl,--fatal-warnings     -DLIBEFIVAR_VERSION=38 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -I/build/source/src/include/  -shared -Wl,-soname,libefisec.so.1 -Wl,--version-script=libefisec.map  -o libefisec.so sec.o secdb.o esl-iter.o util.o -lefivar -lefisec -ldl
/nix/store/zwqkxpi1iz66mix0kirdaq2ps6a9g9cg-binutils-2.41/bin/ld: cannot find -lefivar: No such file or directory
collect2: error: ld returned 1 exit status
make[1]: *** [/build/source/src/include/rules.mk:38: libefisec.so] Error 1 shuffle=721268944

Before the change 2-3 rebuild attemts were enough to trigger build
failure.

After the change `evivar` survived 100 rebuilds.

Artem Klimov noticed that it happens because LIBS gets overridden
(or not overridden) based on the traversal order `make` takes to build
the prerequisites.

If the order is:

    all -> libefivar.so

then LIBS is taken from libefivar.so target, which is

    libefivar.so : LIBS=dl

There are no prerequisites and all is fine.

But if the build order starts from `efisecdb`, then:

    efisecdb -> libefisec.so

then LIBS is taken from `efisecdb`, this is:

    efisecdb : $(EFISECDB_OBJECTS) | libefisec.so
    efisecdb : private LIBS=efivar efisec dl

When these `LIBS` are propagated to `libefisec.so` we get a linking
failure.

Thus the fix is to mark all `LIBS` instances as `private` to make sure
`LIBS` never gets leaked into prerequisites' `LIBS` use. And while at it
do the same for local `MAP` and local `CFLAGS` for consistency.

Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
  • Loading branch information
trofi authored and vathpela committed Jan 29, 2024
1 parent 4f3da3d commit 8116fb1
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,40 +94,41 @@ libefivar.a : $(patsubst %.o,%.static.o,$(LIBEFIVAR_OBJECTS))

libefivar.so : $(LIBEFIVAR_OBJECTS)
libefivar.so : | $(GENERATED_SOURCES) libefivar.map
libefivar.so : LIBS=dl
libefivar.so : MAP=libefivar.map
libefivar.so : private LIBS=dl
libefivar.so : private MAP=libefivar.map

efivar : $(EFIVAR_OBJECTS) | libefivar.so
efivar : LIBS=efivar dl
efivar : private LIBS=efivar dl

efivar-static : $(EFIVAR_OBJECTS) $(patsubst %.o,%.static.o,$(LIBEFIVAR_OBJECTS))
efivar-static : | $(GENERATED_SOURCES)
efivar-static : LIBS=dl
efivar-static : private 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
libefiboot.so : private LIBS=efivar
libefiboot.so : private MAP=libefiboot.map

libefisec.a : $(patsubst %.o,%.static.o,$(LIBEFISEC_OBJECTS))

libefisec.so : $(LIBEFISEC_OBJECTS)
libefisec.so : | libefisec.map
libefisec.so : MAP=libefisec.map
libefisec.so : private MAP=libefisec.map

efisecdb : $(EFISECDB_OBJECTS) | libefisec.so
efisecdb : LIBS=efivar efisec dl
efisecdb : private 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
efisecdb-static : private LIBS=dl

thread-test : libefivar.so
thread-test : CFLAGS=$(HOST_CFLAGS) -I$(TOPDIR)/src/include/efivar
thread-test : LIBS=pthread efivar
# make sure we don't propagate CFLAGS to object files used by 'libefivar.so'
thread-test.o : private CFLAGS=$(HOST_CFLAGS) -I$(TOPDIR)/src/include/efivar
thread-test : private LIBS=pthread efivar

deps : $(ALL_SOURCES)
@$(MAKE) -f $(SRCDIR)/include/deps.mk deps SOURCES="$(ALL_SOURCES)"
Expand Down

0 comments on commit 8116fb1

Please sign in to comment.