@@ -307,11 +307,12 @@ fn create_elf_raw_dylib_stub(sess: &Session, soname: &str, symbols: &[DllImport]
307
307
stub. reserve_section_headers ( ) ;
308
308
stub. reserve_dynsym ( ) ;
309
309
stub. reserve_dynstr ( ) ;
310
+ let verdef_count = 1 + vers. len ( ) ;
310
311
if !vers. is_empty ( ) {
311
312
stub. reserve_gnu_versym ( ) ;
312
- stub. reserve_gnu_verdef ( 1 + vers . len ( ) , 1 + vers . len ( ) ) ;
313
+ stub. reserve_gnu_verdef ( verdef_count , verdef_count ) ;
313
314
}
314
- stub. reserve_dynamic ( 2 ) ; // DT_SONAME, DT_NULL
315
+ stub. reserve_dynamic ( 3 ) ; // DT_SONAME, DT_VERDEFNUM , DT_NULL
315
316
316
317
// First write the ELF header with the arch information.
317
318
let e_machine = match ( arch, sub_arch) {
@@ -443,9 +444,13 @@ fn create_elf_raw_dylib_stub(sess: &Session, soname: &str, symbols: &[DllImport]
443
444
// .dynamic
444
445
// the DT_SONAME will be used by the linker to populate DT_NEEDED
445
446
// which the loader uses to find the library.
446
- // DT_NULL terminates the .dynamic table.
447
447
stub. write_align_dynamic ( ) ;
448
448
stub. write_dynamic_string ( elf:: DT_SONAME , soname) ;
449
+ // LSB section "2.7. Symbol Versioning" requires `DT_VERDEFNUM` to be reliable.
450
+ if verdef_count > 1 {
451
+ stub. write_dynamic ( elf:: DT_VERDEFNUM , verdef_count as u64 ) ;
452
+ }
453
+ // DT_NULL terminates the .dynamic table.
449
454
stub. write_dynamic ( elf:: DT_NULL , 0 ) ;
450
455
451
456
stub_buf
0 commit comments