Skip to content

New cfg key: target_binary_format #152586

@workingjubilee

Description

@workingjubilee

The proposal is to experimentally add a new cfg key to the language, target_binary_format (or similar, e.g. target_bin_fmt), for use by things like wasm32-none-component targets.

Code for such targets wants to cfg based on the object or binary format in use. Based on the current state of discussion about. the target maintainers don't feel comfortable forcing this information into target_env, as target_env does not contain this information for any other target.

This would also simplify certain existing cfg combinations that have to do annoying forms of reasoning to arrive at the answer to questions like e.g. "so, is this a PE32+ binary (whether executable or dll)?" The answer is unfortunately not as simple as "is this Windows?" due to the existence of e.g. target_os = "cygwin" and target_os = "uefi".

@rust-lang/lang Do I need a sponsor for this or something?

We have some of this information available in our target definitions, for reference. The proposal is to expose some already-known-to-the-compiler information, with some minor expansions on such as we will upgrade from only knowing about linkable intermediates to also knowing about linked binary formats:

/// Target's binary file format. Defaults to BinaryFormat::Elf
pub binary_format: BinaryFormat,

Object Format By Type and Loader/OS

object type ELF Wasm Wasm Components Apple Windows AIX
intermediate object (.o) ELF Wasm Wasm MachO COFF XCOFF
executable binary (.exe) ELF Wasm Wasm Component MachO PE32[+] XCOFF?
dynamic library (.dll) ELF Wasm Wasm Component MachO PE32[+] XCOFF?

Unresolved Questions

  • Do we need both target_exe_format and target_dll_format? All major binary formats I'm aware of define both their executable and dynamic library formats as variations on the same object format, but "major" and "I'm aware of" are doing a lot of lifting there. It might be fine to simply say something like target_bin_format and add an additional key for target_dll_format later if we find an exception.
  • Do we need a target_o_format? It seems unlikely to me personally (@workingjubilee), as while I wonder about the need to future proof against unexpected target variation, this primarily is about knowledge of the binary that code will actually execute in. However, as Amanieu noted2, arguably it is "more principled" to reason based purely on object format.

See also

Footnotes

  1. https://github.com/rust-lang/rust/issues/152586#issuecomment-3961167536

  2. https://github.com/rust-lang/rust/issues/152586#issuecomment-3967411885

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-binary-formatsArea: binary formats (e.g. ELF, XCOFF, etc.)A-cfgArea: `cfg` conditional compilationA-targetsArea: Concerning the implications of different compiler targetsC-discussionCategory: Discussion or questions that doesn't represent real issues.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCI-lang-radarItems that are on lang's radar and will need eventual work or consideration.T-langRelevant to the language team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions