[tor-commits] [tor-browser-bundle/master] Bug 9084: Fix TBB3.0 startup crash on Windows XP

mikeperry at torproject.org mikeperry at torproject.org
Mon Sep 30 19:14:29 UTC 2013


commit fc14747c24c87085f6ca502d1643dd2e7a0ea7a0
Author: Georg Koppen <georg at getfoxyproxy.org>
Date:   Sun Sep 22 21:11:14 2013 +0200

    Bug 9084: Fix TBB3.0 startup crash on Windows XP
    
    We link against msvcr100 (which we ship) which needs small patches in nspr and
    gcc; the latter in order to get the runtime libraries recompiled properly.
---
 gitian/descriptors/windows/gitian-firefox.yml |   77 +++++++++++++++++++++----
 gitian/fetch-inputs.sh                        |   29 ++++++++--
 gitian/gpg/BINUTILS.gpg                       |  Bin 0 -> 25772 bytes
 gitian/gpg/GCC.gpg                            |  Bin 0 -> 2635 bytes
 gitian/versions                               |    6 ++
 5 files changed, 98 insertions(+), 14 deletions(-)

diff --git a/gitian/descriptors/windows/gitian-firefox.yml b/gitian/descriptors/windows/gitian-firefox.yml
index c1b2675..698cf35 100644
--- a/gitian/descriptors/windows/gitian-firefox.yml
+++ b/gitian/descriptors/windows/gitian-firefox.yml
@@ -15,6 +15,7 @@ packages:
 - "mingw-w64"
 - "g++-mingw-w64-i686"
 - "mingw-w64-tools"
+- "libmpc-dev"
 reference_datetime: "2000-01-01 00:00:00"
 remotes:
 - "url": "https://git.torproject.org/tor-browser.git"
@@ -22,6 +23,8 @@ remotes:
 files:
 # XXX: we need to make this input tarball deterministic :/
 - "mingw-w64-svn-snapshot.zip"
+- "binutils.tar.bz2"
+- "gcc.tar.bz2"
 - "torbrowser.version"
 - "re-dzip.sh"
 - "dzip.sh"
@@ -45,11 +48,30 @@ script: |
   #sudo bash -c 'echo "deb http://archive.ubuntu.com/ubuntu raring main restricted universe multiverse" >> /etc/apt/sources.list'
   #sudo apt-get update
   #sudo apt-get install -y g++-mingw-w64-i686 mingw-w64-tools mingw-w64
-  #
-  # Build the latest MinGW-w64 headers and CRT
+  
+  # Build the latest MinGW-w64 headers, CRT and runtime libraries to get Tor
+  # Browser going on all Windows platforms >= XP. In order to do so we link
+  # against msvcr100 (which we ship with the browser) as msvcrt on Windows XP
+  # does not contain the secure functions Firefox uses. That in turn makes it
+  # necessary to re-compile the mingw-w64 runtime libraries as well as they are
+  # linked against msvcrt by default. See bug 9084 for a more detailed
+  # discussion.
+
   # FIXME: We need sudo for all of this because otherwise
   # the toolchain can't find the alternate prefix for the CRT headers :/ 
-  # 
+
+  # We don't want to link against msvcrt.dll due to bug 9084.
+  i686-w64-mingw32-g++ -dumpspecs > msvcr100.spec
+  sed 's/msvcrt/msvcr100/' -i msvcr100.spec
+
+  mkdir binutils
+  cd binutils
+  tar -xjvf ../binutils.tar.bz2
+  binutils-*/configure --prefix=/usr --target=i686-w64-mingw32 --disable-multilib
+  make
+  sudo make install
+  cd ..
+
   mkdir mingw-w64
   cd mingw-w64
   unzip ../mingw-w64-svn-snapshot.zip
@@ -57,10 +79,27 @@ script: |
   mkdir mingw-w64-headers32 && cd mingw-w64-headers32
   ../mingw-w64-svn/mingw-w64-headers/configure --host=i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32/ --enable-sdk=all --enable-secure-api --enable-idl
   sudo make install
+  sudo ln -s /usr/i686-w64-mingw32 /usr/mingw
+  sudo mkdir -p /usr/i686-w64-mingw32/lib
+  cd ..
+  cd ..
+  # First stage of gcc compilation
+  mkdir gcc 
+  cd gcc
+  tar -xjvf ../gcc.tar.bz2
+  # Linking libgcc against msvcrt is hard-coded...
+  sed 's/msvcrt/msvcr100/' -i gcc-*/gcc/config/i386/t-mingw-w32 
+  # LDFLAGS_FOR_TARGET does not work for some reason. Thus, we take
+  # CFLAGS_FOR_TARGET.
+  export CFLAGS_FOR_TARGET="-specs=/home/ubuntu/build/msvcr100.spec"
+  gcc-*/configure --prefix=/usr --target=i686-w64-mingw32 --disable-multilib --enable-languages=c,c++
+  make all-gcc
+  sudo make install-gcc
   cd ..
   #
+  cd mingw-w64
   mkdir mingw-w64-crt32 && cd mingw-w64-crt32
-  ../mingw-w64-svn/mingw-w64-crt/configure --host=i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32/
+  ../mingw-w64-svn/mingw-w64-crt/configure --host=i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32
   make
   sudo make install
   cd ..
@@ -70,12 +109,33 @@ script: |
   make
   sudo make install
   cd ..
-  #
   cd ..
+  # Second stage of gcc compilation
+  cd gcc
+  make
+  sudo make install
   #
+  cd ..
   #
   cd tor-browser
   mv .mozconfig-mingw .mozconfig
+  # FIXME
+  # Ideally, using LDFLAGS (and e.g. DLLFLAGS for NSS) would be enough to get
+  # all Firefox libraries linked against msvcr100. Alas, this does not hold for
+  # NSPR. Without patching it we get a "missing entry points for _strcmpi in
+  # msvcr100.dll". Now, this should be fixed in rev>=6179 as the def file there
+  # contains a proper patch according to the mingw-w64 developers.
+  # However, even with this patch the _strcmpi issue is still popping up,
+  # probably due to a bug in our current linking setup. The small patch below
+  # is therefore just a workaround which should get fixed but is at least
+  # justified as the signature of _strcmpi and _stricmp is the same, see:
+  # http://msdn.microsoft.com/en-us/library/k59z8dwe.aspx.
+  sed 's/strcmpi/stricmp/' -i nsprpub/pr/src/linking/prlink.c 
+  export HOST_LDFLAGS=" "
+  export LDFLAGS="-specs=/home/ubuntu/build/msvcr100.spec"
+  # Our flags don't get passed to NSS. We need to do that manually using an
+  # obscure one.
+  export DLLFLAGS="-specs=/home/ubuntu/build/msvcr100.spec"
   grep -v '^pref(\"torbrowser.version\",' browser/app/profile/000-tor-browser.js > browser/app/profile/000-tor-browser.js.fixed
   cat ../torbrowser.version >> browser/app/profile/000-tor-browser.js.fixed
   mv browser/app/profile/000-tor-browser.js.fixed browser/app/profile/000-tor-browser.js
@@ -99,15 +159,12 @@ script: |
   #sudo mv /usr/bin/i686-w64-mingw32-ld /usr/bin/i686-w64-mingw32-ld.orig
   #sudo cp ~/build/bin/i686-w64-mingw32-ld /usr/bin/
   #
