From 2bdb81df0a09cd51a8b56f397a933464554bed30 Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Tue, 25 Jun 2024 12:50:16 +1000 Subject: [PATCH] Add SectionKind::DebugString (#694) For ELF, DWARF string sections need different flags. --- src/common.rs | 5 +++++ src/write/coff/object.rs | 5 ++++- src/write/elf/object.rs | 4 +++- src/write/macho.rs | 2 +- src/write/xcoff.rs | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/common.rs b/src/common.rs index e1ccfdd2..4327edb0 100644 --- a/src/common.rs +++ b/src/common.rs @@ -203,6 +203,11 @@ pub enum SectionKind { /// /// Example Mach-O sections: `__DWARF/__debug_info` Debug, + /// Debug strings. + /// + /// This is the same as either `Debug` or `OtherString`, depending on the file format. + /// This value is only used in the API for writing files. It is never returned when reading files. + DebugString, /// Information for the linker. /// /// Example COFF sections: `.drectve` diff --git a/src/write/coff/object.rs b/src/write/coff/object.rs index 9d6a167c..f70465f3 100644 --- a/src/write/coff/object.rs +++ b/src/write/coff/object.rs @@ -473,7 +473,10 @@ impl<'a> Object<'a> { | SectionKind::ReadOnlyString => { coff::IMAGE_SCN_CNT_INITIALIZED_DATA | coff::IMAGE_SCN_MEM_READ } - SectionKind::Debug | SectionKind::Other | SectionKind::OtherString => { + SectionKind::Debug + | SectionKind::DebugString + | SectionKind::Other + | SectionKind::OtherString => { coff::IMAGE_SCN_CNT_INITIALIZED_DATA | coff::IMAGE_SCN_MEM_READ | coff::IMAGE_SCN_MEM_DISCARDABLE diff --git a/src/write/elf/object.rs b/src/write/elf/object.rs index f71cb026..2785c51c 100644 --- a/src/write/elf/object.rs +++ b/src/write/elf/object.rs @@ -825,7 +825,9 @@ impl<'a> Object<'a> { SectionKind::ReadOnlyString => { elf::SHF_ALLOC | elf::SHF_STRINGS | elf::SHF_MERGE } - SectionKind::OtherString => elf::SHF_STRINGS | elf::SHF_MERGE, + SectionKind::OtherString | SectionKind::DebugString => { + elf::SHF_STRINGS | elf::SHF_MERGE + } SectionKind::Other | SectionKind::Debug | SectionKind::Metadata diff --git a/src/write/macho.rs b/src/write/macho.rs index 08090b1c..abce7cb6 100644 --- a/src/write/macho.rs +++ b/src/write/macho.rs @@ -633,7 +633,7 @@ impl<'a> Object<'a> { SectionKind::Tls => macho::S_THREAD_LOCAL_REGULAR, SectionKind::UninitializedTls => macho::S_THREAD_LOCAL_ZEROFILL, SectionKind::TlsVariables => macho::S_THREAD_LOCAL_VARIABLES, - SectionKind::Debug => macho::S_ATTR_DEBUG, + SectionKind::Debug | SectionKind::DebugString => macho::S_ATTR_DEBUG, SectionKind::OtherString => macho::S_CSTRING_LITERALS, SectionKind::Other | SectionKind::Linker | SectionKind::Metadata => 0, SectionKind::Note | SectionKind::Unknown | SectionKind::Elf(_) => { diff --git a/src/write/xcoff.rs b/src/write/xcoff.rs index 34689800..5aade24d 100644 --- a/src/write/xcoff.rs +++ b/src/write/xcoff.rs @@ -313,7 +313,7 @@ impl<'a> Object<'a> { SectionKind::Tls => xcoff::STYP_TDATA, SectionKind::UninitializedTls => xcoff::STYP_TBSS, SectionKind::OtherString => xcoff::STYP_INFO, - SectionKind::Debug => xcoff::STYP_DEBUG, + SectionKind::Debug | SectionKind::DebugString => xcoff::STYP_DEBUG, SectionKind::Other | SectionKind::Metadata => 0, SectionKind::Note | SectionKind::Linker