Skip to content

Commit

Permalink
elf: fix is_import to check st_shndx
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft committed Nov 15, 2024
1 parent b971318 commit 0632e31
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/elf/sym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ pub fn st_visibility(other: u8) -> u8 {

/// Is this information defining an import?
#[inline]
pub fn is_import(info: u8, value: u64) -> bool {
pub fn is_import(info: u8, shndx: u64) -> bool {
let bind = st_bind(info);
bind == STB_GLOBAL && value == 0
(bind == STB_GLOBAL || bind == STB_WEAK) && shndx == SHN_UNDEF as _
}

/// Convenience function to get the &'static str type from the symbols `st_info`.
Expand Down Expand Up @@ -170,8 +170,7 @@ macro_rules! elf_sym_std_impl {
/// Checks whether this `Sym` has `STB_GLOBAL`/`STB_WEAK` bind and a `st_value` of 0
#[inline]
pub fn is_import(&self) -> bool {
let bind = self.st_info >> 4;
(bind == STB_GLOBAL || bind == STB_WEAK) && self.st_value == 0
is_import(self.st_info, self.st_shndx as _)
}
/// Checks whether this `Sym` has type `STT_FUNC`
#[inline]
Expand Down Expand Up @@ -336,6 +335,8 @@ use core::fmt;
use scroll::ctx;
use scroll::ctx::SizeWith;

use super::section_header::SHN_UNDEF;

#[derive(Clone, Copy, PartialEq, Default)]
/// A unified Sym definition - convertible to and from 32-bit and 64-bit variants
pub struct Sym {
Expand All @@ -355,8 +356,7 @@ impl Sym {
/// Checks whether this `Sym` has `STB_GLOBAL`/`STB_WEAK` bind and a `st_value` of 0
#[inline]
pub fn is_import(&self) -> bool {
let bind = self.st_bind();
(bind == STB_GLOBAL || bind == STB_WEAK) && self.st_value == 0
is_import(self.st_info, self.st_shndx as _)
}
/// Checks whether this `Sym` has type `STT_FUNC`
#[inline]
Expand Down

0 comments on commit 0632e31

Please sign in to comment.