@@ -16,7 +16,7 @@ use object::write::{
16
16
} ;
17
17
use object:: {
18
18
RelocationEncoding , RelocationFlags , RelocationKind , SectionFlags , SectionKind , SymbolFlags ,
19
- SymbolKind , SymbolScope ,
19
+ SymbolKind , SymbolScope , elf ,
20
20
} ;
21
21
use std:: collections:: HashMap ;
22
22
use std:: collections:: hash_map:: Entry ;
@@ -458,12 +458,20 @@ impl Module for ObjectModule {
458
458
let section = self . object . section_mut ( section) ;
459
459
match & mut section. flags {
460
460
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
+ } ;
461
469
section. flags = SectionFlags :: Elf {
462
- sh_flags : object :: elf:: SHF_GNU_RETAIN . into ( ) ,
470
+ sh_flags : u64 :: from ( sh_flags | elf:: SHF_GNU_RETAIN ) ,
463
471
}
464
472
}
465
473
SectionFlags :: Elf { sh_flags } => {
466
- * sh_flags |= u64:: from ( object :: elf:: SHF_GNU_RETAIN )
474
+ * sh_flags |= u64:: from ( elf:: SHF_GNU_RETAIN )
467
475
}
468
476
_ => unreachable ! ( ) ,
469
477
}
@@ -472,8 +480,13 @@ impl Module for ObjectModule {
472
480
object:: BinaryFormat :: MachO => {
473
481
let symbol = self . object . symbol_mut ( symbol) ;
474
482
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
+ } ;
475
488
symbol. flags = SymbolFlags :: MachO {
476
- n_desc : object:: macho:: N_NO_DEAD_STRIP ,
489
+ n_desc : n_desc | object:: macho:: N_NO_DEAD_STRIP ,
477
490
}
478
491
}
479
492
_ => unreachable ! ( ) ,
0 commit comments