Skip to content

Commit 26635c5

Browse files
committed
read/elf: exclude zero sized STT_NOTYPE symbols from is_definitions
These are generally markers, not definitions. In particular, this excludes ARM mapping symbols ('$*').
1 parent 151faf5 commit 26635c5

File tree

4 files changed

+9
-43
lines changed

4 files changed

+9
-43
lines changed

Diff for: crates/examples/testfiles/elf/base-aarch64.o.objdump

-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,4 @@ Dynamic symbols
4040
Dynamic relocations
4141

4242
Symbol map
43-
0x0 "$d"
44-
0x0 "$x"
4543
0x0 "main"

Diff for: crates/examples/testfiles/elf/base-aarch64.objdump

+1-30
Original file line numberDiff line numberDiff line change
@@ -163,52 +163,23 @@ Import { library: "", name: "_ITM_registerTMCloneTable" }
163163
Import { library: "", name: "printf" }
164164

165165
Symbol map
166-
0x21c "$d"
167-
0x598 "$x"
168166
0x598 "_init"
169-
0x5a4 "$x"
170-
0x5b0 "$x"
171-
0x620 "$x"
172167
0x620 "_start"
173-
0x658 "$x"
174168
0x658 "call_weak_fn"
175-
0x670 "$x"
176169
0x670 "deregister_tm_clones"
177170
0x6a0 "register_tm_clones"
178171
0x6d8 "__do_global_dtors_aux"
179172
0x720 "frame_dummy"
180-
0x724 "$x"
181173
0x724 "main"
182-
0x748 "$x"
183174
0x748 "__libc_csu_init"
184175
0x7c8 "__libc_csu_fini"
185-
0x7cc "$x"
186176
0x7cc "_fini"
187-
0x7d4 "$x"
188177
0x7e0 "_IO_stdin_used"
189-
0x7e0 "$d"
190-
0x7e8 "$d"
191-
0x7f8 "$d"
192178
0x7f8 "__FRAME_END__"
193-
0x10d80 "$d"
194-
0x10d80 "__init_array_start"
195179
0x10d80 "__frame_dummy_init_array_entry"
196-
0x10d88 "$d"
197180
0x10d88 "__do_global_dtors_aux_fini_array_entry"
198-
0x10d88 "__init_array_end"
199181
0x10d90 "_DYNAMIC"
200182
0x10fc0 "_GLOBAL_OFFSET_TABLE_"
201-
0x11000 "__data_start"
202-
0x11000 "data_start"
203183
0x11008 "__dso_handle"
204-
0x11008 "$d"
205-
0x11010 "_edata"
206-
0x11010 "$d"
207-
0x11010 "__bss_start__"
208-
0x11010 "__bss_start"
209-
0x11010 "__TMC_END__"
210184
0x11010 "completed.8500"
211-
0x11018 "__bss_end__"
212-
0x11018 "_bss_end__"
213-
0x11018 "_end"
214-
0x11018 "__end__"
185+
0x11010 "__TMC_END__"

Diff for: crates/examples/testfiles/elf/base.objdump

-8
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,11 @@ Symbol map
143143
0x710 "__libc_csu_fini"
144144
0x714 "_fini"
145145
0x720 "_IO_stdin_used"
146-
0x734 "__GNU_EH_FRAME_HDR"
147146
0x874 "__FRAME_END__"
148147
0x200da8 "__frame_dummy_init_array_entry"
149-
0x200da8 "__init_array_start"
150148
0x200db0 "__do_global_dtors_aux_fini_array_entry"
151-
0x200db0 "__init_array_end"
152149
0x200db8 "_DYNAMIC"
153150
0x200fb8 "_GLOBAL_OFFSET_TABLE_"
154-
0x201000 "__data_start"
155-
0x201000 "data_start"
156151
0x201008 "__dso_handle"
157-
0x201010 "_edata"
158-
0x201010 "__bss_start"
159152
0x201010 "completed.7698"
160153
0x201010 "__TMC_END__"
161-
0x201018 "_end"

Diff for: src/read/elf/symbol.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,14 @@ pub trait Sym: Debug + Pod {
478478

479479
/// Return true if the symbol is a definition of a function or data object.
480480
fn is_definition(&self, endian: Self::Endian) -> bool {
481-
let st_type = self.st_type();
482-
(st_type == elf::STT_NOTYPE || st_type == elf::STT_FUNC || st_type == elf::STT_OBJECT)
483-
&& self.st_shndx(endian) != elf::SHN_UNDEF
481+
if self.st_shndx(endian) == elf::SHN_UNDEF {
482+
return false;
483+
}
484+
match self.st_type() {
485+
elf::STT_NOTYPE => self.st_size(endian).into() != 0,
486+
elf::STT_FUNC | elf::STT_OBJECT => true,
487+
_ => false,
488+
}
484489
}
485490
}
486491

0 commit comments

Comments
 (0)