Skip to content

Fix build with panic="abort"#1038

Merged
milyin merged 1 commit intoeclipse-zenoh:mainfrom
anassinator:anassinator/panic-abort
Jun 26, 2025
Merged

Fix build with panic="abort"#1038
milyin merged 1 commit intoeclipse-zenoh:mainfrom
anassinator:anassinator/panic-abort

Conversation

@anassinator
Copy link
Contributor

@anassinator anassinator commented Jun 24, 2025

When building with panic="abort" and std built from source, the size of Mutex<()> varies when wrapped in Option<> or not such that the owned and loaned types have different sizes.

This is specifically due to the poison flag field in Mutex getting compiled out when the panic mode is not set to "unwind". This field's omission pushes the size of the struct to the edge of the 16 byte boundary such that niche optimization no longer has bits to fiddle with after aligning to 8 bytes.

The build fails as follows:

note: evaluation panicked: Size mismatch: type z_loaned_mutex_t has size 16 while type z_owned_mutex_t has size 24

To address, we switch to decl_c_type_inequal! which seems to be safe since we shouldn't be reinterpret_cast()-ing this type and zenoh-cpp doesn't seem to ever reference it.

When building with `panic="abort"` and `std` built from source, the size
of `Mutex<()>` varies when wrapped in `Option<>` or not such that the
owned and loaned types have different sizes.

This is specifically due to the `poison` flag in `Mutex` getting
compiled out when the `panic` mode is not set to `"unwind"`.

The build fails as follows:

```
note: evaluation panicked: Size mismatch: type z_loaned_mutex_t has size 16 while type z_owned_mutex_t has size 24
```

To address, we switch to `decl_c_type_inequal!` which seems to be safe
since we shouldn't be `reinterpret_cast()`-ing this type and `zenoh-cpp`
doesn't seem to ever reference it.
@github-actions
Copy link

PR missing one of the required labels: {'new feature', 'enhancement', 'bug', 'internal', 'breaking-change', 'dependencies', 'documentation'}

@anassinator anassinator marked this pull request as ready for review June 24, 2025 23:41
@anassinator
Copy link
Contributor Author

I want second-hand confirmation that this is fixing it the correct way and that there isn't any implicit assumptions in uses of decl_c_type_inequal!() that we're ignoring here.

@DenisBiryukov91 DenisBiryukov91 added the bug Something isn't working label Jun 25, 2025
@DenisBiryukov91
Copy link
Contributor

I want second-hand confirmation that this is fixing it the correct way and that there isn't any implicit assumptions in uses of decl_c_type_inequal!() that we're ignoring here.

Yes, indeed this looks like a correct fix given that z_xxx_mutex is not used in C++ so requirement to have size_of::() == size_of::<Option>() is irrelevant (at least this is similar to what we do with z_owned_mutex_t in zenoh-pico).

@milyin milyin merged commit 7c76c19 into eclipse-zenoh:main Jun 26, 2025
23 of 24 checks passed
@anassinator anassinator deleted the anassinator/panic-abort branch June 26, 2025 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants