Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 914711 - app-crypt/gnupg: cross compilation is broken
Summary: app-crypt/gnupg: cross compilation is broken
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2023-09-25 16:54 UTC by Allen Webb
Modified: 2024-02-24 23:11 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Allen Webb 2023-09-25 16:54:01 UTC
gnupg fails to cross comiple because npth-config is setting `-L/usr/lib64`:

```
aarch64-cros-linux-gnu-clang   -DKEYBOX_WITH_X509=1 -Wall -Wno-pointer-sign -Wpointer-arith  -Os -pipe  -march=armv8-a+crc+crypto -mtune=cortex-a55 -ftree-vectorize -g -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections  -Wl,-O2 -Wl,--as-needed  -Wl,--gc-sections -Wl,--icf=all -o kbxutil kbxutil-kbxutil.o kbxutil-keybox-util.o kbxutil-keybox-init.o kbxutil-keybox-blob.o kbxutil-keybox-file.o kbxutil-keybox-search.o kbxutil-keybox-update.o kbxutil-keybox-openpgp.o kbxutil-keybox-dump.o ../common/libcommon.a -lksba -lgpg-error -lgcrypt -lgpg-error     
aarch64-cros-linux-gnu-clang   -DKEYBOX_WITH_X509=1     -Wall -Wno-pointer-sign -Wpointer-arith  -Os -pipe  -march=armv8-a+crc+crypto -mtune=cortex-a55 -ftree-vectorize -g -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections  -Wl,-O2 -Wl,--as-needed  -Wl,--gc-sections -Wl,--icf=all -o keyboxd keyboxd-keyboxd.o keyboxd-kbxserver.o keyboxd-frontend.o keyboxd-backend-support.o keyboxd-backend-cache.o keyboxd-backend-kbx.o keyboxd-backend-sqlite.o keyboxd-keybox-util.o keyboxd-keybox-init.o keyboxd-keybox-blob.o keyboxd-keybox-file.o keyboxd-keybox-search.o keyboxd-keybox-update.o keyboxd-keybox-openpgp.o keyboxd-keybox-dump.o ../common/libcommonpth.a -lksba -lgpg-error -lgcrypt -lassuan -L/usr/lib64 -lnpth -lsqlite3 -lgpg-error
...
ld.lld: error: /build/corsola/usr/lib/../lib64/Scrt1.o is incompatible with elf64-x86-64
ld.lld: error: /build/corsola/usr/lib/../lib64/crti.o is incompatible with elf64-x86-64
ld.lld: error: /usr/lib64/clang/17/lib/linux/clang_rt.crtbegin-aarch64.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-keyboxd.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-kbxserver.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-frontend.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-backend-support.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-backend-cache.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-backend-kbx.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-backend-sqlite.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-keybox-util.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-keybox-init.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-keybox-blob.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-keybox-file.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-keybox-search.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-keybox-update.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-keybox-openpgp.o is incompatible with elf64-x86-64
ld.lld: error: keyboxd-keybox-dump.o is incompatible with elf64-x86-64
ld.lld: error: ../common/libcommonpth.a(libcommonpth_a-i18n.o) is incompatible with elf64-x86-64
ld.lld: error: ../common/libcommonpth.a(libcommonpth_a-mapstrings.o) is incompatible with elf64-x86-64
ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

Here is a fix that works for me:
```
diff --git a/app-crypt/gnupg/gnupg-2.4.0.ebuild b/app-crypt/gnupg/gnupg-2.4.0.ebuild
index 9e446d1ad..3e7fb53b5 100644
--- a/app-crypt/gnupg/gnupg-2.4.0.ebuild
+++ b/app-crypt/gnupg/gnupg-2.4.0.ebuild
@@ -118,11 +118,12 @@ my_src_configure() {
                KSBA_CONFIG="${ESYSROOT}/usr/bin/ksba-config"
                LIBASSUAN_CONFIG="${ESYSROOT}/usr/bin/libassuan-config"
                LIBGCRYPT_CONFIG="${ESYSROOT}/usr/bin/${CHOST}-libgcrypt-config"
-               NPTH_CONFIG="${ESYSROOT}/usr/bin/npth-config"
 
                $("${S}/configure" --help | grep -o -- '--without-.*-prefix')
        )
 
+       export ac_cv_path_NPTH_CONFIG="${CHOST}-npth-config"
+
        if use prefix && use usb; then
                # bug #649598
                append-cppflags -I"${ESYSROOT}/usr/include/libusb-1.0"
