Skip to content

$LDFLAGS not affecting libraries linked by libmpi #12922

Open
@minrk

Description

@minrk

Background information

What version of Open MPI are you using? (e.g., v4.1.6, v5.0.1, git branch name and hash, etc.)

v5.0.5

Describe how Open MPI was installed (e.g., from a source/distribution tarball, from a git clone, from an operating system distribution package, etc.)

build from distribution tarball

Please describe the system on which you are running

  • Operating system/version: linux
  • Computer hardware: CI (Azure, x86)
  • Network type: N/A

Details of the problem

When investigating #12921 where libmpi is linked to libcudart despite being unused, we were curious about why libcudart was not being stripped since we have -Wl,--as-needed in $LDFLAGS.

Looking at the link command for libmpi, it looks like:

x86_64-conda-linux-gnu-cc -shared  -fPIC -DPIC  $lots_of.o  -Wl,--whole-archive $lots_of.a \
  -Wl,--no-whole-archive  -Wl,-rpath -Wl,$WORK/opal/.libs -Wl,-rpath -Wl,$WORK/3rd-party/openpmix/src/.libs -Wl,-rpath -Wl,$PREFIX/lib \
  -L$WORK/3rd-party/openpmix/src/.libs -L$PREFIX/lib -lucc -lcudart \
  $WORK/opal/.libs/libopen-pal.so -lucp -lucs -lucm -luct -lpthread -lrt \
  $WORK/3rd-party/openpmix/src/.libs/libpmix.so -lm -lutil -ldl -levent_core -levent_pthreads -lhwloc  \
  # the next line is $LDFLAGS \
  -march=nocona -mtune=haswell -fstack-protector-strong -O2 -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z -Wl,relro -Wl,-z -Wl,now -Wl,--disable-new-dtags -Wl,--gc-sections -Wl,--allow-shlib-undefined -Wl,-rpath -Wl,$PREFIX/lib -Wl,-rpath-link -Wl,$PREFIX/lib  \
  -pthread -Wl,-soname -Wl,libmpi.so.40 -o .libs/libmpi.so.40.40.5

where it seems relevant that $LDFLAGS comes after the libraries being linked, which I think means -Wl,--as-needed does not get applied to libcudart or any of the libraries being linked into libmpi. It is possible that there is a fix as simple as moving $LDFLAGS earlier in the link command, but I am not sure if that would have any undesirable consequences.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions