Skip to content

Commit

Permalink
write: Add SectionKind::ReadOnlyDataWithRel
Browse files Browse the repository at this point in the history
  • Loading branch information
afonso360 committed Jan 16, 2023
1 parent aee2f20 commit f71513e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ pub enum SectionKind {
///
/// Example Mach-O sections: `__TEXT/__const`, `__DATA/__const`, `__TEXT/__literal4`
ReadOnlyData,
/// A read only data section with relocations.
///
/// This is the same as either `Data` or `ReadOnlyData`, depending on the file format.
/// This value is only used in the API for writing files. It is never returned when reading files.
ReadOnlyDataWithRel,
/// A loadable string section.
///
/// Example ELF sections: `.rodata.str`
Expand Down
4 changes: 3 additions & 1 deletion src/write/coff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ impl<'a> Object<'a> {
| coff::IMAGE_SCN_MEM_READ
| coff::IMAGE_SCN_MEM_WRITE
}
SectionKind::ReadOnlyData | SectionKind::ReadOnlyString => {
SectionKind::ReadOnlyData
| SectionKind::ReadOnlyDataWithRel
| SectionKind::ReadOnlyString => {
coff::IMAGE_SCN_CNT_INITIALIZED_DATA | coff::IMAGE_SCN_MEM_READ
}
SectionKind::Debug | SectionKind::Other | SectionKind::OtherString => {
Expand Down
8 changes: 6 additions & 2 deletions src/write/elf/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ impl<'a> Object<'a> {
StandardSection::ReadOnlyData | StandardSection::ReadOnlyString => {
(&[], &b".rodata"[..], SectionKind::ReadOnlyData)
}
StandardSection::ReadOnlyDataWithRel => (&[], b".data.rel.ro", SectionKind::Data),
StandardSection::ReadOnlyDataWithRel => {
(&[], b".data.rel.ro", SectionKind::ReadOnlyDataWithRel)
}
StandardSection::UninitializedData => {
(&[], &b".bss"[..], SectionKind::UninitializedData)
}
Expand Down Expand Up @@ -767,7 +769,9 @@ impl<'a> Object<'a> {
} else {
match section.kind {
SectionKind::Text => elf::SHF_ALLOC | elf::SHF_EXECINSTR,
SectionKind::Data => elf::SHF_ALLOC | elf::SHF_WRITE,
SectionKind::Data | SectionKind::ReadOnlyDataWithRel => {
elf::SHF_ALLOC | elf::SHF_WRITE
}
SectionKind::Tls => elf::SHF_ALLOC | elf::SHF_WRITE | elf::SHF_TLS,
SectionKind::UninitializedData => elf::SHF_ALLOC | elf::SHF_WRITE,
SectionKind::UninitializedTls => elf::SHF_ALLOC | elf::SHF_WRITE | elf::SHF_TLS,
Expand Down
10 changes: 6 additions & 4 deletions src/write/macho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ impl<'a> Object<'a> {
StandardSection::ReadOnlyData => {
(&b"__TEXT"[..], &b"__const"[..], SectionKind::ReadOnlyData)
}
StandardSection::ReadOnlyDataWithRel => {
(&b"__DATA"[..], &b"__const"[..], SectionKind::ReadOnlyData)
}
StandardSection::ReadOnlyDataWithRel => (
&b"__DATA"[..],
&b"__const"[..],
SectionKind::ReadOnlyDataWithRel,
),
StandardSection::ReadOnlyString => (
&b"__TEXT"[..],
&b"__cstring"[..],
Expand Down Expand Up @@ -406,7 +408,7 @@ impl<'a> Object<'a> {
macho::S_ATTR_PURE_INSTRUCTIONS | macho::S_ATTR_SOME_INSTRUCTIONS
}
SectionKind::Data => 0,
SectionKind::ReadOnlyData => 0,
SectionKind::ReadOnlyData | SectionKind::ReadOnlyDataWithRel => 0,
SectionKind::ReadOnlyString => macho::S_CSTRING_LITERALS,
SectionKind::UninitializedData | SectionKind::Common => macho::S_ZEROFILL,
SectionKind::Tls => macho::S_THREAD_LOCAL_REGULAR,
Expand Down
5 changes: 2 additions & 3 deletions src/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,8 @@ impl StandardSection {
match self {
StandardSection::Text => SectionKind::Text,
StandardSection::Data => SectionKind::Data,
StandardSection::ReadOnlyData | StandardSection::ReadOnlyDataWithRel => {
SectionKind::ReadOnlyData
}
StandardSection::ReadOnlyData => SectionKind::ReadOnlyData,
StandardSection::ReadOnlyDataWithRel => SectionKind::ReadOnlyDataWithRel,
StandardSection::ReadOnlyString => SectionKind::ReadOnlyString,
StandardSection::UninitializedData => SectionKind::UninitializedData,
StandardSection::Tls => SectionKind::Tls,
Expand Down

0 comments on commit f71513e

Please sign in to comment.