Skip to content

fuchsia: clean up module#5127

Open
dybucc wants to merge 8 commits into
rust-lang:mainfrom
dybucc:fuchsia-bit-width-transition
Open

fuchsia: clean up module#5127
dybucc wants to merge 8 commits into
rust-lang:mainfrom
dybucc:fuchsia-bit-width-transition

Conversation

@dybucc

@dybucc dybucc commented May 31, 2026

Copy link
Copy Markdown
Contributor

Description

This is a clean-up patch. Changes are concerned with the fuchsia module.

There were lacking definitions. There were records with the wrong alignment. There were types that don't exist upstream. This has been fixed. But there's more stuff to fix.

Testing is pending. This time testing is required. Two supported Fuchsia targets are tier 2. There's no CI job for them.

Sources

Paths are relative to the downloadable SDK. Look under the obj directory. Changes have been made relative to all NEXT releases.


  • wchar_t is not different across architectures. No specific definition was found. Verifying the current definition was not possible.
  • nlink_t is not different across architectures.
  • blksize_t is not different across architectures.
  • ssizet_t had a wrong definition. Other _t-terminated types had similar issues. Those will not be further repeated in this list.
  • A number of types did not exist in the SDK. They exist in vendored libc implementations. These are not part of the SDK. They can be found in cs.opensource.google. This includes suffixed offset types. These are omitted from further mention.

sysroot/include/bits/alltypes.h


  • stat had a mismatched definition.

    sysroot/include/bits/stat.h

  • glob_t had a mismatched definition.

    sysroot/include/glob.h


  • signal.h types often had a mismatched definition. This header file appears later on in this source list. They refer to different paths. They contain different definitions.
  • Affected types include:
    • siginfo_t.
    • sigevent.
    • sigaction.
  • There was trouble with constants. SIG_DFL and others are function pointers. They are cast to function pointers from integers. They are sometimes NULL. This is not allowed in Rust. I have wrapped them in Option. They are all None now. They should not all be None. Transmutation from a pointer without provenance to a function pointer is required. This causes compile-time errors.

sysroot/include/signal.h


  • stat64 doesn't exist.
  • ipc_perm doesn't exist.
  • epoll_data doesn't exist. Deprecation lints here keep popping up. I've attempted to silence them. My attempts have been futile.
  • epoll_event doesn't exist.
  • ff_effect doesn't exist.
  • termios2 doesn't exist.
  • sysinfo doesn't exist.
  • mq_attr doesn't exist.
  • sockaddr_nl doesn't exist.
  • RLIM_SAVED_MAX doesn't exist.
  • RLIM_SAVED_CUR doesn't exist.
  • RLIM_INFINITY doesn't exist.
  • RLIMIT_RTTIME doesn't exist.
  • RLIMIT_NLIMITS doesn't exist.

There were conditional checks against 32-bit targets. Rust does not support 32-bit Fuchsia targets. The Fuchsia project does not support 32-bit machine word targets.


There was an oddity with pthread.h types. They were defined with a single field. This field sometimes had size equivalent to the sum of upstream fields. This has been replaced with the real fields. This has also fixed some size and alignment mismatches.

This has required changes in macros. An attempt has been made to fit the POSIX definitions. This means expanding static initializers to { 0 }. The new type definitions get all their fields zeroed. Some are made into null pointers. Should they be made into Option::Nones? They are not function pointer fields.

sysroot/include/pthread.h


Macros needed fixing. Their definition did not return a value. But a value was returned upstream. Some types needed small fixes.

sysroot/include/sched.h


  • m_context had a mismatched definition. Some modules didn't have a definition.
  • u_context had a mismatched definition. Some modules didn't have a definition.

sysroot/include/bits/signal.h

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget); especially relevant for platforms that may not be checked in CI

@rustbot label +stable-nominated

@dybucc dybucc force-pushed the fuchsia-bit-width-transition branch 2 times, most recently from 399a0a5 to cc9e351 Compare May 31, 2026 14:59
@dybucc dybucc force-pushed the fuchsia-bit-width-transition branch from cc9e351 to ddbf270 Compare June 4, 2026 07:05
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fuchsia-bit-width-transition branch from ddbf270 to 3783462 Compare June 9, 2026 07:14
@rustbot

