-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with --as-needed
with fortran and librt, at least
#104
Comments
It's possible this is something specific about the MPI compilers, but it only seems to come up in the mpi + gcc7 combinations, and removing |
conda-build actually errors out when this is detected these days (there's a way to override it though). |
ok, I'll dig into MPI to see if I can understand how/why they are setting new-dtags and if I can override it. |
Found another weird one today, this time with scotch. scotch gets Hypothesis: clock_gettime is in glibc >= 2.17, so recent libc doesn't need librt for this symbol. But the host glibc is 2.12, so librt is needed. However, the libc in sysroot in the gcc_impl_linux-64 7.3.0 package is 2.31.1. I'm guessing that the more recent glibc version is being used to decide whether librt is needed or not. I don't know if there's a flag I should be adding (or excluding) to consider the host libc (or specify some baseline glibc version directly). The relevant linker command that's producing a lib with missing librt:
|
Where are you seeing glibc 2.31.1, the latest release is 2.28? 2.12.2 is (or at least should be) present in the sysroot of the gcc_impl_linux-64 package (gcc_impl_linux-64-7.3.0-habb00fd_1). |
--as-needed
with fortran, at least--as-needed
with fortran and librt, at least
Oops. I got it from In any case, the linker is treating librt as 'not needed' when librt is only providing symbols present in libc for glibc >= 2.17. I don't know how it's coming to that conclusion or how to tell it to pick a different glibc base version to consider, but I was guessing that it might have to do with using a more recent gcc. |
Interesting, it seems as if the order of the libraries does have some effect. If I add
librt is linked. Adding |
I think @mingwandroid has warned me about this before. -l arguments that happen before --as-needed don't work right. They all have to come after it. That gets back to "mistakes" in makefiles - if they are written in a way that CFLAGS and such get passed after other arguments in the makefile. |
Ah, I see the issue now. Since gcc is being used as the driver the order of the arguments does matter. Specifically the comment about the importance of the order from the GCC manual covers this:
Since the linker has not seen a object file with a symbol from librt when it reaches |
The following change to the diff --git a/recipe/debian-dynamic.patch b/recipe/debian-dynamic.patch
index 50e34f9..28defd0 100644
--- a/recipe/debian-dynamic.patch
+++ b/recipe/debian-dynamic.patch
@@ -131,7 +131,7 @@ Index: scotch/src/libscotch/Makefile
-libscotch$(LIB) : $(LIBSCOTCHDEPS)
- $(AR) $(ARFLAGS) $(@) $(?)
+libscotch$(LIB) : $(LIBSCOTCHDEPS) libscotcherr$(LIB)
-+ $(CC) -shared $(LDFLAGS) $(SONAME)libscotch-$(VERSION)$(SHLIB_EXT) $(LIBSCOTCHDEPS) -L. -lscotcherr -lz -lpthread -lm -o libscotch-$(VERSION)$(SHLIB_EXT)
++ $(CC) -shared $(LDFLAGS) $(SONAME)libscotch-$(VERSION)$(SHLIB_EXT) $(LIBSCOTCHDEPS) -L. -lscotcherr -lz -lpthread -lrt -lm -o libscotch-$(VERSION)$(SHLIB_EXT)
+ ln -s libscotch-$(VERSION)$(SHLIB_EXT) libscotch$(SHLIB_EXT)
+ $(AR) $(ARFLAGS) $(@) $(LIBSCOTCHDEPS)
-$(RANLIB) $(@) |
I've encountered a few hiccups with the new default
-Wl,--as-needed
flag for the compilers. Mostly, these have revealed a few libraries where transitive dependencies were implicit, and can be fixed by making dependencies explicit, or opting out of-Wl,--as-needed
on certain packages.The weirded issue recently is that
--as-needed
and--enable-new-dtags
seem to combine to make entirely non-working fortran executables.To test, create an env with gfortran:
And then try to compile and run a simple fortran hello world (
test.f90
):Simple compilation will work:
But enabling some of the flags that are present when using conda build fails:
Checking
ldd
reveals something odd.libquadmath
is still required, but not found:Removing either as-needed or new-dtags will result in a working executable:
I don't know where the root of the issue is.
The text was updated successfully, but these errors were encountered: