Bug 1335294: Add constexpr to data tables under security/ for better codegen on Windows. r=keeler
☠☠ backed out by f985243bb630 ☠ ☠
authorDavid Major <dmajor@mozilla.com>
Wed, 01 Feb 2017 14:59:57 +1300
changeset 331952 b03c9f4ac1b091b5e8e486715b2ca682e7d6151f
parent 331951 adc12dd054ca8c318bd2976a9015e1d43f373c30
child 331953 1d204b903989e82901423d40b8c713cca6791532
push id31291
push usercbook@mozilla.com
push dateWed, 01 Feb 2017 12:14:40 +0000
treeherdermozilla-central@9e7b1041929f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskeeler
bugs1335294
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1335294: Add constexpr to data tables under security/ for better codegen on Windows. r=keeler MozReview-Commit-ID: 3OMBGfLKP9I
security/certverifier/CNNICHashWhitelist.inc
security/certverifier/CTKnownLogs.h
security/certverifier/ExtendedValidation.cpp
security/manager/ssl/RootHashes.inc
security/manager/tools/genHPKPStaticPins.js
security/manager/tools/genRootCAHashes.js
security/manager/tools/getCTKnownLogs.py
security/manager/tools/getHSTSPreloadList.js
security/manager/tools/makeCNNICHashes.js
--- a/security/certverifier/CNNICHashWhitelist.inc
+++ b/security/certverifier/CNNICHashWhitelist.inc
@@ -10,17 +10,17 @@
 // This file may be removed after Sun Feb 02 2020 21:45:13 GMT-0800 (PST)
 
 #define CNNIC_WHITELIST_HASH_LEN 32
 
 struct WhitelistedCNNICHash {
  const uint8_t hash[CNNIC_WHITELIST_HASH_LEN];
 };
 
