Skip to content

Commit

Permalink
Auto merge of #95338 - bjorn3:sync_cg_gcc-2022-03-26, r=antoyo
Browse files Browse the repository at this point in the history
Sync rustc_codegen_gcc

r? `@ghost`

`@rustbot` label +A-codegen +A-gcc +T-compiler

cc `@antoyo`
  • Loading branch information
bors committed Mar 27, 2022
2 parents 551b4fa + bbff48e commit 06c3c62
Show file tree
Hide file tree
Showing 35 changed files with 1,705 additions and 558 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,43 @@ jobs:

strategy:
fail-fast: false
matrix:
libgccjit_version: ["libgccjit.so", "libgccjit_without_int128.so"]

steps:
- uses: actions/checkout@v2

- uses: actions/checkout@v2
with:
repository: llvm/llvm-project
path: llvm

- name: Install packages
run: sudo apt-get install ninja-build ripgrep

- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow: main.yml
name: libgccjit.so
name: ${{ matrix.libgccjit_version }}
path: gcc-build
repo: antoyo/gcc
search_artifacts: true # Because, instead, the action only check the last job ran and that won't work since we want multiple artifacts.

- name: Setup path to libgccjit
run: |
echo $(readlink -f gcc-build) > gcc_path
# NOTE: the filename is still libgccjit.so even when the artifact name is different.
ln gcc-build/libgccjit.so gcc-build/libgccjit.so.0
- name: Set LIBRARY_PATH
- name: Set env
run: |
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
- name: Set RUST_COMPILER_RT_ROOT
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV

