Allow passing Mach-O flags to set_segment_section#13137
Allow passing Mach-O flags to set_segment_section#13137alexcrichton merged 1 commit intobytecodealliance:mainfrom
set_segment_section#13137Conversation
This enables `rustc_codegen_cranelift` to control these.
| /// Object file segment, section and Mach-O flags. | ||
| pub custom_segment_section: Option<(String, String, u32)>, |
There was a problem hiding this comment.
Another design for this could be to take:
segment: String,
section: String,
macho_section_type: String,
macho_section_attributes: Vec<String>,And then have the "pure_instructions" -> S_ATTR_PURE_INSTRUCTIONS mappings in cranelift-object? What would you prefer?
There was a problem hiding this comment.
Maybe directly use object::write::SectionFlags and then or those flags with the ones cranelift-object would set by default?
There was a problem hiding this comment.
But that would introduce a dependency on object to cranelift-module?
There was a problem hiding this comment.
Ah, right this is cranelift-module, not cranelift-object.
There was a problem hiding this comment.
A third alternative would be:
custom_segment_section: Option<String>,And do the entire parsing inside cranelift-object.
cfallin
left a comment
There was a problem hiding this comment.
Looks reasonable to me -- thanks!
|
|
||
| match self.object.section_flags_mut(section) { | ||
| SectionFlags::MachO { flags } => { | ||
| *flags = *macho_flags; |
There was a problem hiding this comment.
Actually shouldn't this be |=? As is this would overwrite the default flags even when no flags are passed.
There was a problem hiding this comment.
I considered that, but there are no default flags for (SectionKind::Data, SectionKind::ReadOnlyData and SectionKind::ReadOnlyDataWithRel), and if there were, it would break if we tried to |= the section type.
There was a problem hiding this comment.
Would skipping the flag set if macho_flags is 0 makes sense?
There was a problem hiding this comment.
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 no_dead_strip, it might be weird if I got other attributes too.
Though we should probably have an assert that *flags is 0.
There was a problem hiding this comment.
I opened #13153 for adding a debug assertion instead
This enables
rustc_codegen_craneliftto control these, see rust-lang/rustc_codegen_cranelift#1648.