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

Target families for executable format #716

Closed
1 of 3 tasks
dtolnay opened this issue Jan 26, 2024 · 3 comments
Closed
1 of 3 tasks

Target families for executable format #716

dtolnay opened this issue Jan 26, 2024 · 3 comments
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@dtolnay
Copy link
Member

dtolnay commented Jan 26, 2024

Proposal

We augment the builtin targets specs with a target_family identifying their executable format, where appropriate. For example x86_64-unknown-linux-gnu would get target_family = "elf" for ELF, aarch64-apple-darwin would get target_family = "mach-o" for Mach-O, and i686-pc-windows-msvc would get target_family = "coff" for COFF.

Target families are defined by the Reference as "a more generic description of a target, such as the family of the operating systems or architectures that the target generally falls into. Any number of target_family key-value pairs can be set." Extrapolating this to family of operating systems or architectures or executable formats is a natural fit.

Targets are allowed to belong to any number of target families, so this feature does not interfere with targets that already have "unix" or "windows" as a target family. For example cfg(target_family = "unix") and cfg(target_family = "elf") might both evaluate true on the same target.

Having target families for executable format is useful in the ecosystem because it supersedes the use of target_os as a proxy for this purpose, for example in the inventory or linkme crates which deal with executable-format-specific link sections.

Before:

#[cfg_attr(
    any(
        target_os = "linux",
        target_os = "android",
        target_os = "dragonfly",
        target_os = "freebsd",
        target_os = "fuchsia",
        target_os = "haiku",
        target_os = "illumos",
        target_os = "openbsd",
        target_os = "psp",
    ),
    link_section = ".init_array",
)]
#[cfg_attr(
    any(
        target_os = "macos",
        target_os = "ios",
        target_os = "tvos",
        target_os = "watchos",
        target_os = "visionos",
    ),
    link_section = "__DATA,__mod_init_func",
)]
static __CTOR: unsafe extern "C" fn() = __ctor;

After:

#[cfg_attr(target_family = "elf", link_section = ".init_array")]
#[cfg_attr(target_family = "mach-o", link_section = "__DATA,__mod_init_func")]
static __CTOR: unsafe extern "C" fn() = __ctor;

This approach based on target_family is friendlier to custom targets. For example the target spec for seL4 userspace components, which uses target_os = "none", can just set an "elf" target family in its target specifications and thereby pick up ELF-specific functionality in the ecosystem. Having the ecosystem conflate target_os = "none" with ELF as currently most often done is unwise. Additionally, target_family plays nicely with private / closed source operating systems compared to target_os. Some company with an internal target for a private OS doesn't want to push a PR to all the crates to add a case for their private ELF-based target_os for which maybe the name isn't even public.

Mentors or Reviewers

@dtolnay with guidance from @nspin

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

@dtolnay dtolnay added major-change A proposal to make a major change to rustc T-compiler Add this label so rfcbot knows to poll the compiler team labels Jan 26, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jan 26, 2024

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

Concerns or objections to the proposal should be discussed on Zulip and formally registered here by adding a comment with the following syntax:

@rustbot concern reason-for-concern 
<description of the concern> 

Concerns can be lifted with:

@rustbot resolve reason-for-concern 

See documentation at https://forge.rust-lang.org

cc @rust-lang/compiler @rust-lang/compiler-contributors

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Jan 26, 2024
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Feb 1, 2024
@pnkfelix
Copy link
Member

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Sep 26, 2024
@apiraino
Copy link
Contributor

apiraino commented Oct 7, 2024

@rustbot label -final-comment-period +major-change-accepted

@apiraino apiraino closed this as completed Oct 7, 2024
@rustbot rustbot added major-change-accepted A major change proposal that was accepted to-announce Announce this issue on triage meeting and removed final-comment-period The FCP has started, most (if not all) team members are in agreement labels Oct 7, 2024
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

4 participants