Skip to content

Commit 10a2ae5

Browse files
authored
read/coff: SymbolKind::Common detection was too broad (#592)
Common symbols should be IMAGE_SYM_CLASS_EXTERNAL. We were also matching on IMAGE_SYM_CLASS_SECTION, which can occur for section symbols in import libraries where the section is defined in another archive member.
1 parent 88554fa commit 10a2ae5

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

crates/examples/testfiles/coff/import_msvc.lib.objdump

+6-6
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ Symbols
8989
1: Symbol { name: "__IMPORT_DESCRIPTOR_test_x64", address: 0, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Linkage, weak: false, flags: None }
9090
2: Symbol { name: ".idata$2", address: 0, size: 0, kind: Section, section: Section(SectionIndex(2)), scope: Compilation, weak: false, flags: None }
9191
3: Symbol { name: ".idata$6", address: 0, size: 0, kind: Data, section: Section(SectionIndex(3)), scope: Compilation, weak: false, flags: None }
92-
4: Symbol { name: ".idata$4", address: 0, size: 0, kind: Section, section: Common, scope: Compilation, weak: false, flags: None }
93-
5: Symbol { name: ".idata$5", address: 0, size: 0, kind: Section, section: Common, scope: Compilation, weak: false, flags: None }
92+
4: Symbol { name: ".idata$4", address: 0, size: 0, kind: Section, section: Undefined, scope: Compilation, weak: false, flags: None }
93+
5: Symbol { name: ".idata$5", address: 0, size: 0, kind: Section, section: Undefined, scope: Compilation, weak: false, flags: None }
9494
6: Symbol { name: "__NULL_IMPORT_DESCRIPTOR", address: 0, size: 0, kind: Data, section: Undefined, scope: Linkage, weak: false, flags: None }
9595
7: Symbol { name: "\u{7f}test_x64_NULL_THUNK_DATA", address: 0, size: 0, kind: Data, section: Undefined, scope: Linkage, weak: false, flags: None }
9696

@@ -166,8 +166,8 @@ Symbols
166166
1: Symbol { name: "__IMPORT_DESCRIPTOR_test_x86", address: 0, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Linkage, weak: false, flags: None }
167167
2: Symbol { name: ".idata$2", address: 0, size: 0, kind: Section, section: Section(SectionIndex(2)), scope: Compilation, weak: false, flags: None }
168168
3: Symbol { name: ".idata$6", address: 0, size: 0, kind: Data, section: Section(SectionIndex(3)), scope: Compilation, weak: false, flags: None }
169-
4: Symbol { name: ".idata$4", address: 0, size: 0, kind: Section, section: Common, scope: Compilation, weak: false, flags: None }
170-
5: Symbol { name: ".idata$5", address: 0, size: 0, kind: Section, section: Common, scope: Compilation, weak: false, flags: None }
169+
4: Symbol { name: ".idata$4", address: 0, size: 0, kind: Section, section: Undefined, scope: Compilation, weak: false, flags: None }
170+
5: Symbol { name: ".idata$5", address: 0, size: 0, kind: Section, section: Undefined, scope: Compilation, weak: false, flags: None }
171171
6: Symbol { name: "__NULL_IMPORT_DESCRIPTOR", address: 0, size: 0, kind: Data, section: Undefined, scope: Linkage, weak: false, flags: None }
172172
7: Symbol { name: "\u{7f}test_x86_NULL_THUNK_DATA", address: 0, size: 0, kind: Data, section: Undefined, scope: Linkage, weak: false, flags: None }
173173

@@ -243,8 +243,8 @@ Symbols
243243
1: Symbol { name: "__IMPORT_DESCRIPTOR_test_arm64ec", address: 0, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Linkage, weak: false, flags: None }
244244
2: Symbol { name: ".idata$2", address: 0, size: 0, kind: Section, section: Section(SectionIndex(2)), scope: Compilation, weak: false, flags: None }
245245
3: Symbol { name: ".idata$6", address: 0, size: 0, kind: Data, section: Section(SectionIndex(3)), scope: Compilation, weak: false, flags: None }
246-
4: Symbol { name: ".idata$4", address: 0, size: 0, kind: Section, section: Common, scope: Compilation, weak: false, flags: None }
247-
5: Symbol { name: ".idata$5", address: 0, size: 0, kind: Section, section: Common, scope: Compilation, weak: false, flags: None }
246+
4: Symbol { name: ".idata$4", address: 0, size: 0, kind: Section, section: Undefined, scope: Compilation, weak: false, flags: None }
247+
5: Symbol { name: ".idata$5", address: 0, size: 0, kind: Section, section: Undefined, scope: Compilation, weak: false, flags: None }
248248
6: Symbol { name: "__NULL_IMPORT_DESCRIPTOR", address: 0, size: 0, kind: Data, section: Undefined, scope: Linkage, weak: false, flags: None }
249249
7: Symbol { name: "\u{7f}test_arm64ec_NULL_THUNK_DATA", address: 0, size: 0, kind: Data, section: Undefined, scope: Linkage, weak: false, flags: None }
250250

src/read/coff/symbol.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,16 @@ impl<'data, 'file, R: ReadRef<'data>, Coff: CoffHeader> ObjectSymbol<'data>
401401
fn section(&self) -> SymbolSection {
402402
match self.symbol.section_number() {
403403
pe::IMAGE_SYM_UNDEFINED => {
404-
if self.symbol.storage_class() == pe::IMAGE_SYM_CLASS_EXTERNAL
405-
&& self.symbol.value() == 0
406-
{
404+
if self.symbol.storage_class() == pe::IMAGE_SYM_CLASS_EXTERNAL {
405+
if self.symbol.value() == 0 {
406+
SymbolSection::Undefined
407+
} else {
408+
SymbolSection::Common
409+
}
410+
} else if self.symbol.storage_class() == pe::IMAGE_SYM_CLASS_SECTION {
407411
SymbolSection::Undefined
408412
} else {
409-
SymbolSection::Common
413+
SymbolSection::Unknown
410414
}
411415
}
412416
pe::IMAGE_SYM_ABSOLUTE => SymbolSection::Absolute,

0 commit comments

Comments
 (0)