-static const struct WhitelistedCNNICHash WhitelistedCNNICHashes[] = {
+static constexpr struct WhitelistedCNNICHash WhitelistedCNNICHashes[] = {
   {
     { 0x00, 0xC5, 0x9F, 0x5E, 0xF3, 0xB4, 0x6D, 0xBC, 0xA0, 0xA8, 0xBB, 0xA5, 0x0A, 0x72, 0xD4, 0xE1,
       0x83, 0x9A, 0x94, 0xFB, 0x1A, 0x58, 0x5A, 0xD7, 0x2A, 0x7A, 0xAC, 0x3C, 0x72, 0x56, 0x1F, 0xC0 },
   },
   {
     { 0x02, 0x01, 0x4E, 0x80, 0xF5, 0xC4, 0xF3, 0x8B, 0xA9, 0xD9, 0x04, 0x79, 0x1A, 0x63, 0xF6, 0x4D,
       0x05, 0xF9, 0xE2, 0x03, 0xA1, 0xF1, 0x2B, 0x06, 0xD6, 0x55, 0x94, 0x01, 0x41, 0x0E, 0x73, 0x36 },
   },
--- a/security/certverifier/CTKnownLogs.h
+++ b/security/certverifier/CTKnownLogs.h
@@ -27,17 +27,17 @@ struct CTLogInfo
 };
 
 struct CTLogOperatorInfo
 {
   const char* const name;
   const mozilla::ct::CTLogOperatorId id;
 };
 
-const CTLogInfo kCTLogList[] = {
+constexpr CTLogInfo kCTLogList[] = {
   { "Google 'Pilot' log",
     mozilla::ct::CTLogStatus::Included,
     0, // no disqualification time
     0, // operated by Google
     "\x30\x59\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48"
     "\xce\x3d\x03\x01\x07\x03\x42\x00\x04\x7d\xa8\x4b\x12\x29\x80\xa3\x3d\xad"
     "\xd3\x5a\x77\xb8\xcc\xe2\x88\xb3\xa5\xfd\xf1\xd3\x0c\xcd\x18\x0c\xe8\x41"
     "\x46\xe8\x81\x01\x1b\x15\xe1\x4b\xf1\x1b\x62\xdd\x36\x0a\x08\x18\xba\xed"
@@ -184,17 +184,17 @@ const CTLogInfo kCTLogList[] = {
     "\xce\x3d\x03\x01\x07\x03\x42\x00\x04\x48\xf3\x59\xf3\xf6\x05\x18\xd3\xdb"
     "\xb2\xed\x46\x7e\xcf\xc8\x11\xb5\x57\xb1\xa8\xd6\x4c\xe6\x9f\xb7\x4a\x1a"
     "\x14\x86\x43\xa9\x48\xb0\xcb\x5a\x3f\x3c\x4a\xca\xdf\xc4\x82\x14\x55\x9a"
     "\xf8\xf7\x8e\x40\x55\xdc\xf4\xd2\xaf\xea\x75\x74\xfb\x4e\x7f\x60\x86\x2e"
     "\x51",
     91 }
 };
 
-const CTLogOperatorInfo kCTLogOperatorList[] = {
+constexpr CTLogOperatorInfo kCTLogOperatorList[] = {
   { "Google", 0 },
   { "DigiCert", 1 },
   { "Certly", 2 },
   { "Izenpe", 3 },
   { "Symantec", 4 },
   { "Venafi", 5 },
   { "CNNIC", 7 },
   { "WoSign", 8 },
--- a/security/certverifier/ExtendedValidation.cpp
+++ b/security/certverifier/ExtendedValidation.cpp
@@ -24,17 +24,17 @@ extern mozilla::LazyLogModule gPIPNSSLog
 #define OI(x) { siDEROID, (unsigned char*) x, sizeof x }
 
 struct nsMyTrustedEVInfo
 {
   const char* dotted_oid;
   const char* oid_name; // Set this to null to signal an invalid structure,
                   // (We can't have an empty list, so we'll use a dummy entry)
   SECOidTag oid_tag;
-  const unsigned char ev_root_sha256_fingerprint[SHA256_LENGTH];
+  unsigned char ev_root_sha256_fingerprint[SHA256_LENGTH];
   const char* issuer_base64;
   const char* serial_base64;
 };
 
 // HOWTO enable additional CA root certificates for EV:
 //
 // For each combination of "root certificate" and "policy OID",
 // one entry must be added to the array named myTrustedEVInfos.
--- a/security/manager/ssl/RootHashes.inc
+++ b/security/manager/ssl/RootHashes.inc
@@ -8,17 +8,17 @@
 /*****************************************************************************/
 
 #define HASH_LEN 32
 struct CertAuthorityHash {
  const uint8_t hash[HASH_LEN];
  const int32_t binNumber;
 };
 
-static const struct CertAuthorityHash ROOT_TABLE[] = {
+static constexpr struct CertAuthorityHash ROOT_TABLE[] = {
   {
     /* Entrust_Root_Certification_Authority___EC1 */
     { 0x02, 0xED, 0x0E, 0xB2, 0x8C, 0x14, 0xDA, 0x45, 0x16, 0x5C, 0x56, 0x67, 0x91, 0x70, 0x0D, 0x64,
       0x51, 0xD7, 0xFB, 0x56, 0xF0, 0xB2, 0xAB, 0x1D, 0x3B, 0x8E, 0xB0, 0x70, 0xE5, 0x6E, 0xDF, 0xF5 },
       164 /* Bin Number */
   },
   {
     /* AffirmTrust_Commercial */
--- a/security/manager/tools/genHPKPStaticPins.js
+++ b/security/manager/tools/genHPKPStaticPins.js
@@ -444,48 +444,48 @@ function compareByName(a, b) {
   return a.name.localeCompare(b.name);
 }
 
 function genExpirationTime() {
   let now = new Date();
   let nowMillis = now.getTime();
   let expirationMillis = nowMillis + (PINNING_MINIMUM_REQUIRED_MAX_AGE * 1000);
   let expirationMicros = expirationMillis * 1000;
-  return "static const PRTime kPreloadPKPinsExpirationTime = INT64_C(" +
+  return "static constexpr PRTime kPreloadPKPinsExpirationTime = INT64_C(" +
          expirationMicros + ");\n";
 }
 
 function writeFullPinset(certNameToSKD, certSKDToName, pinset) {
   let prefix = "kPinset_" + pinset.name;
   if (!pinset.sha256_hashes || pinset.sha256_hashes.length == 0) {
     throw new Error(`ERROR: Pinset ${pinset.name} does not contain any hashes`);
   }
   writeFingerprints(certNameToSKD, certSKDToName, pinset.name,
                     pinset.sha256_hashes);
 }
 
 function writeFingerprints(certNameToSKD, certSKDToName, name, hashes) {
   let varPrefix = "kPinset_" + name;
-  writeString("static const char* const " + varPrefix + "_Data[] = {\n");
+  writeString("static constexpr const char* " + varPrefix + "_Data[] = {\n");
   let SKDList = [];
   for (let certName of hashes) {
     if (!(certName in certNameToSKD)) {
       throw new Error(`ERROR: Can't find '${certName}' in certNameToSKD`);
     }
     SKDList.push(certNameToSKD[certName]);
   }
   for (let skd of SKDList.sort()) {
     writeString("  " + nameToAlias(certSKDToName[skd]) + ",\n");
   }
   if (hashes.length == 0) {
     // ANSI C requires that an initialiser list be non-empty.
     writeString("  0\n");
   }
   writeString("};\n");
-  writeString("static const StaticFingerprints " + varPrefix + " = {\n  " +
+  writeString("static constexpr StaticFingerprints " + varPrefix + " = {\n  " +
     "sizeof(" + varPrefix + "_Data) / sizeof(const char*),\n  " + varPrefix +
     "_Data\n};\n\n");
 }
 
 function writeEntry(entry) {
   let printVal = `  { "${entry.name}", `;
   if (entry.include_subdomains) {
     printVal += "true, ";
@@ -520,17 +520,17 @@ function writeEntry(entry) {
   }
   printVal += "&kPinset_" + entry.pins;
   printVal += " },\n";
   writeString(printVal);
 }
 
 function writeDomainList(chromeImportedEntries) {
   writeString("/* Sort hostnames for binary search. */\n");
-  writeString("static const TransportSecurityPreload " +
+  writeString("static constexpr TransportSecurityPreload " +
           "kPublicKeyPinningPreloadList[] = {\n");
   let count = 0;
   let mozillaDomains = {};
   gStaticPins.entries.forEach(function(entry) {
     mozillaDomains[entry.name] = true;
   });
   // For any domain for which we have set pins, exclude them from
   // chromeImportedEntries.
@@ -545,17 +545,17 @@ function writeDomainList(chromeImportedE
   sortedEntries.push.apply(sortedEntries, chromeImportedEntries);
   for (let entry of sortedEntries.sort(compareByName)) {
     count++;
     writeEntry(entry);
   }
   writeString("};\n");
 
   writeString("\n// Pinning Preload List Length = " + count + ";\n");
-  writeString("\nstatic const int32_t kUnknownId = -1;\n");
+  writeString("\nstatic constexpr int32_t kUnknownId = -1;\n");
 }
 
 function writeFile(certNameToSKD, certSKDToName,
                    chromeImportedPinsets, chromeImportedEntries) {
   // Compute used pins from both Chrome's and our pinsets, so we can output
   // them later.
   let usedFingerprints = {};
   let mozillaPins = {};
@@ -573,17 +573,17 @@ function writeFile(certNameToSKD, certSK
   }
 
   writeString(FILE_HEADER);
 
   // Write actual fingerprints.
   Object.keys(usedFingerprints).sort().forEach(function(certName) {
     if (certName) {
       writeString("/* " + certName + " */\n");
-      writeString("static const char " + nameToAlias(certName) + "[] =\n");
+      writeString("static constexpr char " + nameToAlias(certName) + "[] =\n");
       writeString("  \"" + certNameToSKD[certName] + "\";\n");
       writeString("\n");
     }
   });
 
   // Write the pinsets
   writeString(PINSETDEF);
   writeString("/* PreloadedHPKPins.json pinsets */\n");
--- a/security/manager/tools/genRootCAHashes.js
+++ b/security/manager/tools/genRootCAHashes.js
@@ -46,17 +46,17 @@ const FILE_HEADER = "/* This Source Code
 "/*****************************************************************************/\n" +
 "\n" +
 "#define HASH_LEN 32\n";
 
 const FP_PREAMBLE = "struct CertAuthorityHash {\n" +
 " const uint8_t hash[HASH_LEN];\n" +
 " const int32_t binNumber;\n" +
 "};\n\n" +
-"static const struct CertAuthorityHash ROOT_TABLE[] = {\n";
+"static constexpr struct CertAuthorityHash ROOT_TABLE[] = {\n";
 
 const FP_POSTAMBLE = "};\n";
 
 // Helper
 function writeString(fos, string) {
   fos.write(string, string.length);
 }
 
--- a/security/manager/tools/getCTKnownLogs.py
+++ b/security/manager/tools/getCTKnownLogs.py
@@ -56,21 +56,21 @@ struct CTLogInfo
 };
 
 struct CTLogOperatorInfo
 {
   const char* const name;
   const mozilla::ct::CTLogOperatorId id;
 };
 
-const CTLogInfo kCTLogList[] = {
+constexpr CTLogInfo kCTLogList[] = {
 $logs
 };
 
-const CTLogOperatorInfo kCTLogOperatorList[] = {
+constexpr CTLogOperatorInfo kCTLogOperatorList[] = {
 $operators
 };
 
 #endif // $include_guard
 """
 
 
 def get_disqualification_time(time_str):
--- a/security/manager/tools/getHSTSPreloadList.js
+++ b/security/manager/tools/getHSTSPreloadList.js
@@ -297,17 +297,17 @@ function output(sortedStatuses, currentL
     // current list significantly easier when we go to update the list.
     for (let status of includedStatuses) {
       let incSubdomainsBool = (status.forceInclude && status.error != ERROR_NONE
                                ? status.originalIncludeSubdomains
                                : status.includeSubdomains);
       status.finalIncludeSubdomains = incSubdomainsBool;
     }
 
-    writeTo("\nstatic const char kSTSHostTable[] = {\n", fos);
+    writeTo("\nstatic constexpr char kSTSHostTable[] = {\n", fos);
     var indices = {};
     var currentIndex = 0;
     for (let status of includedStatuses) {
       indices[status.name] = currentIndex;
       // Add 1 for the null terminator in C.
       currentIndex += status.name.length + 1;
       // Rebuilding the preload list requires reading the previous preload
       // list.  Write out a comment describing each host prior to writing out
@@ -329,17 +329,17 @@ function output(sortedStatuses, currentL
 
     const PREFIX = "\n" +
       "struct nsSTSPreload\n" +
       "{\n" +
       "  const uint32_t mHostIndex : 31;\n" +
       "  const uint32_t mIncludeSubdomains : 1;\n" +
       "};\n" +
       "\n" +
-      "static const nsSTSPreload kSTSPreloadList[] = {\n";
+      "static constexpr nsSTSPreload kSTSPreloadList[] = {\n";
     const POSTFIX = "};\n";
 
     writeTo(PREFIX, fos);
     for (let status of includedStatuses) {
       writeEntry(status, indices, fos);
     }
     writeTo(POSTFIX, fos);
     FileUtils.closeSafeFileOutputStream(fos);
--- a/security/manager/tools/makeCNNICHashes.js
+++ b/security/manager/tools/makeCNNICHashes.js
@@ -34,17 +34,17 @@ const HEADER = "// This Source Code Form
 "// need to be manually edited.\n" +
 "//***************************************************************************\n" +
 "\n";
 
 const PREAMBLE = "#define CNNIC_WHITELIST_HASH_LEN 32\n\n" +
 "struct WhitelistedCNNICHash {\n" +
 " const uint8_t hash[CNNIC_WHITELIST_HASH_LEN];\n" +
 "};\n\n" +
-"static const struct WhitelistedCNNICHash WhitelistedCNNICHashes[] = {\n";
+"static constexpr struct WhitelistedCNNICHash WhitelistedCNNICHashes[] = {\n";
 
 const POSTAMBLE = "};\n";
 
 function writeString(fos, string) {
   fos.write(string, string.length);
 }
 
 // fingerprint is in the form "00:11:22:..."