PEL: Maybe shrink the AdditionalData UD section

If the UserData section created from the AdditionalData event log
property would run the PEL over 16KB, shrink that section enough to make
the PEL fit into 16KB.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ie56f61c9c2eb4a264613388464450d595533bc8c
diff --git a/extensions/openpower-pels/pel.cpp b/extensions/openpower-pels/pel.cpp
index 13e94d0..167d28a 100644
--- a/extensions/openpower-pels/pel.cpp
+++ b/extensions/openpower-pels/pel.cpp
@@ -62,12 +62,26 @@
     auto ud = util::makeSysInfoUserDataSection(additionalData, dataIface);
     _optionalSections.push_back(std::move(ud));
 
+    // Create a UserData section from AdditionalData.
     if (!additionalData.empty())
     {
         ud = util::makeADUserDataSection(additionalData);
 
-        // To be safe, check there isn't too much data
-        if (size() + ud->header().size <= _maxPELSize)
+        // Shrink the section if necessary.
+        if (size() + ud->header().size > _maxPELSize)
+        {
+            if (ud->shrink(_maxPELSize - size()))
+            {
+                _optionalSections.push_back(std::move(ud));
+            }
+            else
+            {
+                log<level::WARNING>(
+                    "Dropping AdditionalData UserData section",
+                    entry("SECTION_SIZE=%d\n", ud->header().size));
+            }
+        }
+        else
         {
             _optionalSections.push_back(std::move(ud));
         }