Skip to content

Commit

Permalink
read/elf: exclude zero sized STT_NOTYPE symbols from is_definition
Browse files Browse the repository at this point in the history
These are generally markers, not definitions.
In particular, this excludes ARM mapping symbols ('$*').

Additionally, since we are treating non-zero sized STT_NOTYPE
symbols as definitions, that means they are not SymbolKind::Label.
  • Loading branch information
philipc committed Nov 27, 2023
1 parent ff3fecb commit e95959c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 43 deletions.
2 changes: 0 additions & 2 deletions crates/examples/testfiles/elf/base-aarch64.o.objdump
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,4 @@ Dynamic symbols
Dynamic relocations

Symbol map
0x0 "$d"
0x0 "$x"
0x0 "main"
29 changes: 0 additions & 29 deletions crates/examples/testfiles/elf/base-aarch64.objdump
Original file line number Diff line number Diff line change
Expand Up @@ -163,52 +163,23 @@ Import { library: "", name: "_ITM_registerTMCloneTable" }
Import { library: "", name: "printf" }

Symbol map
0x21c "$d"
0x598 "$x"
0x598 "_init"
0x5a4 "$x"
0x5b0 "$x"
0x620 "$x"
0x620 "_start"
0x658 "$x"
0x658 "call_weak_fn"
0x670 "$x"
0x670 "deregister_tm_clones"
0x6a0 "register_tm_clones"
0x6d8 "__do_global_dtors_aux"
0x720 "frame_dummy"
0x724 "$x"
0x724 "main"
0x748 "$x"
0x748 "__libc_csu_init"
0x7c8 "__libc_csu_fini"
0x7cc "$x"
0x7cc "_fini"
0x7d4 "$x"
0x7e0 "$d"
0x7e0 "_IO_stdin_used"
0x7e8 "$d"
0x7f8 "$d"
0x7f8 "__FRAME_END__"
0x10d80 "$d"
0x10d80 "__frame_dummy_init_array_entry"
0x10d80 "__init_array_start"
0x10d88 "$d"
0x10d88 "__do_global_dtors_aux_fini_array_entry"
0x10d88 "__init_array_end"
0x10d90 "_DYNAMIC"
0x10fc0 "_GLOBAL_OFFSET_TABLE_"
0x11000 "data_start"
0x11000 "__data_start"
0x11008 "$d"
0x11008 "__dso_handle"
0x11010 "completed.8500"
0x11010 "$d"
0x11010 "__bss_start__"
0x11010 "_edata"
0x11010 "__bss_start"
0x11010 "__TMC_END__"
0x11018 "_bss_end__"
0x11018 "__bss_end__"
0x11018 "_end"
0x11018 "__end__"
8 changes: 0 additions & 8 deletions crates/examples/testfiles/elf/base.objdump
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,11 @@ Symbol map
0x710 "__libc_csu_fini"
0x714 "_fini"
0x720 "_IO_stdin_used"
0x734 "__GNU_EH_FRAME_HDR"
0x874 "__FRAME_END__"
0x200da8 "__frame_dummy_init_array_entry"
0x200da8 "__init_array_start"
0x200db0 "__do_global_dtors_aux_fini_array_entry"
0x200db0 "__init_array_end"
0x200db8 "_DYNAMIC"
0x200fb8 "_GLOBAL_OFFSET_TABLE_"
0x201000 "data_start"
0x201000 "__data_start"
0x201008 "__dso_handle"
0x201010 "completed.7698"
0x201010 "_edata"
0x201010 "__bss_start"
0x201010 "__TMC_END__"
0x201018 "_end"
14 changes: 10 additions & 4 deletions src/read/elf/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ impl<'data, 'file, Elf: FileHeader, R: ReadRef<'data>> ObjectSymbol<'data>
fn kind(&self) -> SymbolKind {
match self.symbol.st_type() {
elf::STT_NOTYPE if self.index.0 == 0 => SymbolKind::Null,
elf::STT_NOTYPE => SymbolKind::Label,
elf::STT_NOTYPE if self.size() == 0 => SymbolKind::Label,
elf::STT_NOTYPE => SymbolKind::Unknown,
elf::STT_OBJECT | elf::STT_COMMON => SymbolKind::Data,
elf::STT_FUNC | elf::STT_GNU_IFUNC => SymbolKind::Text,
elf::STT_SECTION => SymbolKind::Section,
Expand Down Expand Up @@ -478,9 +479,14 @@ pub trait Sym: Debug + Pod {

/// Return true if the symbol is a definition of a function or data object.
fn is_definition(&self, endian: Self::Endian) -> bool {
let st_type = self.st_type();
(st_type == elf::STT_NOTYPE || st_type == elf::STT_FUNC || st_type == elf::STT_OBJECT)
&& self.st_shndx(endian) != elf::SHN_UNDEF
if self.st_shndx(endian) == elf::SHN_UNDEF {
return false;
}
match self.st_type() {
elf::STT_NOTYPE => self.st_size(endian).into() != 0,
elf::STT_FUNC | elf::STT_OBJECT => true,
_ => false,
}
}
}

Expand Down

0 comments on commit e95959c

Please sign in to comment.