[llvm] c4ca87e - [yaml2obj] Don't use uninitialized Type (#123274)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 23 12:22:21 PST 2025


Author: Vitaly Buka
Date: 2025-01-23T12:22:16-08:00
New Revision: c4ca87ee78fa4f1978e018e6e3a260ac9aea399d

URL: https://github.com/llvm/llvm-project/commit/c4ca87ee78fa4f1978e018e6e3a260ac9aea399d
DIFF: https://github.com/llvm/llvm-project/commit/c4ca87ee78fa4f1978e018e6e3a260ac9aea399d.diff

LOG: [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
```

Added: 
    

Modified: 
    llvm/lib/ObjectYAML/ELFYAML.cpp
    llvm/test/tools/yaml2obj/ELF/section-type.yaml

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index 24f426a9aa1f7c..539834fc8d4dbf 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -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()))

diff  --git a/llvm/test/tools/yaml2obj/ELF/section-type.yaml b/llvm/test/tools/yaml2obj/ELF/section-type.yaml
index ad2edd942cc2aa..6f5f42aceafedc 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]]
+


        


More information about the llvm-commits mailing list