about summary refs log tree commit diff
path: root/src/librustc/back
AgeCommit message (Collapse)AuthorLines
2014-05-01auto merge of #13724 : nikomatsakis/rust/expr-use-visitor, r=pnkfelixbors-2/+2
Pre-step towards issue #12624 and others: Introduce ExprUseVisitor, remove the moves computation. ExprUseVisitor is a visitor that walks the AST for a function and calls a delegate to inform it where borrows, copies, and moves occur. In this patch, I rewrite the gather_loans visitor to use ExprUseVisitor, but in future patches, I think we could rewrite regionck, check_loans, and possibly other passes to use it as well. This would refactor the repeated code between those places that tries to determine where copies/moves/etc occur. r? @alexcrichton
2014-04-29auto merge of #13833 : alexcrichton/rust/ffunction-sections, r=thestingerbors-6/+20
The compiler has previously been producing binaries on the order of 1.8MB for hello world programs "fn main() {}". This is largely a result of the compilation model used by compiling entire libraries into a single object file and because static linking is favored by default. When linking, linkers will pull in the entire contents of an object file if any symbol from the object file is used. This means that if any symbol from a rust library is used, the entire library is pulled in unconditionally, regardless of whether the library is used or not. Traditional C/C++ projects do not normally encounter these large executable problems because their archives (rust's rlibs) are composed of many objects. Because of this, linkers can eliminate entire objects from being in the final executable. With rustc, however, the linker does not have the opportunity to leave out entire object files. In order to get similar benefits from dead code stripping at link time, this commit enables the -ffunction-sections and -fdata-sections flags in LLVM, as well as passing --gc-sections to the linker *by default*. This means that each function and each global will be placed into its own section, allowing the linker to GC all unused functions and data symbols. By enabling these flags, rust is able to generate much smaller binaries default. On linux, a hello world binary went from 1.8MB to 597K (a 67% reduction in size). The output size of dynamic libraries remained constant, but the output size of rlibs increased, as seen below: libarena - 2.27% bigger libcollections - 0.64% bigger libflate - 0.85% bigger libfourcc - 14.67% bigger libgetopts - 4.52% bigger libglob - 2.74% bigger libgreen - 9.68% bigger libhexfloat - 13.68% bigger liblibc - 10.79% bigger liblog - 10.95% bigger libnative - 8.34% bigger libnum - 2.31% bigger librand - 1.71% bigger libregex - 6.43% bigger librustc - 4.21% bigger librustdoc - 8.98% bigger librustuv - 4.11% bigger libsemver - 2.68% bigger libserialize - 1.92% bigger libstd - 3.59% bigger libsync - 3.96% bigger libsyntax - 4.96% bigger libterm - 13.96% bigger libtest - 6.03% bigger libtime - 2.86% bigger liburl - 6.59% bigger libuuid - 4.70% bigger libworkcache - 8.44% bigger This increase in size is a result of encoding many more section names into each object file (rlib). These increases are moderate enough that this change seems worthwhile to me, due to the drastic improvements seen in the final artifacts. The overall increase of the stage2 target folder (not the size of an install) went from 337MB to 348MB (3% increase). Additionally, linking is generally slower when executed with all these new sections plus the --gc-sections flag. The stage0 compiler takes 1.4s to link the `rustc` binary, where the stage1 compiler takes 1.9s to link the binary. Three megabytes are shaved off the binary. I found this increase in link time to be acceptable relative to the benefits of code size gained. This commit only enables --gc-sections for *executables*, not dynamic libraries. LLVM does all the heavy lifting when producing an object file for a dynamic library, so there is little else for the linker to do (remember that we only have one object file). I conducted similar experiments by putting a *module's* functions and data symbols into its own section (granularity moved to a module level instead of a function/static level). The size benefits of a hello world were seen to be on the order of 400K rather than 1.2MB. It seemed that enough benefit was gained using ffunction-sections that this route was less desirable, despite the lesser increases in binary rlib size.
2014-04-29rustc: Enable -f{function,data}-sectionsAlex Crichton-6/+20
The compiler has previously been producing binaries on the order of 1.8MB for hello world programs "fn main() {}". This is largely a result of the compilation model used by compiling entire libraries into a single object file and because static linking is favored by default. When linking, linkers will pull in the entire contents of an object file if any symbol from the object file is used. This means that if any symbol from a rust library is used, the entire library is pulled in unconditionally, regardless of whether the library is used or not. Traditional C/C++ projects do not normally encounter these large executable problems because their archives (rust's rlibs) are composed of many objects. Because of this, linkers can eliminate entire objects from being in the final executable. With rustc, however, the linker does not have the opportunity to leave out entire object files. In order to get similar benefits from dead code stripping at link time, this commit enables the -ffunction-sections and -fdata-sections flags in LLVM, as well as passing --gc-sections to the linker *by default*. This means that each function and each global will be placed into its own section, allowing the linker to GC all unused functions and data symbols. By enabling these flags, rust is able to generate much smaller binaries default. On linux, a hello world binary went from 1.8MB to 597K (a 67% reduction in size). The output size of dynamic libraries remained constant, but the output size of rlibs increased, as seen below: libarena - 2.27% bigger ( 292872 => 299508) libcollections - 0.64% bigger ( 6765884 => 6809076) libflate - 0.83% bigger ( 186516 => 188060) libfourcc - 14.71% bigger ( 307290 => 352498) libgetopts - 4.42% bigger ( 761468 => 795102) libglob - 2.73% bigger ( 899932 => 924542) libgreen - 9.63% bigger ( 1281718 => 1405124) libhexfloat - 13.88% bigger ( 333738 => 380060) liblibc - 10.79% bigger ( 551280 => 610736) liblog - 10.93% bigger ( 218208 => 242060) libnative - 8.26% bigger ( 1362096 => 1474658) libnum - 2.34% bigger ( 2583400 => 2643916) librand - 1.72% bigger ( 1608684 => 1636394) libregex - 6.50% bigger ( 1747768 => 1861398) librustc - 4.21% bigger (151820192 => 158218924) librustdoc - 8.96% bigger ( 13142604 => 14320544) librustuv - 4.13% bigger ( 4366896 => 4547304) libsemver - 2.66% bigger ( 396166 => 406686) libserialize - 1.91% bigger ( 6878396 => 7009822) libstd - 3.59% bigger ( 39485286 => 40902218) libsync - 3.95% bigger ( 1386390 => 1441204) libsyntax - 4.96% bigger ( 35757202 => 37530798) libterm - 13.99% bigger ( 924580 => 1053902) libtest - 6.04% bigger ( 2455720 => 2604092) libtime - 2.84% bigger ( 1075708 => 1106242) liburl - 6.53% bigger ( 590458 => 629004) libuuid - 4.63% bigger ( 326350 => 341466) libworkcache - 8.45% bigger ( 1230702 => 1334750) This increase in size is a result of encoding many more section names into each object file (rlib). These increases are moderate enough that this change seems worthwhile to me, due to the drastic improvements seen in the final artifacts. The overall increase of the stage2 target folder (not the size of an install) went from 337MB to 348MB (3% increase). Additionally, linking is generally slower when executed with all these new sections plus the --gc-sections flag. The stage0 compiler takes 1.4s to link the `rustc` binary, where the stage1 compiler takes 1.9s to link the binary. Three megabytes are shaved off the binary. I found this increase in link time to be acceptable relative to the benefits of code size gained. This commit only enables --gc-sections for *executables*, not dynamic libraries. LLVM does all the heavy lifting when producing an object file for a dynamic library, so there is little else for the linker to do (remember that we only have one object file). I conducted similar experiments by putting a *module's* functions and data symbols into its own section (granularity moved to a module level instead of a function/static level). The size benefits of a hello world were seen to be on the order of 400K rather than 1.2MB. It seemed that enough benefit was gained using ffunction-sections that this route was less desirable, despite the lesser increases in binary rlib size.
2014-04-28rustc: Pass -dead_strip on OSXAlex Crichton-0/+12
This flag to the linker asks it to strip away all dead code during linking, as well as dead data. This reduces the size of hello world from 1.7MB to 458K on my system (70% reduction). I have not seen this impact link times negatively, and I have seen this pass 'make check' successfully. I am slightly wary of adding this option, but the benefits are so huge tha I think we should work hard to work around any issues rather than avoid using the flag entirely.
2014-04-25Cleaned up os::consts. The module only exposes constants for the target OS ↵Michael Darakananda-7/+6
and arch. Constants for other OS's and arch's must be defined manually. [breaking-change]
2014-04-24use option_env! instead of env!Niko Matsakis-2/+2
2014-04-24auto merge of #13531 : alexcrichton/rust/fix-some-ices, r=brsonbors-2/+5
See the commits for the affected issues.
2014-04-23Enable use of syntax extensions when cross compiling.Douglas Young-3/+3
This adds the target triple to the crate metadata. When searching for a crate the phase (link, syntax) is taken into account. During link phase only crates matching the target triple are considered. During syntax phase, either the target or host triple will be accepted, unless the crate defines a macro_registrar, in which case only the host triple will match.
2014-04-23rustc: Don't die when a crate id can't be inferredAlex Crichton-1/+4
The filestem of the desired output isn't necessarily a valid crate id, and calling unwrap() will trigger an ICE in rustc. This tries a little harder to infer a "valid crate id" from a crate, with an eventual fallback to a generic crate id if alll else fails. Closes #11107
2014-04-23rustc: Fix passing errors from LLVM to rustcAlex Crichton-1/+1
Many of the instances of setting a global error variable ended up leaving a dangling pointer into free'd memory. This changes the method of error transmission to strdup any error and "relinquish ownership" to rustc when it gets an error. The corresponding Rust code will then free the error as necessary. Closes #12865
2014-04-21Fix misspellings in comments.Joseph Crail-4/+4
2014-04-18auto merge of #13607 : brson/rust/to_owned, r=brsonbors-64/+65
Continues https://github.com/mozilla/rust/pull/13548
2014-04-18Replace all ~"" with "".to_owned()Richo Healey-64/+65
2014-04-18auto merge of #13513 : alexcrichton/rust/up-llvm, r=brsonbors-0/+16
This is a bit of an interesting upgrade to LLVM. Upstream LLVM has started using C++11 features, so they require a C++11 compiler to build. I've updated all the bots to have a C++11 compiler, and they appear to be building LLVM successfully: * Linux bots - I added gcc/g++ 4.7 (good enough) * Android bots - same as the linux ones * Mac bots - I installed the most recent command line tools for Lion which gives us clang 3.2, but LLVM wouldn't build unless it was explicitly asked to link to `libc++` instead of `libstdc++`. This involved tweaking `mklldeps.py` and the `configure` script to get things to work out * Windows bots - mingw-w64 has gcc 4.8.1 which is sufficient for building LLVM (hurray!) * BSD bots - I updated FreeBSD to 10.0 which brought with it a relevant version of clang. The largest fallout I've seen so far is that the test suite doesn't work at all on FreeBSD 10. We've already stopped gating on FreeBSD due to #13427 (we used to be on freebsd 9), so I don't think this puts us in too bad of a situation. I will continue to attempt to fix FreeBSD and the breakage on there. The LLVM update brings with it all of the recently upstreamed LLVM patches. We only have one local patch now which is just an optimization, and isn't required to use upstream LLVM. I want to maintain compatibility with LLVM 3.3 and 3.4 while we can, and this upgrade is keeping us up to date with the 3.5 release. Once 3.5 is release we will in theory no longer require a bundled LLVM.
2014-04-18Update the rest of the compiler with ~[T] changesAlex Crichton-2/+0
2014-04-17rustc: Hint to the linker about static/shared libsAlex Crichton-0/+16
If a linker finds both a static and a dynamic version of the same library, then the linker often chooses the dynamic version. This is surprising when a native library is specified as being "static" in rust source. This modifies the linker command line to obey the hints given in rust source files and instructing the linker to prefer a particular version of a found library. Unfortunately, this patch has no effect on osx because the linker supports no such hint, and it also has no effect on windows because the linker apparently just ignores it. For now this is predominately used to enable the previous patch of linking to libstdc++ statically, but more support would need to be added for this in the future if we wanted to officially support it. cc #12557 (doesn't close because it doesn't support OSX and windows)
2014-04-16rustc: Fix omission of bytecode in staticlibsAlex Crichton-1/+1
The name of the file changed awhile back and this spot wasn't updated to continue ignoring the bytecode from rlibs when copying into staticlibs.
2014-04-11rustc: Deterministically link upstream C librariesAlex Crichton-5/+14
Previously, upstream C libraries were linked in a nondeterministic fashion because they were collected through iter_crate_data() which is a nodeterministic traversal of a hash map. When upstream rlibs had interdependencies among their native libraries (such as libfoo depending on libc), then the ordering would occasionally be wrong, causing linkage to fail. This uses the topologically sorted list of libraries to collect native libraries, so if a native library depends on libc it just needs to make sure that the rust crate depends on liblibc.
2014-04-10auto merge of #13440 : huonw/rust/strbuf, r=alexcrichtonbors-15/+22
libstd: Implement `StrBuf`, a new string buffer type like `Vec`, and port all code over to use it. Rebased & tests-fixed version of https://github.com/mozilla/rust/pull/13269
2014-04-10rustc: Use realpath() for sysroot/rpathAlex Crichton-3/+4
When calculating the sysroot, it's more accurate to use realpath() rather than just one readlink() to account for any intermediate symlinks that the rustc binary resolves itself to. For rpath, realpath() is necessary because the rpath must dictate a relative rpath from the destination back to the originally linked library, which works more robustly if there are no symlinks involved. Concretely, any binary generated on OSX into $TMPDIR requires an absolute rpath because the temporary directory is behind a symlink with one layer of indirection. This symlink causes all relative rpaths to fail to resolve. cc #11734 cc #11857
2014-04-10rustc: Don't rpath to librustrt.dylibAlex Crichton-12/+3
This library no longer exists, there's no reason for this rpath to exist any more.
2014-04-10rustc: Remove absolute rpathsAlex Crichton-29/+1
Concerns have been raised about using absolute rpaths in #11746, and this is the first step towards not relying on rpaths at all. The only current use case for an absolute rpath is when a non-installed rust builds an executable that then moves from is built location. The relative rpath back to libstd and absolute rpath to the installation directory still remain (CFG_PREFIX). Closes #11746 Rebasing of #12754
2014-04-10libstd: Implement `StrBuf`, a new string buffer type like `Vec`, andPatrick Walton-15/+22
port all code over to use it.
2014-04-08Made libflate functions return Options instead of outright failingTobba-3/+9
2014-04-06auto merge of #13165 : sfackler/rust/io-vec, r=alexcrichtonbors-6/+13
`Reader`, `Writer`, `MemReader`, `MemWriter`, and `MultiWriter` now work with `Vec<u8>` instead of `~[u8]`. This does introduce some extra copies since `from_utf8_owned` isn't usable anymore, but I think that can't be helped until `~str`'s representation changes.
2014-04-06De-~[] Reader and WriterSteven Fackler-6/+13
There's a little more allocation here and there now since from_utf8_owned can't be used with Vec.
2014-04-06auto merge of #13340 : FlaPer87/rust/code-model, r=cmrbors-1/+14
Rust currently defaults to `RelocPIC` regardless. This patch adds a new codegen option that allows choosing different relocation-model. The available models are: - default (Use the target-specific default model) - static - pic - no-pic For a more detailed information use `llc --help`
2014-04-06Add support for different relocation modelsFlavio Percoco-1/+14
Rust currently defaults to `RelocPIC` regardless. This patch adds a new codegen option that allows choosing different relocation-model. The available models are: - default (Use the target-specific default model) - static - pic - no-pic For a more detailed information use `llc --help`
2014-04-05rustc: Pass --enable-long-section-names to gccAlex Crichton-0/+27
This was quite a curious bug on windows, and the details can be found in the comment I added to src/librustc/back/link.rs
2014-04-04Fix fallout from std::libc separationCorey Richardson-3/+3
2014-04-01back: link: remove dead codeCorey Richardson-10/+0
2014-04-01back: archive: remove dead codeCorey Richardson-23/+0
2014-04-01back: abi: remove dead codeCorey Richardson-35/+0
2014-03-31rustc: Switch field privacy as necessaryAlex Crichton-9/+9
2014-03-30Removed deprecated functions `map` and `flat_map` for vectors and slices.Marvin Löbel-2/+2
2014-03-28Convert most code to new inner attribute syntax.Brian Anderson-1/+1
Closes #2569
2014-03-27auto merge of #13151 : brson/rust/dist, r=alexcrichton,brsonbors-7/+10
A variety of stuff here, mostly aimed at making `make install` work correctly with `--libdir` and `--mandir`. `make install` again goes through `install.sh`.
2014-03-26rustc: Fix tests for sysroot changesBrian Anderson-2/+2
2014-03-25install: Support --libdir and --mandir correctlyBrian Anderson-7/+10
This adds a hack to rustc to make it find the library directory regardless of whether it is named lib/lib64/lib32.
2014-03-25Changed `iter::Extendable` and `iter::FromIterator` to take a `Iterator` by ↵Marvin Löbel-3/+3
value
2014-03-25auto merge of #13122 : sstewartgallus/rust/cleanup-10734-workarounds, ↵bors-1/+1
r=alexcrichton Cleanup old issue references. One of these workarounds no longer need to be used anymore and the others are out of date.
2014-03-24Cleanup fixed issue #10734 workaroundSteven Stewart-Gallus-1/+1
2014-03-23rustc: Change the filename of compressed bitcodePiotr Czarnecki-5/+7
Fixes #12992 Store compressed bitcode files in rlibs with a different extension. Compression doesn't interfere with --emit=bc. Regression test compares outputs.
2014-03-22rustc: Fix fallout of removing get()Alex Crichton-27/+12
2014-03-20Removing imports of std::vec_ng::VecAlex Crichton-7/+0
It's now in the prelude.
2014-03-20rename std::vec_ng -> std::vecDaniel Micay-6/+6
Closes #12771
2014-03-20rename std::vec -> std::sliceDaniel Micay-2/+2
Closes #12702
2014-03-17De-@ codemap and diagnostic.Eduard Burtescu-4/+3
2014-03-17De-@ move maps and rework parts of trans.Eduard Burtescu-3/+3
2014-03-17De-@ CStore uses.Eduard Burtescu-4/+4