diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp index 24f426a9aa1f7..539834fc8d4db 100644 --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -1588,7 +1588,7 @@ static bool isInteger(StringRef Val) { void MappingTraits>::mapping( IO &IO, std::unique_ptr &Section) { - ELFYAML::ELF_SHT Type; + ELFYAML::ELF_SHT Type = ELF::SHT_NULL; StringRef TypeStr; if (IO.outputting()) { if (auto *S = dyn_cast(Section.get())) diff --git a/llvm/test/tools/yaml2obj/ELF/section-type.yaml b/llvm/test/tools/yaml2obj/ELF/section-type.yaml index ad2edd942cc2a..6f5f42aceafed 100644 --- a/llvm/test/tools/yaml2obj/ELF/section-type.yaml +++ b/llvm/test/tools/yaml2obj/ELF/section-type.yaml @@ -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 @@ -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]] +