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

Fix tests on other platforms. #17

Merged
merged 4 commits into from
Dec 7, 2024
Merged

Fix tests on other platforms. #17

merged 4 commits into from
Dec 7, 2024

Conversation

Robo210
Copy link
Collaborator

@Robo210 Robo210 commented Dec 6, 2024

The tests for the static metadata need to detect when they are running on an unsupported platform and pass gracefully.

Add #[used] attribute to the statics so the linker doesn't remove them.

Add some comments.

The tests for the static metadata need to detect when they are running on an unsupported platform and pass gracefully.

Add #[used] attribute to the statics so the linker doesn't remove them.

Add some comments.
@Robo210 Robo210 requested a review from a team as a code owner December 6, 2024 10:50
src/lib.rs Outdated
static ETW_META: $crate::_details::EventMetadata = $crate::_details::EventMetadata{
kw: $kw,
// TODO: Hash the callsite identity at compile time, or get Identifier to implement Ord
identity: tracing_core::identify_callsite!(&CALLSITE),
event_tag: $tags as u32
};

// These two statics need to be mut to avoid compiler errors about *const EventMetadata not being Sync.
// It's unclear why mut avoids these errors.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is because they want static const to be usable from safe code, so it must follow safe thread rules. static mut is never usable from safe code so thread rules don't have to be checked.

@@ -6,12 +6,14 @@ use tracelogging::*;
use tracelogging_dynamic::EventBuilder;
use tracing_subscriber::registry::{LookupSpan, SpanRef};

// Items within this .rsdata section will be sorted alphabetically, thus the start is named with "0", the end "9", and each metadata "5".
// If these statics aren't mut then everything will silently fail to work.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to match mutability with the variables described in the macro.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why though? By the time the linker gets involved, shouldn't mut/const be gone?

Copy link
Contributor

Choose a reason for hiding this comment

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

mut/const affects where the object gets put into the image. mut variables must go into read/write memory. const variables can go into read-only memory.

idigdoug
idigdoug previously approved these changes Dec 6, 2024
@@ -6,12 +6,14 @@ use tracelogging::*;
use tracelogging_dynamic::EventBuilder;
use tracing_subscriber::registry::{LookupSpan, SpanRef};

// Items within this .rsdata section will be sorted alphabetically, thus the start is named with "0", the end "9", and each metadata "5".
// If these statics aren't mut then everything will silently fail to work.
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to match mutability with the variables described in the macro.

@@ -41,6 +41,9 @@ pub(crate) use tracelogging_dynamic::Guid as native_guid;
#[cfg(target_os = "linux")]
pub(crate) use eventheader::Guid as native_guid;

// Used to detect the noop implementation, for testing purposes
pub(crate) const MAGIC_STATICS_SENTINEL: usize = usize::from_ne_bytes(*b"NO-OPT00");
Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect this to fail to compile for 32-bit. Also, it is not guaranteed that this value will not occur in the wild.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is only used for the no-op case, which should be selected by compiler options. Can we also make the detection of no-op be detected by compiler options rather than by a sentinel? I kinda don't like the sentinel here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I can do that. I was thinking less ifdefs would be better, but I don't really like the sentinel either.

src/lib.rs Outdated
static ETW_META: $crate::_details::EventMetadata = $crate::_details::EventMetadata{
kw: $kw,
// TODO: Hash the callsite identity at compile time, or get Identifier to implement Ord
identity: tracing_core::identify_callsite!(&CALLSITE),
event_tag: $tags as u32
};

// These two statics need to be mut to avoid compiler errors about *const EventMetadata not being Sync.
// It's unclear why mut avoids these errors.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is because they want static const to be usable from safe code, so it must follow safe thread rules. static mut is never usable from safe code so thread rules don't have to be checked.

@Robo210 Robo210 merged commit 515f2d6 into main Dec 7, 2024
3 checks passed
@Robo210 Robo210 deleted the macos2 branch December 7, 2024 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants