[PATCH] D72695: [MachO] Add a test for detecting reserved unit length.

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 02:00:48 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGfcc08aa835de: [MachO] Add a test for detecting reserved unit length. (authored by ikudrin).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72695/new/

https://reviews.llvm.org/D72695

Files:
  lld/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp


Index: lld/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
===================================================================
--- lld/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
+++ lld/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
@@ -97,3 +97,41 @@
   EXPECT_TRUE(atom4->name().equals("_undef"));
   EXPECT_EQ(lld::Atom::definitionUndefined, atom4->definition());
 }
+
+TEST(ToAtomsTest, reservedUnitLength) {
+  static const uint8_t debugInfoWithReservedLengthContent[12] = {
+      0xf0, 0xff, 0xff, 0xff // Reserved length value
+  };
+  static const uint8_t debugInfoWithValidBigLengthContent[12] = {
+      0xef, 0xff, 0xff, 0xff, // The maximum valid length value for DWARF32
+      0x00, 0x00              // Wrong version
+  };
+  static const uint8_t debugAbbrevDummyContent[] = {0x00};
+
+  NormalizedFile fReservedLength, fValidBigLength;
+  fReservedLength.arch = lld::MachOLinkingContext::arch_x86;
+  fValidBigLength.arch = lld::MachOLinkingContext::arch_x86;
+  Section section;
+  section.segmentName = "__DWARF";
+  section.sectionName = "__debug_info";
+  section.content = llvm::makeArrayRef(debugInfoWithReservedLengthContent);
+  fReservedLength.sections.push_back(section);
+  section.content = llvm::makeArrayRef(debugInfoWithValidBigLengthContent);
+  fValidBigLength.sections.push_back(section);
+  section.sectionName = "__debug_abbrev";
+  section.content = llvm::makeArrayRef(debugAbbrevDummyContent);
+  fReservedLength.sections.push_back(section);
+  fValidBigLength.sections.push_back(section);
+
+  auto resultReservedLength = normalizedToAtoms(fReservedLength, "foo", false);
+  auto resultValidBigLength = normalizedToAtoms(fValidBigLength, "foo", false);
+
+  // Both cases should return errors, but different.
+  ASSERT_FALSE(resultReservedLength);
+  ASSERT_FALSE(resultValidBigLength);
+
+  EXPECT_STREQ("Malformed DWARF in foo",
+               toString(resultReservedLength.takeError()).c_str());
+  EXPECT_STREQ("Unsupported DWARF version in foo",
+               toString(resultValidBigLength.takeError()).c_str());
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72695.238196.patch
Type: text/x-patch
Size: 2097 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200115/b67d3c3e/attachment.bin>


More information about the llvm-commits mailing list