Skip to content

configure: ignore library directories of a foreign architecture - #1121

Open
qianeric-backup wants to merge 1 commit into
vanhauser-thc:masterfrom
qianeric-backup:fix/foreign-arch-libdirs
Open

qianeric-backup wants to merge 1 commit into
vanhauser-thc:masterfrom
qianeric-backup:fix/foreign-arch-libdirs

Conversation

@qianeric-backup

Copy link
Copy Markdown

The problem

On Debian and Ubuntu, /etc/ld.so.conf.d/i386-linux-gnu.conf lists the 32-bit multiarch
directories next to the native ones, and configure reads all of ld.so.conf.d into LIBDIRS:

LIBDIRS="$LIBDIRS `cat /etc/ld.so.conf /etc/ld.so.conf.d/* 2> /dev/null | ...`"

A x86_64 host therefore ends up with both /usr/lib/x86_64-linux-gnu and
/usr/lib/i386-linux-gnu in the search list.

The module checks match libraries by file name only:

TMP_LIB=`/bin/ls $i/libssl.so* 2> /dev/null | grep ssl`

A 32-bit libssl.so in the i386 directory satisfies that check in a 64-bit build, its directory
is appended to XLIBPATHS, and the linker then walks a directory full of objects it cannot use:

/usr/bin/ld: skipping incompatible /lib/i386-linux-gnu/libgcc_s.so.1 when searching for /lib/i386-linux-gnu/libgcc_s.so.1

That is not only noise — the generated -L path points at the wrong library set.

The change

Filter LIBDIRS down to directories whose objects match the host ELF class, before any module is
probed. Each directory is sampled through the first lib*.so* it contains; directories without any
library, and directories whose sample does not contradict SIXFOUR, are kept exactly as before.

Two guards:

  • file(1) missing → the whole filter is skipped and behaviour is unchanged.
  • Directories below --prefix → never filtered. SIXFOUR is derived from uname -m, which
    reports the build host under a cross compiler, so filtering there could drop the target
    libraries the user pointed at explicitly.

Effect

Before (XLIBPATHS and the two linker warnings):

XLIBPATHS=-L/usr/lib -L/usr/local/lib -L/lib -L/lib/i386-linux-gnu
/usr/bin/ld: skipping incompatible /lib/i386-linux-gnu/libgcc_s.so.1 ...

After:

XLIBPATHS=-L/usr/lib -L/usr/local/lib -L/lib -L/lib/x86_64-linux-gnu

Verified on x86_64 Ubuntu 24.04 with gcc 13.3.0: ./configure && make completes with zero
"skipping incompatible" lines and a working ./hydra. The filter is architecture-agnostic in
principle (SIXFOUR picks the 64-bit or 32-bit expectation), but I only had a 64-bit host to test
it on.

Relation to #450

This is adjacent to the pkg-config request in #450 and does not implement it. When looking at that,
I found that configure already carries pkg-config logic — but only inside the Darwin branch, so
non-macOS platforms never use it. I drafted promoting it to all platforms, then dropped that
change: the per-module checks already cover the common layouts (/usr/*p*sql*/include,
$i/libssh/libssh.h, and so on), and I could not demonstrate a real failure it fixes on a normal
Linux install. Submitting that without evidence seemed worse than leaving #450 for someone who hits
a concrete non-standard prefix.

This arch filter, by contrast, reproduces on any Debian/Ubuntu x86_64 host.

/etc/ld.so.conf.d/ lists the native multiarch directory next to a foreign
one on Debian and Ubuntu. A x86_64 host therefore gets both
/usr/lib/x86_64-linux-gnu and /usr/lib/i386-linux-gnu into LIBDIRS.

The module checks match libraries by file name only:

    TMP_LIB=`/bin/ls $i/libssl.so* 2> /dev/null | grep ssl`

so a 32-bit libssl.so in the i386 directory satisfies the check in a 64-bit
build. Its directory is then appended to XLIBPATHS and the linker tries every
object in it:

    /usr/bin/ld: skipping incompatible /lib/i386-linux-gnu/libgcc_s.so.1

The resulting -L path is not just noise: it points at the wrong library set.

Filter LIBDIRS down to the directories whose objects match the host ELF class
before any module is probed. The check samples the first lib*.so* in a
directory with file(1) and keeps the directory when it does not contradict
SIXFOUR; empty directories and directories without any lib*.so* are kept as
before. When file(1) is not available the filter is skipped entirely and the
old behaviour is preserved.

Directories below --prefix are never filtered. SIXFOUR comes from uname -m,
which reports the build host under a cross compiler, so filtering there could
drop the target libraries the user pointed at explicitly.

On a x86_64 host this turns

    XLIBPATHS=-L/usr/lib -L/usr/local/lib -L/lib -L/lib/i386-linux-gnu

into

    XLIBPATHS=-L/usr/lib -L/usr/local/lib -L/lib -L/lib/x86_64-linux-gnu

and removes both "skipping incompatible" lines from the build.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The library-directory filter can hide native dependencies by inspecting symlinks rather than their targets and rejecting samples whose architecture cannot be determined.

2 open issues
What changed in this PR

This PR adds architecture filtering to configure to prevent foreign library directories from entering Hydra’s dependency search paths. It addresses incompatible-library detection, not the broader pkg-config request in #450.

Changes:

  • Samples shared libraries with file and filters directories according to SIXFOUR before module probes.
  • Skips filtering when file is unavailable and exempts directories beneath --prefix.
File Description
configure Adds library-directory classification and filtering before dependency detection.

Review effort: Balanced

Comment thread configure
ARCH_LIBDIRS="$ARCH_LIBDIRS $archdir"
continue
fi
archdesc=`file -b "$archsample" 2> /dev/null`
Comment thread configure
Comment on lines +225 to +233
if [ "$SIXFOUR" = "64" ]; then
case "$archdesc" in
*64-bit*) ARCH_LIBDIRS="$ARCH_LIBDIRS $archdir" ;;
esac
else
case "$archdesc" in
*32-bit*) ARCH_LIBDIRS="$ARCH_LIBDIRS $archdir" ;;
esac
fi
@vanhauser-thc

vanhauser-thc commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

@qianeric-backup please have a look at the issues copilot found

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants