Commit graph

81 commits

Author SHA1 Message Date
mark 2c31b45ae8 mv std libs to library/ 2020-07-27 19:51:13 -05:00
bors 371917ab21 Auto merge of #74613 - Mark-Simulacrum:revert-gimli, r=nnethercote
Revert libbacktrace -> gimli

This reverts 4cbd265c11 028f8d7b85 13db3cc1e8 d7a36d8964 (and technically 79673d3009 but it's made empty by previous reverts).

The current plan is to land this PR as a temporary change, so that we can get a better handle on the regressions introduced by it. Trying to fix/examine them in master is difficult, and we want to be better able to evaluate them without impact to other PRs being landed in the mean time.

That said, it is currently *my* belief that gimli, in one form or another, will need to land sometime soon. I think it's quite likely that it may slip a week or two, but I would personally push for re-landing it then "regardless" of the regressions. We should try to focus efforts on understanding and removing as much of the performance impact as possible, as everyone pretty much agrees that it should be quite minimal (and entirely in the linker, basically).

r? @nnethercote
2020-07-23 11:14:48 +00:00
Vadim Petrochenkov 7be36a86f7 build: Avoid unnecessary build script reruns in libstd
Add a FIXME to build scripts in profiler_builtins
2020-07-22 20:06:37 +03:00
Mark Rousskov cc4f547cf4 Revert "std: Switch from libbacktrace to gimli"
This reverts commit 13db3cc1e8.
2020-07-22 07:16:45 -04:00
Alex Crichton 13db3cc1e8 std: Switch from libbacktrace to gimli
This commit is a proof-of-concept for switching the standard library's
backtrace symbolication mechanism on most platforms from libbacktrace to
gimli. The standard library's support for `RUST_BACKTRACE=1` requires
in-process parsing of object files and DWARF debug information to
interpret it and print the filename/line number of stack frames as part
of a backtrace.

Historically this support in the standard library has come from a
library called "libbacktrace". The libbacktrace library seems to have
been extracted from gcc at some point and is written in C. We've had a
lot of issues with libbacktrace over time, unfortunately, though. The
library does not appear to be actively maintained since we've had
patches sit for months-to-years without comments. We have discovered a
good number of soundness issues with the library itself, both when
parsing valid DWARF as well as invalid DWARF. This is enough of an issue
that the libs team has previously decided that we cannot feed untrusted
inputs to libbacktrace. This also doesn't take into account the
portability of libbacktrace which has been difficult to manage and
maintain over time. While possible there are lots of exceptions and it's
the main C dependency of the standard library right now.

For years it's been the desire to switch over to a Rust-based solution
for symbolicating backtraces. It's been assumed that we'll be using the
Gimli family of crates for this purpose, which are targeted at safely
and efficiently parsing DWARF debug information. I've been working
recently to shore up the Gimli support in the `backtrace` crate. As of a
few weeks ago the `backtrace` crate, by default, uses Gimli when loaded
from crates.io. This transition has gone well enough that I figured it
was time to start talking seriously about this change to the standard
library.

This commit is a preview of what's probably the best way to integrate
the `backtrace` crate into the standard library with the Gimli feature
turned on. While today it's used as a crates.io dependency, this commit
switches the `backtrace` crate to a submodule of this repository which
will need to be updated manually. This is not done lightly, but is
thought to be the best solution. The primary reason for this is that the
`backtrace` crate needs to do some pretty nontrivial filesystem
interactions to locate debug information. Working without `std::fs` is
not an option, and while it might be possible to do some sort of
trait-based solution when prototyped it was found to be too unergonomic.
Using a submodule allows the `backtrace` crate to build as a submodule
of the `std` crate itself, enabling it to use `std::fs` and such.

Otherwise this adds new dependencies to the standard library. This step
requires extra attention because this means that these crates are now
going to be included with all Rust programs by default. It's important
to note, however, that we're already shipping libbacktrace with all Rust
programs by default and it has a bunch of C code implementing all of
this internally anyway, so we're basically already switching
already-shipping functionality to Rust from C.

* `object` - this crate is used to parse object file headers and
  contents. Very low-level support is used from this crate and almost
  all of it is disabled. Largely we're just using struct definitions as
  well as convenience methods internally to read bytes and such.

* `addr2line` - this is the main meat of the implementation for
  symbolication. This crate depends on `gimli` for DWARF parsing and
  then provides interfaces needed by the `backtrace` crate to turn an
  address into a filename / line number. This crate is actually pretty
  small (fits in a single file almost!) and mirrors most of what
  `dwarf.c` does for libbacktrace.

* `miniz_oxide` - the libbacktrace crate transparently handles
  compressed debug information which is compressed with zlib. This crate
  is used to decompress compressed debug sections.

* `gimli` - not actually used directly, but a dependency of `addr2line`.

* `adler32`- not used directly either, but a dependency of
  `miniz_oxide`.

The goal of this change is to improve the safety of backtrace
symbolication in the standard library, especially in the face of
possibly malformed DWARF debug information. Even to this day we're still
seeing segfaults in libbacktrace which could possibly become security
vulnerabilities. This change should almost entirely eliminate this
possibility whilc also paving the way forward to adding more features
like split debug information.

Some references for those interested are:

* Original addition of libbacktrace - #12602
* OOM with libbacktrace - #24231
* Backtrace failure due to use of uninitialized value - #28447
* Possibility to feed untrusted data to libbacktrace - #21889
* Soundness fix for libbacktrace - #33729
* Crash in libbacktrace - #39468
* Support for macOS, never merged - ianlancetaylor/libbacktrace#2
* Performance issues with libbacktrace - #29293, #37477
* Update procedure is quite complicated due to how many patches we
  need to carry - #50955
* Libbacktrace doesn't work on MinGW with dynamic libs - #71060
* Segfault in libbacktrace on macOS - #71397

Switching to Rust will not make us immune to all of these issues. The
crashes are expected to go away, but correctness and performance may
still have bugs arise. The gimli and `backtrace` crates, however, are
actively maintained unlike libbacktrace, so this should enable us to at
least efficiently apply fixes as situations come up.
2020-07-17 14:32:18 -07:00
Eric Huss 0eb293ddb7 Use an allow-list of platforms that support std.
Use a fall-through for no_std targets.
2020-07-15 09:57:10 -07:00
Eric Huss 6e9a1de0d1 Introduce restricted-std feature. 2020-07-15 09:57:05 -07:00
Eric Huss 8c6c1dd3d3 Automatically calculate std::env::consts::ARCH.
This simplifies the definition for ARCH.

Note that this changes asmjs-unknown-emscripten ARCH to `wasm32`,
which reflects the actual target arch.
2020-07-15 08:38:10 -07:00
Patrick Mooney b77aefb76e Add illumos triple
Co-Authored-By: Jason King <jason.brian.king@gmail.com>
Co-Authored-By: Joshua M. Clulow <jmc@oxide.computer>
2020-04-14 20:36:07 +00:00
Stefan Lankes c874789613 remove dependency from libhermit
The build process of the unikernel HermitCore is redesigned and
doesn't longer depend on libhermit.
2019-11-25 08:59:23 +01:00
Stefan Lankes c1e440a90f redesign of the interface to the unikernel HermitCore
- the old interface between HermitCore and the Rust Standard Library
  based on a small C library (newlib)
- remove this interface and call directly the unikernel
- remove the dependency to the HermitCore linker
- use rust-lld as linker
2019-10-06 15:26:14 +00:00
Vadim Petrochenkov 434152157f Remove lint annotations in specific crates that are already enforced by rustbuild
Remove some random unnecessary lint `allow`s
2019-07-28 18:46:24 +03:00
Hugo Beauzée-Luyssen 9407ed759f std: rand: Use BCrypt on UWP
As Rtl* functions are not allowed there
2019-07-25 21:30:08 +02:00
Hugo Beauzée-Luyssen 3becaf4b9b std: Link UWP with allowed libraries only 2019-07-25 21:30:08 +02:00
Marcel Hellwig cc314b066a Remove bitrig support from rust 2019-05-13 11:09:06 +02:00
Taiki Endo 93b6d9e086 libstd => 2018 2019-02-28 04:06:15 +09:00
Mark Rousskov 2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Alex Crichton 8d500572fa std: Use backtrace-sys from crates.io
This commit switches the standard library to using the `backtrace-sys`
crate from crates.io instead of duplicating the logic here in the Rust
repositor with the `backtrace-sys`'s crate's logic.

Eventually this will hopefully be a good step towards using the
`backtrace` crate directly from crates.io itself, but we're not quite
there yet! Hopefully this is a small incremental first step we can take.
2018-12-24 08:32:57 -08:00
bors 7d03617bab Auto merge of #56568 - notriddle:master, r=alexcrichton
Remove dependency on shell32.dll

Closes #56510 if it works on MinGW (I've only tested it on MSVC).
2018-12-14 13:44:15 +00:00
Alex Crichton 4c21a3bc2a std: Depend directly on crates.io crates
Ever since we added a Cargo-based build system for the compiler the
standard library has always been a little special, it's never been able
to depend on crates.io crates for runtime dependencies. This has been a
result of various limitations, namely that Cargo doesn't understand that
crates from crates.io depend on libcore, so Cargo tries to build crates
before libcore is finished.

I had an idea this afternoon, however, which lifts the strategy
from #52919 to directly depend on crates.io crates from the standard
library. After all is said and done this removes a whopping three
submodules that we need to manage!

The basic idea here is that for any crate `std` depends on it adds an
*optional* dependency on an empty crate on crates.io, in this case named
`rustc-std-workspace-core`. This crate is overridden via `[patch]` in
this repository to point to a local crate we write, and *that* has a
`path` dependency on libcore.

Note that all `no_std` crates also depend on `compiler_builtins`, but if
we're not using submodules we can publish `compiler_builtins` to
crates.io and all crates can depend on it anyway! The basic strategy
then looks like:

* The standard library (or some transitive dep) decides to depend on a
  crate `foo`.
* The standard library adds

  ```toml
  [dependencies]
  foo = { version = "0.1", features = ['rustc-dep-of-std'] }
  ```
* The crate `foo` has an optional dependency on `rustc-std-workspace-core`
* The crate `foo` has an optional dependency on `compiler_builtins`
* The crate `foo` has a feature `rustc-dep-of-std` which activates these
  crates and any other necessary infrastructure in the crate.

A sample commit for `dlmalloc` [turns out to be quite simple][commit].
After that all `no_std` crates should largely build "as is" and still be
publishable on crates.io! Notably they should be able to continue to use
stable Rust if necessary, since the `rename-dependency` feature of Cargo
is soon stabilizing.

As a proof of concept, this commit removes the `dlmalloc`,
`libcompiler_builtins`, and `libc` submodules from this repository. Long
thorns in our side these are now gone for good and we can directly
depend on crates.io! It's hoped that in the long term we can bring in
other crates as necessary, but for now this is largely intended to
simply make it easier to manage these crates and remove submodules.

This should be a transparent non-breaking change for all users, but one
possible stickler is that this almost for sure breaks out-of-tree
`std`-building tools like `xargo` and `cargo-xbuild`. I think it should
be relatively easy to get them working, however, as all that's needed is
an entry in the `[patch]` section used to build the standard library.
Hopefully we can work with these tools to solve this problem!

[commit]: 28ee12db81
2018-12-11 21:08:22 -08:00
Michael Howell 81de5d9519 Remove dependency on shell32.dll #56510 2018-12-10 12:09:50 -07:00
Jonathan A. Kollasch 2d368b5de8 NetBSD: link libstd with librt in addition to libpthread 2018-11-02 17:41:36 +00:00
ljedrz d28aed6dc4 Prefer unwrap_or_else to unwrap_or in case of function calls/allocations 2018-10-19 09:45:45 +02:00
Alex Crichton 5595aeb6b7 Add rustc SHA to released DWARF debuginfo
This commit updates the debuginfo that is encoded in all of our released
artifacts by default. Currently it has paths like `/checkout/src/...` but these
are a little inconsistent and have changed over time. This commit instead
attempts to actually define the file paths in our debuginfo to be consistent
between releases.

All debuginfo paths are now intended to be `/rustc/$sha` where `$sha` is the git
sha of the released compiler. Sub-paths are all paths into the git repo at that
`$sha`.
2018-09-10 10:10:38 -07:00
Josh Stone e0d8364dad std: Use target_pointer_width for BACKTRACE_ELF_SIZE
The former code used `target.contains("64")` to detect Elf64 targets,
but this is inaccurate in a few cases:

- `s390x-unknown-linux-gnu` is 64-bit
- `sparcv9-sun-solaris` is 64-bit
- `x86_64-unknown-linux-gnux32` is 32-bit

Instead the `std` build script can use `CARGO_CFG_TARGET_POINTER_WIDTH`
to reliably detect 64-bit targets for libbacktrace.

Also update to backtrace-sys 0.1.24 for alexcrichton/backtrace-rs#122.
2018-08-14 21:08:42 -07:00
bors e06c875442 Auto merge of #51757 - nielx:fix/haiku-fixes, r=nagisa
Haiku: several smaller fixes to build and run rust on Haiku

This PR combines three small patches that help Rust build and run on the Haiku platform. These patches do not intend to impact other platforms.
2018-07-06 20:05:23 +00:00
Taylor Cramer 3265189b68 Use in-tree libbacktrace on Fuchsia 2018-06-29 18:04:26 -07:00
Niels Sascha Reedijk 990b3c8d9d Haiku: fix build of libbacktrace 2018-06-24 17:00:19 +02:00
Adam Barth 0c6cd26aec [fuchsia] Migrate from launchpad to fdio_spawn_etc
fdio_spawn_etc is the preferred way of creating processes on Fuchsia
now.
2018-06-07 09:22:59 -07:00
Alex Crichton 7c14a54bc8 Replace libbacktrace with a submodule
While we're at it update the `backtrace` crate from crates.io. It turns out that
the submodule's configure script has gotten a lot more finnicky as of late so
also switch over to using the `cc` crate manually which allows to avoid some
hacks around the configure script as well
2018-05-30 05:58:23 -07:00
Alex Crichton 0e0f74bcf9 rustc: Embed LLVM bitcode by default on iOS
This commit updates rustc to embed bitcode in each object file generated by
default when compiling for iOS. This was determined in #35968 as a step
towards better compatibility with the iOS toolchain, so let's give it a spin and
see how it turns out!

Note that this also updates the `cc` dependency which should propagate this
change of embedding bitcode for C dependencies as well.
2018-03-13 08:29:19 -07:00
Alex Crichton 1999a3fb41 rustbuild: Tweak CFLAGS to various libstd pieces
* Pass `opt_level(2)` when calculating CFLAGS to get the right flags on iOS
* Unconditionally pass `-O2` when compiling libbacktrace

This should...

Close #48903
Close #48906
2018-03-13 08:28:27 -07:00
Ed Schouten 146fe0ad75 Add proper library dependencies for libstd on CloudABI.
Don't attempt to build libunwind on CloudABI, as libunwind is already
provided by the system by default.
2017-12-29 09:33:26 +01:00
kennytm 2566fa25c7
Revert "Add a file to trivially disable tool building or testing"
This reverts commit ab018c76e1.

This also adds the `ToolBuild::is_ext_tool` field to replace the previous
`ToolBuild::expectation` field, to indicate whether a build-failure of
certain tool is essential.
2017-12-27 00:00:45 +08:00
Alex Crichton 80ff0f74b0 std: Add a new wasm32-unknown-unknown target
This commit adds a new target to the compiler: wasm32-unknown-unknown. This
target is a reimagining of what it looks like to generate WebAssembly code from
Rust. Instead of using Emscripten which can bring with it a weighty runtime this
instead is a target which uses only the LLVM backend for WebAssembly and a
"custom linker" for now which will hopefully one day be direct calls to lld.

Notable features of this target include:

* There is zero runtime footprint. The target assumes nothing exists other than
  the wasm32 instruction set.
* There is zero toolchain footprint beyond adding the target. No custom linker
  is needed, rustc contains everything.
* Very small wasm modules can be generated directly from Rust code using this
  target.
* Most of the standard library is stubbed out to return an error, but anything
  related to allocation works (aka `HashMap`, `Vec`, etc).
* Naturally, any `#[no_std]` crate should be 100% compatible with this new
  target.

This target is currently somewhat janky due to how linking works. The "linking"
is currently unconditional whole program LTO (aka LLVM is being used as a
linker). Naturally that means compiling programs is pretty slow! Eventually
though this target should have a linker.

This target is also intended to be quite experimental. I'm hoping that this can
act as a catalyst for further experimentation in Rust with WebAssembly. Breaking
changes are very likely to land to this target, so it's not recommended to rely
on it in any critical capacity yet. We'll let you know when it's "production
ready".

---

Currently testing-wise this target is looking pretty good but isn't complete.
I've got almost the entire `run-pass` test suite working with this target (lots
of tests ignored, but many passing as well). The `core` test suite is still
getting LLVM bugs fixed to get that working and will take some time. Relatively
simple programs all seem to work though!

