All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel Díaz" <daniel.diaz@linaro.org>
To: Masahiro Yamada <masahiroy@kernel.org>,
	Michal Marek <michal.lkml@markovi.net>,
	Rolf Eike Beer <eb@emlix.com>,
	linux-kbuild@vger.kernel.org,
	linux-kernel@vger.kernel.org (open list)
Cc: "Daniel Díaz" <daniel.diaz@linaro.org>,
	stable@vger.kernel.org,
	"Naresh Kamboju" <naresh.kamboju@linaro.org>
Subject: [PATCH] scripts: Fix linking extract-cert against libcrypto
Date: Mon,  8 Feb 2021 22:59:56 -0600	[thread overview]
Message-ID: <20210209050047.1958473-1-daniel.diaz@linaro.org> (raw)

When compiling under OpenEmbedded, the following error is seen
as of recently:

  /srv/oe/build/tmp/hosttools/ld: cannot find /lib/libc.so.6 inside /
  /srv/oe/build/tmp/hosttools/ld: cannot find /usr/lib/libc_nonshared.a inside /
  /srv/oe/build/tmp/hosttools/ld: cannot find /lib/ld-linux-x86-64.so.2 inside /
  collect2: error: ld returned 1 exit status
  make[2]: *** [scripts/Makefile.host:95: scripts/extract-cert] Error 1

This is because 2cea4a7a1885 ("scripts: use pkg-config to
locate libcrypto") now calls for `pkg-config --libs libcrypto`
and inserts that into the Makefile rules as LDLIBS when
building extract-cert.c.

The problem is that --libs will include both -l and -L, which
will be out of order when compiling/linking.

This (very ugly) command is what's produced with OpenEmbedded:

  gcc -Wp,-MMD,scripts/.extract-cert.d -Wall -Wmissing-prototypes -Wstrict-prototypes \
    -O2 -fomit-frame-pointer -std=gnu89 \
    -isystem/oe/build/tmp/work/MACHINE/linux/5.10+gitAUTOINC+b01f250d83-r0/recipe-sysroot-native/usr/include \
    -O2 -pipe -L/oe/build/tmp/work/MACHINE/linux/5.10+gitAUTOINC+b01f250d83-r0/recipe-sysroot-native/usr/lib \
    -L/oe/build/tmp/work/MACHINE/linux/5.10+gitAUTOINC+b01f250d83-r0/recipe-sysroot-native/lib \
    -Wl,-rpath-link,/oe/build/tmp/work/MACHINE/linux/5.10+gitAUTOINC+b01f250d83-r0/recipe-sysroot-native/usr/lib \
    -Wl,-rpath-link,/oe/build/tmp/work/MACHINE/linux/5.10+gitAUTOINC+b01f250d83-r0/recipe-sysroot-native/lib \
    -Wl,-rpath,/oe/build/tmp/work/MACHINE/linux/5.10+gitAUTOINC+b01f250d83-r0/recipe-sysroot-native/usr/lib \
    -Wl,-rpath,/oe/build/tmp/work/MACHINE/linux/5.10+gitAUTOINC+b01f250d83-r0/recipe-sysroot-native/lib \
    -Wl,-O1 -I/oe/build/tmp/work/MACHINE/linux/5.10+gitAUTOINC+b01f250d83-r0/recipe-sysroot-native/usr/include \
    -I ./scripts -o scripts/extract-cert \
    /oe/build/tmp/work-shared/intel-corei7-64/kernel-source/scripts/extract-cert.c \
    -L/oe/build/tmp/work/MACHINE/linux/5.10+gitAUTOINC+b01f250d83-r0/recipe-sysroot/usr//lib \
    -lcrypto

As per `make`'s documentation:

  LDFLAGS
    Extra flags to give to compilers when they are supposed to
    invoke the linker, ‘ld’, such as -L. Libraries (-lfoo)
    should be added to the LDLIBS variable instead.

  LDLIBS
    Library flags or names given to compilers when they are
    supposed to invoke the linker, ‘ld’. LOADLIBES is a
    deprecated (but still supported) alternative to LDLIBS.
    Non-library linker flags, such as -L, should go in the
    LDFLAGS variable.

Fixes: 2cea4a7a1885 ("scripts: use pkg-config to locate libcrypto")
Cc: stable@vger.kernel.org # 5.6.x
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: Daniel Díaz <daniel.diaz@linaro.org>
---
 scripts/Makefile | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/scripts/Makefile b/scripts/Makefile
index 9de3c03b94aa..4b4e938b4ba7 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -3,7 +3,8 @@
 # scripts contains sources for various helper programs used throughout
 # the kernel for the build process.
 
-CRYPTO_LIBS = $(shell pkg-config --libs libcrypto 2> /dev/null || echo -lcrypto)
+CRYPTO_LDFLAGS = $(shell pkg-config --libs-only-L libcrypto 2> /dev/null)
+CRYPTO_LDLIBS = $(shell pkg-config --libs-only-l libcrypto 2> /dev/null || echo -lcrypto)
 CRYPTO_CFLAGS = $(shell pkg-config --cflags libcrypto 2> /dev/null)
 
 hostprogs-always-$(CONFIG_BUILD_BIN2C)			+= bin2c
@@ -17,9 +18,11 @@ hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE)	+= insert-sys-cert
 
 HOSTCFLAGS_sorttable.o = -I$(srctree)/tools/include
 HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include
-HOSTLDLIBS_sign-file = $(CRYPTO_LIBS)
+HOSTLDFLAGS_sign-file = $(CRYPTO_LDFLAGS)
+HOSTLDLIBS_sign-file = $(CRYPTO_LDLIBS)
 HOSTCFLAGS_extract-cert.o = $(CRYPTO_CFLAGS)
-HOSTLDLIBS_extract-cert = $(CRYPTO_LIBS)
+HOSTLDFLAGS_extract-cert = $(CRYPTO_LDFLAGS)
+HOSTLDLIBS_extract-cert = $(CRYPTO_LDLIBS)
 
 ifdef CONFIG_UNWINDER_ORC
 ifeq ($(ARCH),x86_64)
-- 
2.25.1


             reply	other threads:[~2021-02-09  5:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09  4:59 Daniel Díaz [this message]
2021-02-09  8:44 ` [PATCH] scripts: Fix linking extract-cert against libcrypto Rolf Eike Beer
2021-02-11  8:23   ` Rolf Eike Beer
2021-02-11 10:29   ` Rolf Eike Beer
2021-02-12  7:44     ` Rolf Eike Beer
2021-02-16 23:53       ` Daniel Díaz
2021-02-11  7:11 ` Masahiro Yamada
2021-02-16 23:51   ` Daniel Díaz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210209050047.1958473-1-daniel.diaz@linaro.org \
    --to=daniel.diaz@linaro.org \
    --cc=eb@emlix.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=naresh.kamboju@linaro.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.