Skip to content

Commit d6fa3e1

Browse files
committed
obtain verdefnum from verdef section header
Similarly to #611 Rust's ELF raw-dylibs do not contain the information about verdef count. This goes against LSB, but all the other linkers can handle it, presumably by using `st_info` of`.gnu.version_d` section. I'm not sure if this is the right thing to do, maybe `sh_info` should be used just as a fallback when `.dynamic` doesn't have `DT_VERDEFNUM` tag? On current main `tests/ui/linkage-attr/raw-dylib/elf/glibc-x86_64.rs` fails with: ``` wild: error: Failed to load symbols from `/tmp/rustcnCgdWG/raw-dylibs/lib105m6f543m4qw1t7khnttg751.so` Caused by: Invalid version index 1 ```
1 parent 6ed00da commit d6fa3e1

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

libwild/src/elf.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use object::LittleEndian;
1818
use object::read::elf::CompressionHeader;
1919
use object::read::elf::Crel;
2020
use object::read::elf::CrelIterator;
21-
use object::read::elf::Dyn;
2221
use object::read::elf::FileHeader as _;
2322
use object::read::elf::RelocationSections;
2423
use object::read::elf::SectionHeader as _;
@@ -66,8 +65,8 @@ pub(crate) struct File<'data> {
6665
/// An iterator over the version definitions and the corresponding linked string table index.
6766
pub(crate) verdef: Option<(VerdefIterator<'data>, object::SectionIndex)>,
6867

69-
/// Number of verdef versions according to the dynamic table.
70-
pub(crate) verdefnum: u64,
68+
/// Number of verdef versions according to `sh_info` of `.gnu._version_d` section.
69+
pub(crate) verdefnum: u32,
7170

7271
/// e_flags from the header.
7372
pub(crate) eflags: u32,
@@ -144,10 +143,9 @@ impl<'data> File<'data> {
144143
let mut symbols = SymbolTable::default();
145144
let mut versym: &[Versym] = &[];
146145
let mut verdef = None;
147-
let mut dynamic = None;
148146
let mut verdefnum = 0;
149147

150-
// Find all the sections that we're interested in in a single scan of the section table so
148+
// Find all the sections that we're interested in a single scan of the section table so
151149
// as to avoid multiple scans.
152150
for (section_index, section) in sections.enumerate() {
153151
match SectionType::from_header(section) {
@@ -162,22 +160,12 @@ impl<'data> File<'data> {
162160
}
163161
sht::GNU_VERDEF => {
164162
verdef = section.gnu_verdef(endian, data)?;
165-
}
166-
sht::DYNAMIC => {
167-
dynamic = section.dynamic(endian, data)?;
163+
verdefnum = section.sh_info(endian);
168164
}
169165
_ => {}
170166
}
171167
}
172168

173-
if let Some((dynamic, _)) = dynamic {
174-
for dy in dynamic {
175-
if dy.d_tag(endian) == u64::from(object::elf::DT_VERDEFNUM) {
176-
verdefnum = dy.d_val(endian);
177-
}
178-
}
179-
}
180-
181169
Ok(Self {
182170
arch: architecture,
183171
data,

libwild/src/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5392,9 +5392,9 @@ impl<'data> DynamicLayoutState<'data> {
53925392
resources: &GraphResources<'data, '_>,
53935393
queue: &mut LocalWorkQueue,
53945394
) -> Result {
5395-
let dt_info = DynamicTagValues::read(self.object)?;
5396-
self.symbol_versions_needed = vec![false; dt_info.verdefnum as usize];
5395+
self.symbol_versions_needed = vec![false; self.object.verdefnum as usize];
53975396

5397+
let dt_info = DynamicTagValues::read(self.object)?;
53985398
if let Some(soname) = dt_info.soname {
53995399
self.lib_name = soname;
54005400
}

0 commit comments

Comments
 (0)