[llvm-branch-commits] [yaml2obj] Don't use uninitialized Type (PR #123274)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 16 18:41:36 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-objectyaml

Author: Vitaly Buka (vitalybuka)

<details>
<summary>Changes</summary>

With -DMACHINE=EM_NONE, machine specific
sections, like SHT_ARM_EXIDX, will fall to parse
and set `Type`.


---
Full diff: https://github.com/llvm/llvm-project/pull/123274.diff


1 Files Affected:

- (modified) llvm/lib/ObjectYAML/ELFYAML.cpp (+6-3) 


``````````diff
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index 83e6cf76dd746f..961815392a1348 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 = ELF::ET_NONE;
+  ELFYAML::ELF_SHT Type;
   StringRef TypeStr;
   if (IO.outputting()) {
     if (auto *S = dyn_cast<ELFYAML::Section>(Section.get()))
@@ -1599,9 +1599,12 @@ void MappingTraits<std::unique_ptr<ELFYAML::Chunk>>::mapping(
     // When the Type string does not have a "SHT_" prefix, we know it is not a
     // description of a regular ELF output section.
     TypeStr = getStringValue(IO, "Type");
-    if (TypeStr.starts_with("SHT_") || isInteger(TypeStr))
+    if (TypeStr.starts_with("SHT_") || isInteger(TypeStr)) {
       IO.mapRequired("Type", Type);
-  }
+      if (static_cast<Input&>(IO).error())
+        Type = ELF::SHT_NULL;
+    }
+   }
 
   if (TypeStr == "Fill") {
     assert(!IO.outputting()); // We don't dump fills currently.

``````````

</details>


https://github.com/llvm/llvm-project/pull/123274


More information about the llvm-branch-commits mailing list