Skip to content

Commit c4ca87e

Browse files
authored
[yaml2obj] Don't use uninitialized Type (#123274)
Alternative to #123137 With -DMACHINE=EM_NONE, machine specific sections, like SHT_ARM_EXIDX, will fall to parse and set `Type`. This triggers msan on ``` yaml2obj llvm-project/llvm/test/tools/yaml2obj/ELF/mips-abi-flags.yaml -DMACHINE=EM_NONE ```
1 parent e10d551 commit c4ca87e

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

llvm/lib/ObjectYAML/ELFYAML.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ static bool isInteger(StringRef Val) {
15881588

15891589
void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
15901590
IO &IO, std::unique_ptr<ELFYAML::Chunk> &Section) {
1591-
ELFYAML::ELF_SHT Type;
1591+
ELFYAML::ELF_SHT Type = ELF::SHT_NULL;
15921592
StringRef TypeStr;
15931593
if (IO.outputting()) {
15941594
if (auto *S = dyn_cast<ELFYAML::Section>(Section.get()))

llvm/test/tools/yaml2obj/ELF/section-type.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# RUN: yaml2obj %s -o %t
2-
# RUN: llvm-readobj --sections %t | FileCheck %s
1+
# RUN: yaml2obj %s --docnum=1 -o %t1
2+
# RUN: llvm-readobj --sections %t1 | FileCheck %s
33

44
# CHECK: Name: enum
55
# CHECK: Type: SHT_PROGBITS
@@ -25,3 +25,19 @@ Sections:
2525
Type: 0xabcd
2626
- Name: decimal
2727
Type: 1234
28+
29+
## Check that we can handle unknown section and chunk types.
30+
# RUN: not yaml2obj %s --docnum=2 -DSECTION_TYPE=UNKNOWN_TYPE -o %t2 2>&1 | FileCheck %s --check-prefix=UNKNOWN-TYPE
31+
# RUN: not yaml2obj %s --docnum=2 -DSECTION_TYPE=SHT_UNKNOWN_TYPE -o %t2 2>&1 | FileCheck %s --check-prefix=UNKNOWN-TYPE
32+
33+
# UNKNOWN-TYPE: error: invalid hex32 number
34+
35+
--- !ELF
36+
FileHeader:
37+
Class: ELFCLASS64
38+
Data: ELFDATA2LSB
39+
Type: ET_REL
40+
Sections:
41+
- Name: .foo
42+
Type: [[SECTION_TYPE]]
43+

0 commit comments

Comments
 (0)