-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Allow passing Mach-O flags to set_segment_section
#13137
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -434,8 +434,8 @@ impl Module for ObjectModule { | |
| "Custom section not supported for TLS" | ||
| ))); | ||
| } | ||
| let (seg, sec) = &custom_segment_section.as_ref().unwrap(); | ||
| self.object.add_section( | ||
| let (seg, sec, macho_flags) = &custom_segment_section.as_ref().unwrap(); | ||
| let section = self.object.add_section( | ||
| seg.clone().into_bytes(), | ||
| sec.clone().into_bytes(), | ||
| if decl.writable { | ||
|
|
@@ -445,7 +445,22 @@ impl Module for ObjectModule { | |
| } else { | ||
| SectionKind::ReadOnlyDataWithRel | ||
| }, | ||
| ) | ||
| ); | ||
|
|
||
| match self.object.section_flags_mut(section) { | ||
| SectionFlags::MachO { flags } => { | ||
| *flags = *macho_flags; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually shouldn't this be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I considered that, but there are no default flags for (
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would skipping the flag set if macho_flags is 0 makes sense?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could do: let section_type = *macho_flags & SECTION_TYPE;
let section_attributes = *macho_flags & SECTION_ATTRIBUTES;
let current_attributes = (*flags & SECTION_ATTRIBUTES);
*flags = section_type | current_attributes | section_attributes;But I feared that might be confusing too, if I request only Though we should probably have an assert that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opened #13153 for adding a debug assertion instead |
||
| } | ||
| _ => { | ||
| if *macho_flags != 0 { | ||
| return Err(cranelift_module::ModuleError::Backend(anyhow::anyhow!( | ||
| "unsupported Mach-O flags for this platform: {macho_flags:?}" | ||
| ))); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| section | ||
| }; | ||
|
|
||
| if used { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another design for this could be to take:
And then have the
"pure_instructions" -> S_ATTR_PURE_INSTRUCTIONSmappings incranelift-object? What would you prefer?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe directly use
object::write::SectionFlagsand then or those flags with the ones cranelift-object would set by default?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that would introduce a dependency on
objecttocranelift-module?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right this is cranelift-module, not cranelift-object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A third alternative would be:
And do the entire parsing inside
cranelift-object.