---

It's worth nothing that you may not immediately see the "smallest possible wasm
module" for the input you feed to rustc. For various reasons it's very difficult
to get rid of the final "bloat" in vanilla rustc (again, a real linker should
fix all this). For now what you'll have to do is:

    cargo install --git https://github.com/alexcrichton/wasm-gc
    wasm-gc foo.wasm bar.wasm

And then `bar.wasm` should be the smallest we can get it!

---

In any case for now I'd love feedback on this, particularly on the various
integration points if you've got better ideas of how to approach them!
2017-11-19 21:07:41 -08:00
Vadim Petrochenkov 9e0fc5ccd0 rustbuild: Support specifying archiver and linker explicitly 2017-10-15 22:10:07 +03:00
Alex Crichton 7694ca419b Update to the cc crate
This is the name the `gcc` crate has moved to
2017-09-28 07:45:50 -07:00
P.Y. Laligand 43cff131dd The Magenta kernel is now called Zircon. 2017-09-24 13:53:10 -07:00
Oliver Schneider ab018c76e1
Add a file to trivially disable tool building or testing 2017-09-17 21:41:45 +02:00
bors ddd123ed9a Auto merge of #44251 - kennytm:osx-backtrace, r=alexcrichton
Add libbacktrace support for Apple platforms (resubmitted)

Resubmitting #43422 rebased on the current master (cc @JohnColanduoni).

I have added an additional commit to fallback to `dladdr`-based `resolve_symbol` if `libbacktrace` returns `None`, otherwise the stack trace will be full of `<unknown>` when you forget to pass the `-g` flag (actually it seems — at least on macOS — the `dladdr` symbol is more accurate than the `libbacktrace` one).
2017-09-09 17:32:13 +00:00
Ralf Jung 12d84cc009 update gcc crate
Use gcc::Build rather than deprecated gcc::Config.
Fixes #43973
2017-09-02 21:51:18 +02:00
John Colanduoni e8121b3d16
Add libbacktrace support for Apple platforms 2017-09-02 03:24:15 +08:00
Samuel Holland 15c141ce05 Remove incorrect special case of mips-musl
The libdl/librt/libpthread provided by musl are no-op (empty static
libraries) on all architectures, mips included.
2017-08-22 16:24:29 -05:00
Ian Douglas Scott 2fd4663fee
Make backtraces work on Redox, copying Unix implementation 2017-08-03 21:13:44 -07:00
Danek Duvall ea23e50fcb DNS functions are in libresolv on Solaris, just like on MacOS 2017-07-24 15:57:57 -07:00
Nikita Baksalyar e084bb2abc
Fix Rustbuild linking on Illumos
Illumos (an OpenSolaris fork) expects to get several
extra library references for some system functions used
by Rust standard library. This commit adds required linker
options to rustbuild, which is currently doesn't work on
Illumos-based operating systems.
2017-07-07 08:32:18 +03:00
Jon Gjengset 68ae6173fe
Reload nameserver information on lookup failure
As discussed in #41570, UNIX systems often cache the contents of
/etc/resolv.conf, which can cause lookup failures to persist even after
a network connection becomes available. This patch modifies lookup_host
to force a reload of the nameserver entries following a lookup failure.
This is in line with what many C programs already do (see #41570 for
details). On systems with nscd, this should not be necessary, but not
all systems run nscd.

Introduces an std linkage dependency on libresolv on macOS/iOS (which
also makes it necessary to update run-make/tools.mk).

Fixes #41570.
Depends on rust-lang/libc#585.
2017-05-04 23:59:55 -04:00
Vadim Petrochenkov 428f063fcd Automate timestamp creation and build skipping for native libraries
Add comments
2017-03-04 21:38:26 +03:00
Vadim Petrochenkov aeadc81ddc Build compiler-rt and sanitizers only once 2017-03-04 21:38:26 +03:00
Vadim Petrochenkov f2187093f8 Add/remove rerun-if-changed when necessary 2017-03-04 21:38:26 +03:00