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 binary_format to rustc target specs #136637

Merged
merged 1 commit into from
Feb 24, 2025
Merged

Conversation

Pyr0de
Copy link
Contributor

@Pyr0de Pyr0de commented Feb 6, 2025

Added binary format field to TargetOptions

Fixes #135724

r? @Noratrieb

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 6, 2025
@Pyr0de

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) label Feb 7, 2025
@Pyr0de
Copy link
Contributor Author

Pyr0de commented Feb 7, 2025

@rustbot label -O-apple +A-target-specs

@rustbot rustbot added A-target-specs Area: Compile-target specifications and removed O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) labels Feb 7, 2025
@bors
Copy link
Contributor

bors commented Feb 7, 2025

☔ The latest upstream changes (presumably #136684) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot rustbot added the O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) label Feb 7, 2025
@Pyr0de Pyr0de marked this pull request as ready for review February 8, 2025 05:15
@rustbot
Copy link
Collaborator

rustbot commented Feb 8, 2025

These commits modify compiler targets.
(See the Target Tier Policy.)

Copy link
Member

@Noratrieb Noratrieb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is great. It looks good, but I'll take a closer look to ensure that every single target is still correct after you address my feedback below. Then we can merge it.

@Pyr0de
Copy link
Contributor Author

Pyr0de commented Feb 14, 2025

There were 2 places that used this adhoc logic for the binary format

This one, I have changed to use the binary format field from Target

This one requires the object::read::BinaryFormat to pass to another function

let binary_format = if sess.target.is_like_osx {
BinaryFormat::MachO
} else if sess.target.is_like_windows {
BinaryFormat::Coff
} else if sess.target.is_like_aix {
BinaryFormat::Xcoff
} else {
BinaryFormat::Elf
};
let mut file = write::Object::new(binary_format, architecture, endianness);

@@ -208,7 +190,7 @@ fn prefix_and_suffix<'tcx>(
let mut begin = String::new();
let mut end = String::new();
match asm_binary_format {
AsmBinaryFormat::Elf => {
BinaryFormat::Elf | BinaryFormat::Xcoff => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Xcoff here with Elf since it wasn't taken into account before and AsmBinaryFormat defaulted to elf

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'd expect this to be wrong, but not any more wrong than before, and I don't really know anything about XCoff. Let's leave it like this and open a follow-up issue about this and ping the AIX maintainers there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created an issue about this at #137219

Copy link
Contributor

@folkertdev folkertdev Feb 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

author of this file here: I just checked, and this is definitely wrong and needs something custom. I don't think we have any tests that would hit this target, so I think this PR can just be merged first, and then we fix naked_asm for AIX later.

I'll have a stab at a fix, and then hopefully the AIX folks can confirm that what I come up with actually works.

also in general: this is a really nice change, thanks!

@bors
Copy link
Contributor

bors commented Feb 15, 2025

☔ The latest upstream changes (presumably #137046) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@Noratrieb Noratrieb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the other use you mentioned, I would add a method to BinaryFormat that returns the object::BinaryFormat and use that there.

I also ran the following script to compare your results against the previous logic:

#!/usr/bin/env bash
for target in $(rustc +dev3 --print target-list); do
	json=$(rustc +dev3 --print target-spec-json --target "$target" -Zunstable-options 2>/dev/null)
	fmt=$(echo "$json"| jq '."binary-format"' -r)
	
	is_like_windows=$(echo "$json"| jq '."is-like-windows"')
	is_like_osx=$(echo "$json"| jq '."is-like-osx"')
	is_like_wasm=$(echo "$json"| jq '."is-like-wasm"')

	if [ "$is_like_windows" = "true" ]; then
		if [ "$fmt" != "coff" ]; then
			echo "ERROR: $fmt $target"
		fi
	elif [ "$is_like_osx" = "true" ]; then
		if [ "$fmt" != "mach-o" ]; then
			echo "ERROR: $fmt $target"
		fi
	elif [ "$is_like_wasm" = "true" ]; then
		if [ "$fmt" != "wasm" ]; then
			echo "ERROR: $fmt $target"
		fi
	else
		if [ "$fmt" != "null" ]; then
			echo "ERROR: $fmt $target"
		fi
	fi
done

It found two results:

ERROR: xcoff powerpc64-ibm-aix
ERROR: null x86_64-pc-cygwin

XCoff for AIX is good, but ELF for cygwin is wrong. Cygwin is Windows and uses Coff, you need to adjust that as well.

@@ -208,7 +190,7 @@ fn prefix_and_suffix<'tcx>(
let mut begin = String::new();
let mut end = String::new();
match asm_binary_format {
AsmBinaryFormat::Elf => {
BinaryFormat::Elf | BinaryFormat::Xcoff => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'd expect this to be wrong, but not any more wrong than before, and I don't really know anything about XCoff. Let's leave it like this and open a follow-up issue about this and ping the AIX maintainers there.

@Noratrieb
Copy link
Member

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Feb 23, 2025

📌 Commit 17f2928 has been approved by Noratrieb

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 23, 2025
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Feb 23, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 23, 2025
Rollup of 8 pull requests

Successful merges:

 - rust-lang#136439 (Misc. `rustc_codegen_ssa` cleanups 🧹)
 - rust-lang#136543 (intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic)
 - rust-lang#136637 (Add binary_format to rustc target specs)
 - rust-lang#137099 (Fix rustdoc test directives that were accidentally ignored 🧐)
 - rust-lang#137297 (Update `compiler-builtins` to 0.1.147)
 - rust-lang#137451 (FIx `sym` -> `syn` typo in tail-expr-drop-order type opt-out)
 - rust-lang#137452 (bootstrap: add module docs for core:metadata)
 - rust-lang#137483 (rename sub_ptr to offset_from_unsigned)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 23, 2025
Rollup of 8 pull requests

Successful merges:

 - rust-lang#136439 (Misc. `rustc_codegen_ssa` cleanups 🧹)
 - rust-lang#136543 (intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic)
 - rust-lang#136637 (Add binary_format to rustc target specs)
 - rust-lang#137099 (Fix rustdoc test directives that were accidentally ignored 🧐)
 - rust-lang#137297 (Update `compiler-builtins` to 0.1.147)
 - rust-lang#137451 (FIx `sym` -> `syn` typo in tail-expr-drop-order type opt-out)
 - rust-lang#137452 (bootstrap: add module docs for core:metadata)
 - rust-lang#137483 (rename sub_ptr to offset_from_unsigned)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2c6fa32 into rust-lang:master Feb 24, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Feb 24, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 24, 2025
Rollup merge of rust-lang#136637 - Pyr0de:binary-format, r=Noratrieb

Add binary_format to rustc target specs

Added binary format field to `TargetOptions`

Fixes rust-lang#135724

r? `@Noratrieb`
@Pyr0de Pyr0de deleted the binary-format branch February 24, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-target-specs Area: Compile-target specifications O-apple Operating system: Apple (macOS, iOS, tvOS, visionOS, watchOS) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add binary_format to rustc target specs
6 participants