This comment has been minimized.

@dybucc

dybucc commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

CI actually passes. There seems to be an issue with a glob import that is not used, but this has not
been changed in the patch (it's not even part of it, for that matter.) For some reason, rebasing
onto main with dependabot updates has ended up with a warning across all of my open PRs due to
that one (now apparently unused) import.

@rustbot rustbot added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Jun 9, 2026
@dybucc dybucc force-pushed the fuchsia-bit-width-transition branch from 3783462 to 53b65df Compare June 15, 2026 15:18
@rustbot

This comment has been minimized.

@tgross35

Copy link
Copy Markdown
Contributor

@rustbot blocked
@SnoozeThis wait 2 months -> remove label S-blocked, add label S-waiting-on-review

Like other deprecations, holding off until we can actually give the users an alternative.

@SnoozeThis

Copy link
Copy Markdown

(https://snoozeth.is/db3wDy9dFKA) I will wait until Wed, 19 Aug 2026 08:31:22 UTC and then add label S-waiting-on-review and remove label S-blocked.

@rustbot claim.

@dybucc dybucc force-pushed the fuchsia-bit-width-transition branch from 53b65df to b8d548c Compare June 21, 2026 16:24
@rustbot

This comment has been minimized.

@dybucc

dybucc commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

There's some problems in Fuchsia. Each vendored libc implementation has a different implementation. Sometimes they can be unified. Other times it's not possible. An example of the latter is stat. It resolves to different padding fields.

Should I also expose cfgs for each libc implementation?

@dybucc dybucc force-pushed the fuchsia-bit-width-transition branch from 5d7d0ae to 48d5e6a Compare June 22, 2026 06:47
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fuchsia-bit-width-transition branch 4 times, most recently from 66e4bed to dd07b99 Compare June 22, 2026 15:09
@dybucc dybucc changed the title refactor: deprecate off64_t type in Fuchsia fuchsia: clean up module Jun 22, 2026
@dybucc dybucc force-pushed the fuchsia-bit-width-transition branch 3 times, most recently from 70bef1c to 48d1e3d Compare June 22, 2026 15:57
@dybucc dybucc force-pushed the fuchsia-bit-width-transition branch 4 times, most recently from 416f276 to 0b8b2e6 Compare June 24, 2026 11:43
@rustbot

This comment has been minimized.

@dybucc dybucc force-pushed the fuchsia-bit-width-transition branch 4 times, most recently from 35c2504 to 29b5331 Compare June 24, 2026 12:13
@dybucc dybucc force-pushed the fuchsia-bit-width-transition branch from 29b5331 to 2b8b9da Compare June 25, 2026 07:29
@rustbot

This comment has been minimized.

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For any of the commits where I said LGTM, if you want to split them to a separate PR I'd be happy to apply them now to thin down how much is in this PR.

View changes since this review

Comment thread src/fuchsia/riscv64.rs

// From psABI Calling Convention for RV64
pub type __u64 = c_ulonglong;
pub type wchar_t = i32;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Commit "fuchsia: mirror type aliases": it looks like wchar_t was i32 on rv64 and x86, but u32 on aarch64 so they probably shouldn't be combined

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair. But there's something to be noted here. wchar_t is always defined in terms of __WCHAR_TYPE__. This type does not seem to appear anywhere in the Fuchsia tree [1]. I haven't had a way of verifying if the current definitions are correct.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That one comes from the compiler, search for __WCHAR_TYPE__ at https://c.godbolt.org/z/efjeK48j5. So I believe the existing definitions are correct.

Comment thread src/fuchsia/mod.rs Outdated
Comment thread src/fuchsia/mod.rs
Comment on lines +1032 to +1035
pub union fpos_t {
__opaque: [c_char; 16],
__align: c_double,
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Commit "fuchsia: fill in definition of fpos_t": LGTM @ d8710c0.

Comment thread src/fuchsia/aarch64.rs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Commit "fuchsia: deprecate nonexistent types": LGTM @ 9ace3f9

Comment thread src/fuchsia/mod.rs Outdated
Comment thread src/fuchsia/mod.rs
Comment thread src/fuchsia/mod.rs Outdated
Comment thread src/fuchsia/mod.rs
Comment on lines -3146 to 3144
pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> () {
let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
cpuset.bits[idx] |= 1 << offset;
()
pub fn CPU_SET(cpu: usize, cpuset: &mut cpu_set_t) -> c_ulonglong {
(cpu / 8 >= size_of::<crate::cpu_set_t>())
.then_some(0)
.unwrap_or_else(|| {
let c = &mut cpuset.__bits[cpu / 8 / size_of::<c_long>()];
*c |= 1 << (cpu % (8 * size_of::<c_long>()));

*c
})
}

pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> () {
let size_in_bits = 8 * size_of_val(&cpuset.bits[0]); // 32, 64 etc
let (idx, offset) = (cpu / size_in_bits, cpu % size_in_bits);
cpuset.bits[idx] &= !(1 << offset);
()
pub fn CPU_CLR(cpu: usize, cpuset: &mut cpu_set_t) -> c_ulonglong {
(cpu / 8 >= size_of::<crate::cpu_set_t>())
.then_some(0)
.unwrap_or_else(|| {
let c = &mut cpuset.__bits[cpu / 8 / size_of::<c_long>()];
*c &= !(1 << (cpu % (8 * size_of::<c_long>())));

*c
})
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think these are supposed to return values, or at least that's more of an implementation detail than something we need to show. Per https://man7.org/linux/man-pages/man3/CPU_SET.3.html they're treated as void functions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread src/fuchsia/mod.rs Outdated
Comment thread src/fuchsia/aarch64.rs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Commit "fuchsia: fix bits/signal.h types": LGTM @ 33d311a, but should wait on a maintainer to test ideally.

Note: when you link on codesearch, use l-r or links->commit to get a permalink in case sources move around.

dybucc added 2 commits June 26, 2026 11:58
Fixes `fd_set`'s array field. The size was wrong [1]. Now unused
constants have been removed. The PR has been separated from the commit
fixing miscellaneous records.

[1]: https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/sys/select.h;l=23-25
Mirror type aliases. They were previously only equivalent. This changes
them to using C types.

Remove architecture-specific definitions. They were the same.
@dybucc dybucc force-pushed the fuchsia-bit-width-transition branch from 2b8b9da to fda5b07 Compare June 26, 2026 10:13
@rustbot

rustbot commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

dybucc added 3 commits June 26, 2026 12:14
Mirror constants. They were previously equivalent.
Fills in the pending definition. It's opaque in other platforms. It's
public in the Fuchsia headers [1]. Solves a `FIXME`.

[1]: https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/stdio.h;l=47-50
Remove nonexistent types. They are not part of the Fuchsia SDK.

Replace `off64_t` in two routines. It's now `off_t`. `off64_t` has never
existed in Fuchsia.
@dybucc dybucc force-pushed the fuchsia-bit-width-transition branch 6 times, most recently from 4dd1622 to 15e946a Compare June 26, 2026 11:20
dybucc added 3 commits June 26, 2026 13:30
Remove uses of 32-bit target conditional compilation. Fuchsia does not
support 32-bit targets [1]. This is unnecessary.

Fix missing fields in records. No particular header file is targetted.
All wrong records have been fixed. c.f. all headers under
`sysroot/include` in the SDK.

Fix `cpu_set_t` macros [2]. They were wrongly defined. They neither
returned the right values.

[1]: https://fuchsia.dev/fuchsia-src/contribute/governance/rfcs/0111_fuchsia_hardware_specifications#required_64-bit_cpu_and_platform
[2]: https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/sched.h
Fix definition of types in x86_64. `mcontext_t` provided opaque
field. `ucontext_t` had a slightly wrong definition. New records have
been introduced. They are particular to `mcontext_t`.

Add definitions in AArch64 and RISC-V64. They were missing. They are
different for all three target architectures.

These are declared in [1].

[1]: https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/bits/signal.h
Remove opaque types. Replace with proper fields.

Remove conditional defintion for 32-bit targets. Fuchsia has no 32-bit
targets.

Static initializers needed modification. They are specified as `{ 0 }`
in POSIX for C. The new definition replicates that. It zeroes/nullifies
the new fields. Constants were used to initialize the previous opaque
array. These have been deprecated.

These are declared in [1].

[1]: https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/include/pthread.h
@dybucc

dybucc commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants