Bug 1302891 - Part 2 - Create CFI vtable whitelist during configuration; r?glandium draft
authorEnes Goktas <egoktas@mozilla.com>
Thu, 15 Sep 2016 17:19:08 -0700
changeset 418762 41aa83dc93040eb3ee1ba237901dc1b851f28674
parent 418761 9530f09f2faa5fdc19ac0c19fe43f3d3606730bf
child 418763 412f6b84519a3985fb3a42a78b2b64383e7f9077
push id30776
push userbmo:enes.goktas@gmail.com
push dateThu, 29 Sep 2016 05:44:28 +0000
reviewersglandium
bugs1302891
milestone52.0a1
Bug 1302891 - Part 2 - Create CFI vtable whitelist during configuration; r?glandium MozReview-Commit-ID: GupmRS8yXTU
build/generate_cfi_whitelist.py
old-configure.in
new file mode 100755
--- /dev/null
+++ b/build/generate_cfi_whitelist.py
@@ -0,0 +1,76 @@
+#!/usr/bin/python
+
+import os
+import sys
+import subprocess
+
+def extractInterfaces(idlFileName):
+  interfaceNames = set()
+  with open(idlFileName, "rb") as f:
+    for l in f.xreadlines():
+      if l.startswith("interface "):
+        spl = l.split(":")
+        if len(spl) == 1: continue
+
+        interfaceName = spl[0].split()[1]
+        interfaceNames.add(interfaceName)
+
+  return interfaceNames
+
+def mangleRTTI(n):
+  return "_ZTS%d%s" % (len(n),n)
+
+def getListOfIDLFiles(topsrcdir):
+  cmd = 'find ' + topsrcdir + ' -type f -name *.idl'
+  proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
+  return proc.communicate()[0]
+
+def main():
+  # assert the file is in 'build' dir before getting
+  # the topsrcdir with os.path.dirname()
+  scriptdir = os.path.dirname(os.path.realpath(__file__))
+  assert(scriptdir.endswith("build"))
+  topsrcdir = os.path.dirname(scriptdir)
+
+  # extract interface names that use XPTCStubBase's vtable at runtime
+  interfaceNames = set()
+
+  listOfIDLs = getListOfIDLFiles(topsrcdir)
+  for idlFileName in listOfIDLs.split():
+    interfaceNames.update(extractInterfaces(idlFileName.strip()))
+
+  whitelist = open(topsrcdir + "/cfi-whitelist.txt", "wb")
+
+  # whitelist relationship between interface names and XPTCStubBase
+  for name in interfaceNames:
+    whitelist.write("vtablelink:%s:_ZTV14nsXPTCStubBase\n" % mangleRTTI(name))
+
+  # whitelist other linked vtables (unrelated to XPTCStubBase)
+  whitelist.write("vtablelink:%s:%s\n" %
+                  ("_ZTS13nsPIDOMWindowI18mozIDOMWindowProxyE",
+                   "_ZTV14nsGlobalWindow"))
+  whitelist.write("vtablelink:%s:%s\n" %
+                  ("_ZTS13nsPIDOMWindowI18mozIDOMWindowProxyE",
+                   "_ZTV20nsGlobalChromeWindow"))
+  whitelist.write("vtablelink:%s:%s\n" %
+                  ("_ZTS13nsPIDOMWindowI18mozIDOMWindowProxyE",
+                   "_ZTV19nsGlobalModalWindow"))
+  whitelist.write("vtablelink:%s:%s\n" %
+                  ("_ZTS13nsPIDOMWindowI13mozIDOMWindowE",
+                   "_ZTV14nsGlobalWindow"))
+  whitelist.write("vtablelink:%s:%s\n" %
+                  ("_ZTS13nsPIDOMWindowI13mozIDOMWindowE",
+                   "_ZTV20nsGlobalChromeWindow"))
+  whitelist.write("vtablelink:%s:%s\n" %
+                  ("_ZTS13nsPIDOMWindowI13mozIDOMWindowE",
+                   "_ZTV19nsGlobalModalWindow"))
+
+  whitelist.write("vtablelink:%s:%s\n" %
+                  ("_ZTSN7mozilla3dom10IDBRequestE",
+                   "_ZTVN7mozilla3dom15IDBWrapperCacheE"))
+
+  whitelist.close()
+
+
+if __name__ == "__main__":
+  sys.exit(main())
--- a/old-configure.in
+++ b/old-configure.in
@@ -236,17 +236,16 @@ if test -n "$MOZ_CFI"; then
             echo "ld is ld.gold"
         else
             echo "Could not set ld.gold as the linker."
             echo "Please ensure that ld is the gold linker (ld.gold)."
             exit 1
         fi
     fi
 
-
     LLVM_NM=$(which llvm-nm)
     GNU_NM=$(which nm)
     if test -n "$LLVM_NM"; then
         cp "$LLVM_NM" "$GNU_NM"
     else
         echo "Could not find llvm-nm. Please add path of llvm/bin to PATH env."
         exit 1
     fi
@@ -259,16 +258,25 @@ if test -n "$MOZ_CFI"; then
 #            LDFLAGS="$LDFLAGS -B $_objdir/build/unix/gold"
 #        else
 #            rm -rf $_objdir/build/unix/gold
 #        fi
 #
 #        # use ld gold for everything
 #        cp $LD_GOLD /usr/bin/ld
 #    fi
+
+     echo "Create cfi-whitelist.txt"
+     $_topsrcdir/build/generate_cfi_whitelist.py
+     if test -f "$_topsrcdir/cfi-whitelist.txt"; then
+        echo "$_topsrcdir/cfi-whitelist.txt found."
+     else
+        echo "$_topsrcdir/cfi-whitelist.txt could not be found!"
+        exit 1
+     fi
 fi
 
 dnl ========================================================
 dnl Checks for compilers.
 dnl ========================================================
 
 dnl AR_FLAGS set here so HOST_AR_FLAGS can be set correctly (see bug 538269)
 AR_FLAGS='crs $@'