Skip to content

[yaml2obj] Don't use uninitialized Type #123274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/lib/ObjectYAML/ELFYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ static bool isInteger(StringRef Val) {

void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
IO &IO, std::unique_ptr<ELFYAML::Chunk> &Section) {
ELFYAML::ELF_SHT Type;
ELFYAML::ELF_SHT Type = ELF::SHT_NULL;
StringRef TypeStr;
if (IO.outputting()) {
if (auto *S = dyn_cast<ELFYAML::Section>(Section.get()))
Expand Down
20 changes: 18 additions & 2 deletions llvm/test/tools/yaml2obj/ELF/section-type.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-readobj --sections %t | FileCheck %s
# RUN: yaml2obj %s --docnum=1 -o %t1
# RUN: llvm-readobj --sections %t1 | FileCheck %s

# CHECK: Name: enum
# CHECK: Type: SHT_PROGBITS
Expand All @@ -25,3 +25,19 @@ Sections:
Type: 0xabcd
- Name: decimal
Type: 1234

## Check that we can handle unknown section and chunk types.
# RUN: not yaml2obj %s --docnum=2 -DSECTION_TYPE=UNKNOWN_TYPE -o %t2 2>&1 | FileCheck %s --check-prefix=UNKNOWN-TYPE
# RUN: not yaml2obj %s --docnum=2 -DSECTION_TYPE=SHT_UNKNOWN_TYPE -o %t2 2>&1 | FileCheck %s --check-prefix=UNKNOWN-TYPE

# UNKNOWN-TYPE: error: invalid hex32 number

--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Sections:
- Name: .foo
Type: [[SECTION_TYPE]]

Loading