From 35c7aec59273ce484e39f18fad730e2733c34fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Wed, 20 Jun 2012 11:14:08 -0400 Subject: [PATCH] Bug 761421 - Upgrade clang to 158160. r=rail. Part 1 of many, add a script to build a tar file with clang to be use with tooltool. For now this is centos 5 only, but will be ported to OS X too. --- build/unix/build-clang/build-clang.py | 115 +++++++++++++++++ .../compiler-rt-gnu89-inline.patch | 10 ++ build/unix/build-clang/old-ld-hack.patch | 120 ++++++++++++++++++ 3 files changed, 245 insertions(+) create mode 100644 build/unix/build-clang/build-clang.py create mode 100644 build/unix/build-clang/compiler-rt-gnu89-inline.patch create mode 100644 build/unix/build-clang/old-ld-hack.patch diff --git a/build/unix/build-clang/build-clang.py b/build/unix/build-clang/build-clang.py new file mode 100644 index 00000000000..8ef0ec54f5f --- /dev/null +++ b/build/unix/build-clang/build-clang.py @@ -0,0 +1,115 @@ +#!/usr/bin/python +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +llvm_revision = "158160" +moz_version = "moz0" + +############################################## + +import os +import os.path +import shutil +import tarfile +import subprocess + +def check_run(args): + r = subprocess.call(args) + assert r == 0 + +def run_in(path, args): + d = os.getcwd() + os.chdir(path) + check_run(args) + os.chdir(d) + +def patch(patch, plevel, srcdir): + patch = os.path.realpath(patch) + check_run(['patch', '-d', srcdir, '-p%s' % plevel, '-i', patch, '--fuzz=0', + '-s']) + +def build_package(package_source_dir, package_build_dir, configure_args): + if not os.path.exists(package_build_dir): + os.mkdir(package_build_dir) + run_in(package_build_dir, + ["%s/configure" % package_source_dir] + configure_args) + run_in(package_build_dir, ["make", "-j8"]) + run_in(package_build_dir, ["make", "install"]) + +def with_env(env, f): + old_env = os.environ.copy() + os.environ.update(env) + f() + os.environ.clear() + os.environ.update(old_env) + +def build_tar_package(tar, name, base, directory): + name = os.path.realpath(name) + run_in(base, [tar, "-cjf", name, "--mtime=2012-01-01", "--owner=root", + directory]) + +def svn_co(url, directory, revision): + check_run(["svn", "co", "-r", revision, url, directory]) + +# The directories end up in the debug info, so the easy way of getting +# a reproducible build is to run it in a know absolute directory. +# We use a directory in /builds/slave because the mozilla infrastructure +# cleans it up automatically. +base_dir = "/builds/slave/moz-toolchain" + +source_dir = base_dir + "/src" +build_dir = base_dir + "/build" + +llvm_source_dir = source_dir + "/llvm" +clang_source_dir = source_dir + "/clang" +compiler_rt_source_dir = source_dir + "/compiler-rt" + +def build_one_stage(env, stage_dir, is_stage_one): + def f(): + build_one_stage_aux(stage_dir, is_stage_one) + with_env(env, f) + +def build_one_stage_aux(stage_dir, is_stage_one): + os.mkdir(stage_dir) + + build_dir = stage_dir + "/build" + inst_dir = stage_dir + "/inst" + + configure_opts = ["--enable-optimized", + "--prefix=%s" % inst_dir, + "--with-gcc-toolchain=/tools/gcc-4.5-0moz3"] + if is_stage_one: + configure_opts.append("--with-optimize-option=-O0") + + build_package(llvm_source_dir, build_dir, configure_opts) + +if not os.path.exists(source_dir): + os.makedirs(source_dir) + svn_co("http://llvm.org/svn/llvm-project/llvm/trunk", + llvm_source_dir, llvm_revision) + svn_co("http://llvm.org/svn/llvm-project/cfe/trunk", + clang_source_dir, llvm_revision) + svn_co("http://llvm.org/svn/llvm-project/compiler-rt/trunk", + compiler_rt_source_dir, llvm_revision) + os.symlink("../../clang", llvm_source_dir + "/tools/clang") + os.symlink("../../compiler-rt", llvm_source_dir + "/projects/compiler-rt") + patch("old-ld-hack.patch", 1, llvm_source_dir) + patch("compiler-rt-gnu89-inline.patch", 0, compiler_rt_source_dir) + +if os.path.exists(build_dir): + shutil.rmtree(build_dir) +os.makedirs(build_dir) + +stage1_dir = build_dir + '/stage1' +stage1_inst_dir = stage1_dir + '/clang' +build_one_stage({"CC" : "/tools/gcc-4.5-0moz3/bin/gcc -static-libgcc", + "CXX" : "/tools/gcc-4.5-0moz3/bin/g++ -static-libgcc -static-libstdc++"}, + stage1_dir, True) + +stage2_dir = build_dir + '/stage2' +build_one_stage({"CC" : stage1_inst_dir + "/bin/clang -static-libgcc -fgnu89-inline", + "CXX" : stage1_inst_dir + "/bin/clang++ -static-libgcc -static-libstdc++"}, + stage2_dir, False) + +build_tar_package("/bin/tar", "clang.tar.bz2", stage3_dir, "clang") diff --git a/build/unix/build-clang/compiler-rt-gnu89-inline.patch b/build/unix/build-clang/compiler-rt-gnu89-inline.patch new file mode 100644 index 00000000000..f51394277f2 --- /dev/null +++ b/build/unix/build-clang/compiler-rt-gnu89-inline.patch @@ -0,0 +1,10 @@ +Index: make/config.mk +=================================================================== +--- make/config.mk (revision 157958) ++++ make/config.mk (working copy) +@@ -43,4 +43,4 @@ + ### + # Common compiler options + COMMON_CXXFLAGS=-fno-exceptions -fPIC -funwind-tables -I${ProjSrcRoot}/lib +-COMMON_CFLAGS=-fPIC ++COMMON_CFLAGS=-fPIC -fgnu89-inline diff --git a/build/unix/build-clang/old-ld-hack.patch b/build/unix/build-clang/old-ld-hack.patch new file mode 100644 index 00000000000..318236f87cc --- /dev/null +++ b/build/unix/build-clang/old-ld-hack.patch @@ -0,0 +1,120 @@ +diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h +index 9932306..948caa8 100644 +--- a/include/llvm/MC/MCStreamer.h ++++ b/include/llvm/MC/MCStreamer.h +@@ -116,7 +116,7 @@ namespace llvm { + return FrameInfos[i]; + } + +- ArrayRef getFrameInfos() { ++ MutableArrayRef getFrameInfos() { + return FrameInfos; + } + +diff --git a/lib/MC/MCDwarf.cpp b/lib/MC/MCDwarf.cpp +index e16f7ae..edf1d6d 100644 +--- a/lib/MC/MCDwarf.cpp ++++ b/lib/MC/MCDwarf.cpp +@@ -859,7 +859,6 @@ namespace { + const MCSymbol &EmitCIE(MCStreamer &streamer, + const MCSymbol *personality, + unsigned personalityEncoding, +- const MCSymbol *lsda, + bool IsSignalFrame, + unsigned lsdaEncoding); + MCSymbol *EmitFDE(MCStreamer &streamer, +@@ -1131,7 +1130,6 @@ bool FrameEmitterImpl::EmitCompactUnwind(MCStreamer &Streamer, + const MCSymbol &FrameEmitterImpl::EmitCIE(MCStreamer &streamer, + const MCSymbol *personality, + unsigned personalityEncoding, +- const MCSymbol *lsda, + bool IsSignalFrame, + unsigned lsdaEncoding) { + MCContext &context = streamer.getContext(); +@@ -1172,7 +1170,7 @@ const MCSymbol &FrameEmitterImpl::EmitCIE(MCStreamer &streamer, + Augmentation += "z"; + if (personality) + Augmentation += "P"; +- if (lsda) ++ if (lsdaEncoding) + Augmentation += "L"; + Augmentation += "R"; + if (IsSignalFrame) +@@ -1203,7 +1201,7 @@ const MCSymbol &FrameEmitterImpl::EmitCIE(MCStreamer &streamer, + // Personality + augmentationLength += getSizeForEncoding(streamer, personalityEncoding); + } +- if (lsda) ++ if (lsdaEncoding) + augmentationLength += 1; + // Encoding of the FDE pointers + augmentationLength += 1; +@@ -1221,7 +1219,7 @@ const MCSymbol &FrameEmitterImpl::EmitCIE(MCStreamer &streamer, + EmitPersonality(streamer, *personality, personalityEncoding); + } + +- if (lsda) ++ if (lsdaEncoding) + EmitEncodingByte(streamer, lsdaEncoding, "LSDA Encoding"); + + // Encoding of the FDE pointers +@@ -1322,6 +1320,8 @@ MCSymbol *FrameEmitterImpl::EmitFDE(MCStreamer &streamer, + if (frame.Lsda) + EmitSymbol(streamer, *frame.Lsda, frame.LsdaEncoding, + "Language Specific Data Area"); ++ else if (frame.LsdaEncoding) ++ streamer.EmitIntValue(0, 4); + } + + // Call Frame Instructions +@@ -1385,7 +1385,7 @@ void MCDwarfFrameEmitter::Emit(MCStreamer &Streamer, + MCObjectFileInfo *MOFI = + const_cast(Context.getObjectFileInfo()); + FrameEmitterImpl Emitter(UsingCFI, IsEH); +- ArrayRef FrameArray = Streamer.getFrameInfos(); ++ MutableArrayRef FrameArray = Streamer.getFrameInfos(); + + // Emit the compact unwind info if available. + if (IsEH && MOFI->getCompactUnwindSection()) +@@ -1405,7 +1405,31 @@ void MCDwarfFrameEmitter::Emit(MCStreamer &Streamer, + MCSymbol *FDEEnd = NULL; + DenseMap CIEStarts; + +- const MCSymbol *DummyDebugKey = NULL; ++ ++ const MCSymbol *HackPersonality = NULL; ++ unsigned HackLsdaEncoding = 0; ++ unsigned HackPersonalityEncoding = 0; ++ for (unsigned i = 0, n = FrameArray.size(); i < n; ++i) { ++ const MCDwarfFrameInfo &Frame = FrameArray[i]; ++ if (!HackPersonality) ++ HackPersonality = Frame.Personality; ++ if (!HackLsdaEncoding) ++ HackLsdaEncoding = Frame.LsdaEncoding; ++ if (!HackPersonalityEncoding) ++ HackPersonalityEncoding = Frame.PersonalityEncoding; ++ } ++ ++ for (unsigned i = 0, n = FrameArray.size(); i < n; ++i) { ++ MCDwarfFrameInfo &Frame = FrameArray[i]; ++ assert(Frame.Personality == NULL || Frame.Personality == HackPersonality); ++ Frame.Personality = HackPersonality; ++ assert(Frame.LsdaEncoding == 0 || Frame.LsdaEncoding == HackLsdaEncoding); ++ Frame.LsdaEncoding = HackLsdaEncoding; ++ assert(Frame.PersonalityEncoding == 0 || Frame.PersonalityEncoding == HackPersonalityEncoding); ++ Frame.PersonalityEncoding = HackPersonalityEncoding; ++ } ++ ++ const MCSymbol *DummyDebugKey = NULL; + for (unsigned i = 0, n = FrameArray.size(); i < n; ++i) { + const MCDwarfFrameInfo &Frame = FrameArray[i]; + CIEKey Key(Frame.Personality, Frame.PersonalityEncoding, +@@ -1413,7 +1437,7 @@ void MCDwarfFrameEmitter::Emit(MCStreamer &Streamer, + const MCSymbol *&CIEStart = IsEH ? CIEStarts[Key] : DummyDebugKey; + if (!CIEStart) + CIEStart = &Emitter.EmitCIE(Streamer, Frame.Personality, +- Frame.PersonalityEncoding, Frame.Lsda, ++ Frame.PersonalityEncoding, + Frame.IsSignalFrame, + Frame.LsdaEncoding); +