This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix cmake circular dependency error
AbandonedPublic

Authored by tskeith on May 4 2020, 10:47 AM.

Details

Summary

The combination of these two changes lead to a cmake error in flang:

The error is:

CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
  "FortranEvaluate" of type STATIC_LIBRARY
    depends on "FortranSemantics" (weak)
  "obj.FortranSemantics" of type OBJECT_LIBRARY
    depends on "FortranEvaluate" (strong)
  "FortranSemantics" of type STATIC_LIBRARY
    depends on "FortranEvaluate" (weak)
    depends on "obj.FortranSemantics" (strong)
At least one of these targets is not a STATIC_LIBRARY.  Cyclic dependencies are allowed only among static libraries.

This change attempts to remove the link-time dependency of FortranEvaluate
on FortranSemantics.

Diff Detail

Event Timeline

tskeith created this revision.May 4 2020, 10:47 AM
Herald added a project: Restricted Project. · View Herald Transcript

@clementval, you added this dependency to fix a linking problem. If this change makes it come back, can you provide details? FortranEvaluate should not depend on FortranSemantics at link time.

@tskeith If I removed it I see these kind of error:

../../../../lib/libFortranEvaluate.a(characteristics.cpp.o):characteristics.cpp:function Fortran::evaluate::characteristics::TypeAndShape::AcquireShape(Fortran::semantics::ObjectEntityDetails const&) [clone .localalias.62]: error: undefined reference to 'Fortran::semantics::ArraySpec::IsDeferredShape() const'
../../../../lib/libFortranEvaluate.a(characteristics.cpp.o):characteristics.cpp:function Fortran::evaluate::characteristics::TypeAndShape::AcquireShape(Fortran::semantics::ObjectEntityDetails const&) [clone .localalias.62]: error: undefined reference to 'Fortran::semantics::ArraySpec::IsAssumedRank() const'
../../../../lib/libFortranEvaluate.a(characteristics.cpp.o):characteristics.cpp:function Fortran::evaluate::characteristics::TypeAndShape::AcquireShape(Fortran::semantics::ObjectEntityDetails const&) [clone .localalias.62]: error: undefined reference to 'Fortran::semantics::ArraySpec::IsAssumedShape() const'
../../../../lib/libFortranEvaluate.a(characteristics.cpp.o):characteristics.cpp:function Fortran::evaluate::characteristics::TypeAndShape::AcquireShape(Fortran::semantics::ObjectEntityDetails const&) [clone .localalias.62]: error: undefined reference to 'Fortran::semantics::ArraySpec::IsAssumedSize() const'

@clementval, you added this dependency to fix a linking problem. If this change makes it come back, can you provide details? FortranEvaluate should not depend on FortranSemantics at link time.

Something has change since the patch landed because the cmake error you are reporting was not being reported before. I have it as well now on my system.

Sorry, I didn't realize that this would more aggressively expose the cyclic library dependencies here. I'm glad they look easy to fix.
As an aside, I think another recent change will also break flang. I'll see if I can get a quick fix.

This revision is now accepted and ready to land.May 4 2020, 12:35 PM

Sorry, I didn't realize that this would more aggressively expose the cyclic library dependencies here. I'm glad they look easy to fix.
As an aside, I think another recent change will also break flang. I'll see if I can get a quick fix.

On my side this is not fixed. I need this dependency at link time. Is there a way to add it differently to not trigger the cmake error?

There _is_ a real cyclic dependency in code between these two libraries that I have been meaning to look in to but haven't had the time. It has to do with the instantiation of templates I believe, but I don't have more information than that as I haven't dug deeply into it yet.
The cyclic dependency doesn't matter to gold, lld or ld64 (the osx linker), but it does matter to bfd which is the default on most Linux systems.

As an aside: the CMake error exists because cyclic dependencies aren't allowed in shared libraries; they aren't allowed because it doesn't really makes sense with how dynamic loading works. The only way to fix this properly (I believe) is to fix the cyclic dependency in the code.