# https://github.com/actions/cache/issues/133
- name: Fixup owner of ~/.cargo/
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_gcc/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ gimple*
res
test-backend
gcc_path
benchmarks
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_gcc/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ dependencies = [
[[package]]
name = "gccjit"
version = "1.0.0"
source = "git+https://github.com/antoyo/gccjit.rs#0672b78d162d65b6f36ea4062947253affe9fdef"
source = "git+https://github.com/antoyo/gccjit.rs#bdecdecfb8a02ec861a39a350f990faa33bd31c3"
dependencies = [
"gccjit_sys",
]

[[package]]
name = "gccjit_sys"
version = "0.0.1"
source = "git+https://github.com/antoyo/gccjit.rs#0672b78d162d65b6f36ea4062947253affe9fdef"
source = "git+https://github.com/antoyo/gccjit.rs#bdecdecfb8a02ec861a39a350f990faa33bd31c3"
dependencies = [
"libc 0.1.12",
]
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_codegen_gcc/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ You can also use my [fork of gcc](https://github.com/antoyo/gcc) which already i
```bash
$ git clone https://github.com/rust-lang/rustc_codegen_gcc.git
$ cd rustc_codegen_gcc
$ git clone https://github.com/llvm/llvm-project llvm --depth 1 --single-branch
$ export RUST_COMPILER_RT_ROOT="$PWD/llvm/compiler-rt"
$ ./prepare_build.sh # download and patch sysroot src
$ ./build.sh --release
```
Expand Down Expand Up @@ -109,6 +111,13 @@ Or add a breakpoint to `add_error` in gdb and print the line number using:
```
p loc->m_line
p loc->m_filename->m_buffer
```
To print a debug representation of a tree:
```c
debug_tree(expr);
```

To get the `rustc` command to run in `gdb`, add the `--verbose` flag to `cargo build`.
Expand All @@ -134,4 +143,5 @@ To get the `rustc` command to run in `gdb`, add the `--verbose` flag to `cargo b
* Set `linker='-Clinker=m68k-linux-gcc'`.
* Set the path to the cross-compiling libgccjit in `gcc_path`.
* Disable the 128-bit integer types if the target doesn't support them by using `let i128_type = context.new_type::<i64>();` in `context.rs` (same for u128_type).
* Comment the line: `context.add_command_line_option("-masm=intel");` in src/base.rs.
* (might not be necessary) Disable the compilation of libstd.so (and possibly libcore.so?).
43 changes: 38 additions & 5 deletions compiler/rustc_codegen_gcc/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,27 @@
#set -x
set -e

if [ -f ./gcc_path ]; then
codegen_channel=debug
sysroot_channel=debug

while [[ $# -gt 0 ]]; do
case $1 in
--release)
codegen_channel=release
shift
;;
--release-sysroot)
sysroot_channel=release
shift
;;
*)
echo "Unknown option $1"
exit 1
;;
esac
done

if [ -f ./gcc_path ]; then
export GCC_PATH=$(cat gcc_path)
else
echo 'Please put the path to your custom build of libgccjit in the file `gcc_path`, see Readme.md for details'
Expand All @@ -13,13 +33,21 @@ fi
export LD_LIBRARY_PATH="$GCC_PATH"
export LIBRARY_PATH="$GCC_PATH"

if [[ "$1" == "--release" ]]; then
features=

if [[ "$1" == "--features" ]]; then
shift
features="--features $1"
shift
fi

if [[ "$codegen_channel" == "release" ]]; then
export CHANNEL='release'
CARGO_INCREMENTAL=1 cargo rustc --release
CARGO_INCREMENTAL=1 cargo rustc --release $features
else
echo $LD_LIBRARY_PATH
export CHANNEL='debug'
cargo rustc
cargo rustc $features
fi

source config.sh
Expand All @@ -28,4 +56,9 @@ rm -r target/out || true
mkdir -p target/out/gccjit

echo "[BUILD] sysroot"
time ./build_sysroot/build_sysroot.sh $CHANNEL
if [[ "$sysroot_channel" == "release" ]]; then
time ./build_sysroot/build_sysroot.sh --release
else
time ./build_sysroot/build_sysroot.sh
fi

2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/build_sysroot/build_sysroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if [[ "$1" == "--release" ]]; then
RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3" cargo build --target $TARGET_TRIPLE --release
else
sysroot_channel='debug'
cargo build --target $TARGET_TRIPLE
cargo build --target $TARGET_TRIPLE --features compiler_builtins/c
fi

# Copy files to sysroot
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/cargo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pushd $(dirname "$0") >/dev/null
source config.sh

# read nightly compiler from rust-toolchain file
TOOLCHAIN=$(cat rust-toolchain)
TOOLCHAIN=$(cat rust-toolchain | grep channel | sed 's/channel = "\(.*\)"/\1/')

popd >/dev/null

Expand Down
20 changes: 17 additions & 3 deletions compiler/rustc_codegen_gcc/example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ unsafe extern "C" fn _Unwind_Resume() {
#[lang = "sized"]
pub trait Sized {}

#[lang = "destruct"]
pub trait Destruct {}

#[lang = "unsize"]
pub trait Unsize<T: ?Sized> {}

Expand Down Expand Up @@ -59,6 +62,7 @@ unsafe impl Copy for i16 {}
unsafe impl Copy for i32 {}
unsafe impl Copy for isize {}
unsafe impl Copy for f32 {}
unsafe impl Copy for f64 {}
unsafe impl Copy for char {}
unsafe impl<'a, T: ?Sized> Copy for &'a T {}
unsafe impl<T: ?Sized> Copy for *const T {}
Expand Down Expand Up @@ -443,12 +447,22 @@ pub trait Deref {
fn deref(&self) -> &Self::Target;
}

pub trait Allocator {
}

pub struct Global;

impl Allocator for Global {}

#[lang = "owned_box"]
pub struct Box<T: ?Sized>(*mut T);
pub struct Box<
T: ?Sized,
A: Allocator = Global,
>(*mut T, A);

impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}

impl<T: ?Sized> Drop for Box<T> {
impl<T: ?Sized, A: Allocator> Drop for Box<T, A> {
fn drop(&mut self) {
// drop is currently performed by compiler.
}
Expand All @@ -468,7 +482,7 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
}

#[lang = "box_free"]
unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
unsafe fn box_free<T: ?Sized, A: Allocator>(ptr: *mut T, alloc: A) {
libc::free(ptr as *mut u8);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ index 0000000..46fd999
+[package]
+name = "core"
+version = "0.0.0"
+edition = "2018"
+edition = "2021"
+
+[lib]
+name = "coretests"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,4 @@ index 4bc44e9..8e3c7a4 100644

#[test]
fn cell_allows_array_cycle() {
diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs
index 3e00e0a..8e5663b 100644
--- a/library/core/tests/slice.rs
+++ b/library/core/tests/slice.rs
@@ -2108,6 +2108,7 @@ fn test_copy_within_panics_src_out_of_bounds() {
bytes.copy_within(usize::MAX..=usize::MAX, 0);
}

+/*
#[test]
fn test_is_sorted() {
let empty: [i32; 0] = [];
@@ -2122,6 +2123,7 @@ fn test_is_sorted() {
assert!(!["c", "bb", "aaa"].is_sorted());
assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
}
+*/

#[test]
fn test_slice_run_destructors() {
-- 2.21.0 (Apple Git-122)
Loading

0 comments on commit 06c3c62

Please sign in to comment.