[llvm] [llvm-objdump] Error with relevant message when adding invalid notes (PR #90458)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 30 00:52:15 PDT 2024


================
@@ -623,6 +623,58 @@ handleUserSection(const NewSectionInfo &NewSection,
   return F(NewSection.SectionName, Data);
 }
 
+static Error verifyNoteSection(StringRef Name, llvm::endianness E,
+                               ArrayRef<uint8_t> Data) {
+
+  // An ELF note have the following structure:
+  // Name Size: 4 bytes (integer)
+  // Desc Size: 4 bytes (integer)
+  // Type     : 4 bytes
+  // Name     : variable size, padded to a 4 byte boundary
+  // Desc     : variable size, padded to a 4 byte boundary
+
+  if (Data.empty())
+    return Error::success();
+
+  if (Data.size() < 12) {
+    std::string msg;
+    raw_string_ostream(msg)
+        << Name << " data must be either empty or at least 12 bytes long.";
----------------
jh7370 wrote:

Nit: coding standards say that errors shouldn't end in ".". Same applies below.

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


More information about the llvm-commits mailing list