@tskeith If I removed it I see these kind of error:

../../../../lib/libFortranEvaluate.a(characteristics.cpp.o):characteristics.cpp:function Fortran::evaluate::characteristics::TypeAndShape::AcquireShape(Fortran::semantics::ObjectEntityDetails const&) [clone .localalias.62]: error: undefined reference to 'Fortran::semantics::ArraySpec::IsDeferredShape() const'
../../../../lib/libFortranEvaluate.a(characteristics.cpp.o):characteristics.cpp:function Fortran::evaluate::characteristics::TypeAndShape::AcquireShape(Fortran::semantics::ObjectEntityDetails const&) [clone .localalias.62]: error: undefined reference to 'Fortran::semantics::ArraySpec::IsAssumedRank() const'
../../../../lib/libFortranEvaluate.a(characteristics.cpp.o):characteristics.cpp:function Fortran::evaluate::characteristics::TypeAndShape::AcquireShape(Fortran::semantics::ObjectEntityDetails const&) [clone .localalias.62]: error: undefined reference to 'Fortran::semantics::ArraySpec::IsAssumedShape() const'
../../../../lib/libFortranEvaluate.a(characteristics.cpp.o):characteristics.cpp:function Fortran::evaluate::characteristics::TypeAndShape::AcquireShape(Fortran::semantics::ObjectEntityDetails const&) [clone .localalias.62]: error: undefined reference to 'Fortran::semantics::ArraySpec::IsAssumedSize() const'

What compiler, linker, and OS?

It seems that another cyclic dependency exists through FortranParser, which requires the Deleters defined in FortranEvaluate.

Sorry, I didn't realize that this would more aggressively expose the cyclic library dependencies here. I'm glad they look easy to fix.
As an aside, I think another recent change will also break flang. I'll see if I can get a quick fix.

On my side this is not fixed. I need this dependency at link time. Is there a way to add it differently to not trigger the cmake error?

I'm looking at restricting it to PUBLIC libraries, which would give you the previous behavior for this code.

I've updated my previous commit to avoid the problem. See D79366

I've updated my previous commit to avoid the problem. See D79366

This fixes the problem.

@tskeith If I removed it I see these kind of error:

../../../../lib/libFortranEvaluate.a(characteristics.cpp.o):characteristics.cpp:function Fortran::evaluate::characteristics::TypeAndShape::AcquireShape(Fortran::semantics::ObjectEntityDetails const&) [clone .localalias.62]: error: undefined reference to 'Fortran::semantics::ArraySpec::IsDeferredShape() const'
../../../../lib/libFortranEvaluate.a(characteristics.cpp.o):characteristics.cpp:function Fortran::evaluate::characteristics::TypeAndShape::AcquireShape(Fortran::semantics::ObjectEntityDetails const&) [clone .localalias.62]: error: undefined reference to 'Fortran::semantics::ArraySpec::IsAssumedRank() const'
../../../../lib/libFortranEvaluate.a(characteristics.cpp.o):characteristics.cpp:function Fortran::evaluate::characteristics::TypeAndShape::AcquireShape(Fortran::semantics::ObjectEntityDetails const&) [clone .localalias.62]: error: undefined reference to 'Fortran::semantics::ArraySpec::IsAssumedShape() const'
../../../../lib/libFortranEvaluate.a(characteristics.cpp.o):characteristics.cpp:function Fortran::evaluate::characteristics::TypeAndShape::AcquireShape(Fortran::semantics::ObjectEntityDetails const&) [clone .localalias.62]: error: undefined reference to 'Fortran::semantics::ArraySpec::IsAssumedSize() const'

What compiler, linker, and OS?

CentOS Linux release 7.8.2003 (AltArch)
gcc 7.5
GNU gold

By the way, with the fix from D79366 you can keep the dependency as is.

tskeith abandoned this revision.May 4 2020, 3:48 PM

@stephenneuendorffer, thanks for taking care of this.