[PATCH] D109566: [yaml2obj][XCOFF] write an invalid index for an invalid Section name specified in Symbol

Esme Yi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 9 22:23:25 PDT 2021


Esme created this revision.
Esme added reviewers: jhenderson, shchenz, Higuoxing.
Herald added subscribers: arphaman, hiraditya.
Esme requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is found during testing the error paths in D98003 <https://reviews.llvm.org/D98003>.
See the error case 2 in llvm/test/tools/obj2yaml/XCOFF/invalid.yaml of D98003 <https://reviews.llvm.org/D98003>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109566

Files:
  llvm/lib/ObjectYAML/XCOFFEmitter.cpp


Index: llvm/lib/ObjectYAML/XCOFFEmitter.cpp
===================================================================
--- llvm/lib/ObjectYAML/XCOFFEmitter.cpp
+++ llvm/lib/ObjectYAML/XCOFFEmitter.cpp
@@ -387,8 +387,17 @@
       }
       W.write<uint32_t>(YamlSym.Value);
     }
-    W.write<int16_t>(
-        YamlSym.SectionName.size() ? SectionIndexMap[YamlSym.SectionName] : 0);
+    if (YamlSym.SectionName.size()) {
+      StringRef SymSecName =
+          StringRef(YamlSym.SectionName.data(), YamlSym.SectionName.size());
+      // If the section name specified in the symbol is not a valid member of
+      // SectionIndexMap, write an invalid index.
+      W.write<int16_t>(SectionIndexMap.find(SymSecName) == SectionIndexMap.end()
+                           ? -3
+                           : SectionIndexMap[YamlSym.SectionName]);
+    } else {
+      W.write<int16_t>(0);
+    }
     W.write<uint16_t>(YamlSym.Type);
     W.write<uint8_t>(YamlSym.StorageClass);
     W.write<uint8_t>(YamlSym.NumberOfAuxEntries);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109566.371783.patch
Type: text/x-patch
Size: 1020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210910/0be58a94/attachment.bin>


More information about the llvm-commits mailing list