-  export HOST_LDFLAGS=" "
-  export LDFLAGS="-nostdlib -lgcc -lmsvcr100 -L/home/ubuntu/build/"
   make $MAKEOPTS -f client.mk build
   #
   make -C obj-* package INNER_MAKE_PACKAGE=true
   cp -a obj-*/dist/firefox/* $INSTDIR/App/Firefox/
-  cp -a /usr/lib/gcc/i686-w64-mingw32/4.6/libgcc_s_sjlj-1.dll $INSTDIR/App/Firefox/
-  cp -a /usr/lib/gcc/i686-w64-mingw32/4.6/libssp*.dll $INSTDIR/App/Firefox/
-  cp -a /usr/lib/gcc/i686-w64-mingw32/4.6/libstdc*dll $INSTDIR/App/Firefox/
+  cp -a /usr/i686-w64-mingw32/lib/libgcc_s_sjlj-1.dll $INSTDIR/App/Firefox/
+  cp -a /usr/i686-w64-mingw32/lib/libstdc*dll $INSTDIR/App/Firefox/
   cp -a ~/build/msvcr100.dll $INSTDIR/App/Firefox/
   #
   # XXX: What the hell are these three bytes anyways?
diff --git a/gitian/fetch-inputs.sh b/gitian/fetch-inputs.sh
index 2e25a5e..cce3331 100755
--- a/gitian/fetch-inputs.sh
+++ b/gitian/fetch-inputs.sh
@@ -38,9 +38,10 @@ trap "bash '$CLEANUP'; rm -f '$CLEANUP'" EXIT
 verify() {
   local file="$1"; shift
   local keyring="$1"; shift
+  local suffix="$1"; shift
 
   local f
-  for f in "$file" "$file.asc" "$keyring"; do
+  for f in "$file" "$file.$suffix" "$keyring"; do
     if ! [ -e "$f" ]; then
       echo >&2 "Error: Required file $f does not exist."; exit 1
     fi
@@ -52,7 +53,7 @@ verify() {
   echo "rm -rf '$gpghome'" >> "$CLEANUP"
   exec 3> "$tmpfile"
 
-  GNUPGHOME="$gpghome" gpg --no-options --no-default-keyring --trust-model=always --keyring="$keyring" --status-fd=3 --verify "$file.asc" "$file" >/dev/null 2>&1
+  GNUPGHOME="$gpghome" gpg --no-options --no-default-keyring --trust-model=always --keyring="$keyring" --status-fd=3 --verify "$file.$suffix" "$file" >/dev/null 2>&1
   if grep -q '^\[GNUPG:\] GOODSIG ' "$tmpfile"; then
     return 0
   else
@@ -99,16 +100,33 @@ for i in OPENSSL # OBFSPROXY
 do
   PACKAGE="${i}_PACKAGE"
   URL="${MIRROR_URL}${!PACKAGE}"
+  SUFFIX="asc"
   get "${!PACKAGE}" "$URL"
-  get "${!PACKAGE}.asc" "$URL.asc"
+  get "${!PACKAGE}.$SUFFIX" "$URL.$SUFFIX"
 
-  if ! verify "${!PACKAGE}" "$WRAPPER_DIR/gpg/$i.gpg"; then
+  if ! verify "${!PACKAGE}" "$WRAPPER_DIR/gpg/$i.gpg" $SUFFIX; then
     echo "$i: GPG signature is broken for ${URL}"
     mv "${!PACKAGE}" "${!PACKAGE}.badgpg"
     exit 1
   fi
 done
 
+for i in BINUTILS GCC
+do
+  PACKAGE="${i}_PACKAGE"
+  URL="${i}_URL" 
+  SUFFIX="sig"
+  get "${!PACKAGE}" "${!URL}"
+  get "${!PACKAGE}.$SUFFIX" "${!URL}.$SUFFIX"
+
+  if ! verify "${!PACKAGE}" "$WRAPPER_DIR/gpg/$i.gpg" $SUFFIX; then
+    echo "$i: GPG signature is broken for ${!URL}"
+    mv "${!PACKAGE}" "${!PACKAGE}.badgpg"
+    exit 1
+  fi
+done
+
+
 for i in TOOLCHAIN4 OSXSDK MSVCR100
 do
   PACKAGE="${i}_PACKAGE"
@@ -186,6 +204,9 @@ done
 ln -sf "$NOSCRIPT_PACKAGE" noscript at noscript.net.xpi
 ln -sf "$PDFJS_PACKAGE" uriloader at pdf.js.xpi
 ln -sf "$OPENSSL_PACKAGE" openssl.tar.gz
+ln -sf "$BINUTILS_PACKAGE" binutils.tar.bz2
+ln -sf "$GCC_PACKAGE" gcc.tar.bz2
+ 
 
 # Fetch latest gitian-builder itself
 # XXX - this is broken if a non-standard inputs dir is selected using the command line flag.
diff --git a/gitian/gpg/BINUTILS.gpg b/gitian/gpg/BINUTILS.gpg
new file mode 100644
index 0000000..f24bb01
Binary files /dev/null and b/gitian/gpg/BINUTILS.gpg differ
diff --git a/gitian/gpg/GCC.gpg b/gitian/gpg/GCC.gpg
new file mode 100644
index 0000000..e62de27
Binary files /dev/null and b/gitian/gpg/GCC.gpg differ
diff --git a/gitian/versions b/gitian/versions
index 1488b07..c601dc1 100755
--- a/gitian/versions
+++ b/gitian/versions
@@ -17,6 +17,8 @@ GITIAN_TAG=tor-browser-builder-3.0-4
 
 OPENSSL_VER=1.0.1e
 FIREFOX_LANG_VER=17.0.9esr
+BINUTILS_VER=2.22
+GCC_VER=4.6.3
 
 ## File names for the source packages
 OPENSSL_PACKAGE=openssl-${OPENSSL_VER}.tar.gz
@@ -26,6 +28,8 @@ TOOLCHAIN4_PACKAGE=multiarch-darwin11-cctools127.2-gcc42-5666.3-llvmgcc42-2336.1
 OSXSDK_PACKAGE=apple-uni-sdk-10.6_20110407-0.flosoft1_i386.deb
 MINGW_PACKAGE=mingw-w64-svn-snapshot.zip
 MSVCR100_PACKAGE=msvcr100.dll
+BINUTILS_PACKAGE=binutils-${BINUTILS_VER}.tar.bz2
+GCC_PACKAGE=gcc-${GCC_VER}.tar.bz2
 
 # Hashes for things with weak sigs or no sigs
 OPENSSL_HASH=f74f15e8c8ff11aa3d5bb5f276d202ec18d7246e95f961db76054199c69c1ae3
@@ -39,3 +43,5 @@ MSVCR100_HASH=1221a09484964a6f38af5e34ee292b9afefccb3dc6e55435fd3aaf7c235d9067
 OPENSSL_URL=https://www.openssl.org/source/${OPENSSL_PACKAGE}
 TOOLCHAIN4_URL=https://mingw-and-ndk.googlecode.com/files/${TOOLCHAIN4_PACKAGE}
 OSXSDK_URL=https://launchpad.net/~flosoft/+archive/cross-apple/+files/${OSXSDK_PACKAGE}
+BINUTILS_URL=https://ftp.gnu.org/gnu/binutils/${BINUTILS_PACKAGE}
+GCC_URL=https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VER}/${GCC_PACKAGE}



More information about the tor-commits mailing list