@@ -16,7 +16,7 @@ use object::write::{
1616} ;
1717use object:: {
1818 RelocationEncoding , RelocationFlags , RelocationKind , SectionFlags , SectionKind , SymbolFlags ,
19- SymbolKind , SymbolScope ,
19+ SymbolKind , SymbolScope , elf ,
2020} ;
2121use std:: collections:: HashMap ;
2222use std:: collections:: hash_map:: Entry ;
@@ -458,12 +458,20 @@ impl Module for ObjectModule {
458458 let section = self . object . section_mut ( section) ;
459459 match & mut section. flags {
460460 SectionFlags :: None => {
461+ // Explicitly specify default flags as SectionFlags::Elf overwrites them
462+ let sh_flags = if decl. tls {
463+ elf:: SHF_ALLOC | elf:: SHF_WRITE | elf:: SHF_TLS
464+ } else if decl. writable || !relocs. is_empty ( ) {
465+ elf:: SHF_ALLOC | elf:: SHF_WRITE
466+ } else {
467+ elf:: SHF_ALLOC
468+ } ;
461469 section. flags = SectionFlags :: Elf {
462- sh_flags : object :: elf:: SHF_GNU_RETAIN . into ( ) ,
470+ sh_flags : u64 :: from ( sh_flags | elf:: SHF_GNU_RETAIN ) ,
463471 }
464472 }
465473 SectionFlags :: Elf { sh_flags } => {
466- * sh_flags |= u64:: from ( object :: elf:: SHF_GNU_RETAIN )
474+ * sh_flags |= u64:: from ( elf:: SHF_GNU_RETAIN )
467475 }
468476 _ => unreachable ! ( ) ,
469477 }
@@ -472,8 +480,13 @@ impl Module for ObjectModule {
472480 object:: BinaryFormat :: MachO => {
473481 let symbol = self . object . symbol_mut ( symbol) ;
474482 assert ! ( matches!( symbol. flags, SymbolFlags :: None ) ) ;
483+ let n_desc = if decl. linkage == Linkage :: Preemptible {
484+ object:: macho:: N_WEAK_DEF
485+ } else {
486+ 0
487+ } ;
475488 symbol. flags = SymbolFlags :: MachO {
476- n_desc : object:: macho:: N_NO_DEAD_STRIP ,
489+ n_desc : n_desc | object:: macho:: N_NO_DEAD_STRIP ,
477490 }
478491 }
479492 _ => unreachable ! ( ) ,
0 commit comments