```

Reproducible: Always
Comment 1 Allen Webb 2023-09-25 16:55:21 UTC
See also: https://bugs.gentoo.org/914708
Comment 2 Allen Webb 2023-09-25 18:00:16 UTC
That broke non-cross compilation, so I changed it to:
+       # Fix cross-compilation. (https://bugs.gentoo.org/914711)
+       if tc-is-cross-compiler; then
+               export ac_cv_path_NPTH_CONFIG="${CHOST}-npth-config"
+       else
+               export ac_cv_path_NPTH_CONFIG="${ESYSROOT}/usr/bin/npth-config"
+       fi
Comment 3 Raul Rangel 2023-10-13 21:53:55 UTC
https://chromium-review.googlesource.com/c/chromiumos/overlays/portage-stable/+/4939479 was also required for me.
Comment 4 James Le Cuirot gentoo-dev 2023-12-16 22:49:49 UTC
That doesn't work for me. How would it work anyway, where would ${CHOST}-npth-config even come from?

The fact is this package is a mess for cross-compiling. Even once you get past NPTH, the other *-config scripts also add -L/usr/lib64 to the flags. The only way to do this right is pkg-config, and I suspect upstream won't like that.
Comment 5 James Le Cuirot gentoo-dev 2024-02-24 12:08:20 UTC
This is now unavoidable since Portage pulls in gnupg via getuto. I used to sidestep the issue with USE=-rsync-verify.
Comment 6 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-02-24 12:20:49 UTC
(In reply to James Le Cuirot from comment #4)
> That doesn't work for me. How would it work anyway, where would
> ${CHOST}-npth-config even come from?
> 
> The fact is this package is a mess for cross-compiling. Even once you get
> past NPTH, the other *-config scripts also add -L/usr/lib64 to the flags.
> The only way to do this right is pkg-config, and I suspect upstream won't
> like that.

They've actually got way better about pkg-config recently...
Comment 7 James Le Cuirot gentoo-dev 2024-02-24 12:39:17 UTC
Yeah, now I'm looking deeper, it seems to use pkg-config under the hood, and setting ac_cv_path_GPGRT_CONFIG helps (GPGRT_CONFIG strangely doesn't), but something's still not right.
Comment 8 James Le Cuirot gentoo-dev 2024-02-24 17:21:33 UTC
Good news! Removing all the other CONFIG variables and adding this makes it work!

> ac_cv_path_GPGRT_CONFIG="${ESYSROOT}/usr/bin/${CHOST}-gpgrt-config"

Only after bumping npth to 1.7 though, which was released just 2 days ago. :D That includes a new .pc file, which gpgrt-config uses.

I don't know exactly how gpgrt-config works. It looks like it a reimplementation of pkg-config in Bash. As awful as that sounds, it does work. It even uses the SYSROOT properly without setting any environment variables, seemingly by basing paths on where it was executed from. As such, using the build host's gpgrt-config doesn't work. I fear this won't work with prefix, but this is still a big improvement.
Comment 9 James Le Cuirot gentoo-dev 2024-02-24 17:25:19 UTC
Giving app-crypt/pinentry the same treatment fixes that too. :)
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-02-24 17:26:37 UTC
I think it's obvious but feel free to commit whatever to the gnupg stack as long as you've tested it. Thank you!
Comment 11 Larry the Git Cow gentoo-dev 2024-02-24 23:11:08 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ff8d9f188ee04d7cb0737e55b6e917cf569679de

commit ff8d9f188ee04d7cb0737e55b6e917cf569679de
Author:     James Le Cuirot <chewi@gentoo.org>
AuthorDate: 2024-02-24 23:08:53 +0000
Commit:     James Le Cuirot <chewi@gentoo.org>
CommitDate: 2024-02-24 23:08:53 +0000

    app-crypt/gnupg: Fix cross-compiling by using gpgrt-config
    
    It appears to be a reimplementation of pkg-config in Bash. It even uses the
    SYSROOT properly without setting any environment variables, seemingly by basing
    paths on where it was executed from. As such, using the build host's
    gpgrt-config doesn't work. npth 1.7 is needed to cross-compile successfully but
    older versions work for native builds.
    
    Closes: https://bugs.gentoo.org/914711
    Signed-off-by: James Le Cuirot <chewi@gentoo.org>

 app-crypt/gnupg/gnupg-2.4.4-r1.ebuild | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)