Skip to content
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

Add start-group/end-group flags when linking a program with rustc #14026

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bonzini
Copy link
Contributor

@bonzini bonzini commented Dec 19, 2024

This is needed for QEMU, but it may be useful anyway. Because rustc does not support extract_objects, QEMU creates a static library with all the C objects. It then passes this static library as link_whole, together with another static library containing general purpose utility functions which is passed as link_with.

Unfortunately, these two have a circular dependency and they cannot be merged because of the link_whole/link_with difference. While lld seems to have the --start-group/--end-group semantics automatically, ld.bfd can fail if these options are needed. This can cause difference between distros depending on how Rust is packaged (e.g. Ubuntu 22.04 and Debian bookworm seem to use ld.bfd).

To improve compatibility, add --start-group and --end-group options like Meson already does with C programs.

This is an alternative to #14031. It is a bit inferior for QEMU, but the changes are a bit simpler. Both can be included if desired.

from .. import options
from ..linkers.linkers import GnuLikeDynamicLinkerMixin, SolarisDynamicLinker, CompCertDynamicLinker

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'GnuLikeDynamicLinkerMixin' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GnuLikeDynamicLinkerMixin occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GnuLikeDynamicLinkerMixin' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GnuLikeDynamicLinkerMixin occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GnuLikeDynamicLinkerMixin' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GnuLikeDynamicLinkerMixin occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GnuLikeDynamicLinkerMixin' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GnuLikeDynamicLinkerMixin occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GnuLikeDynamicLinkerMixin' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GnuLikeDynamicLinkerMixin occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GnuLikeDynamicLinkerMixin' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GnuLikeDynamicLinkerMixin occurs after the cyclic
import
of mesonbuild.compilers.rust.
from .. import options
from ..linkers.linkers import GnuLikeDynamicLinkerMixin, SolarisDynamicLinker, CompCertDynamicLinker

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'SolarisDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of SolarisDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'SolarisDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of SolarisDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'SolarisDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of SolarisDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'SolarisDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of SolarisDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'SolarisDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of SolarisDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'SolarisDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of SolarisDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
from .. import options
from ..linkers.linkers import GnuLikeDynamicLinkerMixin, SolarisDynamicLinker, CompCertDynamicLinker

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'CompCertDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompCertDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'CompCertDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompCertDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'CompCertDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompCertDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'CompCertDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompCertDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'CompCertDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompCertDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
'CompCertDynamicLinker' may not be defined if module
mesonbuild.linkers.linkers
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompCertDynamicLinker occurs after the cyclic
import
of mesonbuild.compilers.rust.
mesonbuild/compilers/rust.py Fixed Show fixed Hide fixed
@bonzini bonzini force-pushed the rust-group-libraries branch from 1167d7c to 37d1945 Compare December 19, 2024 23:58
from ..mesonlib import EnvironmentException, MesonException, Popen_safe_logged
from ..options import OptionKey
from .compilers import Compiler, clike_debug_args
from .mixins.clike import GROUP_FLAGS

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'GROUP_FLAGS' may not be defined if module
mesonbuild.compilers.mixins.clike
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GROUP_FLAGS occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GROUP_FLAGS' may not be defined if module
mesonbuild.compilers.mixins.clike
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GROUP_FLAGS occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GROUP_FLAGS' may not be defined if module
mesonbuild.compilers.mixins.clike
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GROUP_FLAGS occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GROUP_FLAGS' may not be defined if module
mesonbuild.compilers.mixins.clike
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GROUP_FLAGS occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GROUP_FLAGS' may not be defined if module
mesonbuild.compilers.mixins.clike
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GROUP_FLAGS occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GROUP_FLAGS' may not be defined if module
mesonbuild.compilers.mixins.clike
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GROUP_FLAGS occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GROUP_FLAGS' may not be defined if module
mesonbuild.compilers.mixins.clike
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GROUP_FLAGS occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GROUP_FLAGS' may not be defined if module
mesonbuild.compilers.mixins.clike
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GROUP_FLAGS occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GROUP_FLAGS' may not be defined if module
mesonbuild.compilers.mixins.clike
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GROUP_FLAGS occurs after the cyclic
import
of mesonbuild.compilers.rust.
'GROUP_FLAGS' may not be defined if module
mesonbuild.compilers.mixins.clike
is imported before module
mesonbuild.compilers.rust
, as the
definition
of GROUP_FLAGS occurs after the cyclic
import
of mesonbuild.compilers.rust.
@bonzini bonzini force-pushed the rust-group-libraries branch 2 times, most recently from 4d524dd to 502317e Compare December 20, 2024 09:17
@bonzini bonzini force-pushed the rust-group-libraries branch from 502317e to ad18530 Compare December 20, 2024 11:29
@@ -62,6 +65,37 @@
except StopIteration:
return None


class RustcCompilerArgs(arglist.CompilerArgs):

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'CompilerArgs' may not be defined if module
mesonbuild.arglist
is imported before module
mesonbuild.compilers.rust
, as the
definition
of CompilerArgs occurs after the cyclic
import
of mesonbuild.compilers.rust.
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.

1 participant