Skip to content

Commit 06c3c62

Browse files
committed
Auto merge of rust-lang#95338 - bjorn3:sync_cg_gcc-2022-03-26, r=antoyo
Sync rustc_codegen_gcc r? `@ghost` `@rustbot` label +A-codegen +A-gcc +T-compiler cc `@antoyo`
2 parents 551b4fa + bbff48e commit 06c3c62

35 files changed

+1705
-558
lines changed

compiler/rustc_codegen_gcc/.github/workflows/main.yml compiler/rustc_codegen_gcc/.github/workflows/ci.yml

+15-2
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,43 @@ jobs:
1010

1111
strategy:
1212
fail-fast: false
13+
matrix:
14+
libgccjit_version: ["libgccjit.so", "libgccjit_without_int128.so"]
1315

1416
steps:
1517
- uses: actions/checkout@v2
1618

19+
- uses: actions/checkout@v2
20+
with:
21+
repository: llvm/llvm-project
22+
path: llvm
23+
1724
- name: Install packages
1825
run: sudo apt-get install ninja-build ripgrep
1926

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

2836
- name: Setup path to libgccjit
2937
run: |
3038
echo $(readlink -f gcc-build) > gcc_path
39+
# NOTE: the filename is still libgccjit.so even when the artifact name is different.
3140
ln gcc-build/libgccjit.so gcc-build/libgccjit.so.0
3241
33-
- name: Set LIBRARY_PATH
42+
- name: Set env
3443
run: |
3544
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
3645
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
46+
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
47+
48+
- name: Set RUST_COMPILER_RT_ROOT
49+
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV
3750

3851
# https://github.com/actions/cache/issues/133
3952
- name: Fixup owner of ~/.cargo/

compiler/rustc_codegen_gcc/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ gimple*
1818
res
1919
test-backend
2020
gcc_path
21+
benchmarks

compiler/rustc_codegen_gcc/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ dependencies = [
4141
[[package]]
4242
name = "gccjit"
4343
version = "1.0.0"
44-
source = "git+https://github.com/antoyo/gccjit.rs#0672b78d162d65b6f36ea4062947253affe9fdef"
44+
source = "git+https://github.com/antoyo/gccjit.rs#bdecdecfb8a02ec861a39a350f990faa33bd31c3"
4545
dependencies = [
4646
"gccjit_sys",
4747
]
4848

4949
[[package]]
5050
name = "gccjit_sys"
5151
version = "0.0.1"
52-
source = "git+https://github.com/antoyo/gccjit.rs#0672b78d162d65b6f36ea4062947253affe9fdef"
52+
source = "git+https://github.com/antoyo/gccjit.rs#bdecdecfb8a02ec861a39a350f990faa33bd31c3"
5353
dependencies = [
5454
"libc 0.1.12",
5555
]

compiler/rustc_codegen_gcc/Readme.md

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ You can also use my [fork of gcc](https://github.com/antoyo/gcc) which already i
2121
```bash
2222
$ git clone https://github.com/rust-lang/rustc_codegen_gcc.git
2323
$ cd rustc_codegen_gcc
24+
$ git clone https://github.com/llvm/llvm-project llvm --depth 1 --single-branch
25+
$ export RUST_COMPILER_RT_ROOT="$PWD/llvm/compiler-rt"
2426
$ ./prepare_build.sh # download and patch sysroot src
2527
$ ./build.sh --release
2628
```
@@ -109,6 +111,13 @@ Or add a breakpoint to `add_error` in gdb and print the line number using:
109111
110112
```
111113
p loc->m_line
114+
p loc->m_filename->m_buffer
115+
```
116+
117+
To print a debug representation of a tree:
118+
119+
```c
120+
debug_tree(expr);
112121
```
113122

114123
To get the `rustc` command to run in `gdb`, add the `--verbose` flag to `cargo build`.
@@ -134,4 +143,5 @@ To get the `rustc` command to run in `gdb`, add the `--verbose` flag to `cargo b
134143
* Set `linker='-Clinker=m68k-linux-gcc'`.
135144
* Set the path to the cross-compiling libgccjit in `gcc_path`.
136145
* 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).
146+
* Comment the line: `context.add_command_line_option("-masm=intel");` in src/base.rs.
137147
* (might not be necessary) Disable the compilation of libstd.so (and possibly libcore.so?).

compiler/rustc_codegen_gcc/build.sh

+38-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,27 @@
33
#set -x
44
set -e
55

6-
if [ -f ./gcc_path ]; then
6+
codegen_channel=debug
7+
sysroot_channel=debug
8+
9+
while [[ $# -gt 0 ]]; do
10+
case $1 in
11+
--release)
12+
codegen_channel=release
13+
shift
14+
;;
15+
--release-sysroot)
16+
sysroot_channel=release
17+
shift
18+
;;
19+
*)
20+
echo "Unknown option $1"
21+
exit 1
22+
;;
23+
esac
24+
done
25+
26+
if [ -f ./gcc_path ]; then
727
export GCC_PATH=$(cat gcc_path)
828
else
929
echo 'Please put the path to your custom build of libgccjit in the file `gcc_path`, see Readme.md for details'
@@ -13,13 +33,21 @@ fi
1333
export LD_LIBRARY_PATH="$GCC_PATH"
1434
export LIBRARY_PATH="$GCC_PATH"
1535

16-
if [[ "$1" == "--release" ]]; then
36+
features=
37+
38+
if [[ "$1" == "--features" ]]; then
39+
shift
40+
features="--features $1"
41+
shift
42+
fi
43+
44+
if [[ "$codegen_channel" == "release" ]]; then
1745
export CHANNEL='release'
18-
CARGO_INCREMENTAL=1 cargo rustc --release
46+
CARGO_INCREMENTAL=1 cargo rustc --release $features
1947
else
2048
echo $LD_LIBRARY_PATH
2149
export CHANNEL='debug'
22-
cargo rustc
50+
cargo rustc $features
2351
fi
2452

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

3058
echo "[BUILD] sysroot"
31-
time ./build_sysroot/build_sysroot.sh $CHANNEL
59+
if [[ "$sysroot_channel" == "release" ]]; then
60+
time ./build_sysroot/build_sysroot.sh --release
61+
else
62+
time ./build_sysroot/build_sysroot.sh
63+
fi
64+

compiler/rustc_codegen_gcc/build_sysroot/build_sysroot.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if [[ "$1" == "--release" ]]; then
2222
RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3" cargo build --target $TARGET_TRIPLE --release
2323
else
2424
sysroot_channel='debug'
25-
cargo build --target $TARGET_TRIPLE
25+
cargo build --target $TARGET_TRIPLE --features compiler_builtins/c
2626
fi
2727

2828
# Copy files to sysroot

compiler/rustc_codegen_gcc/cargo.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pushd $(dirname "$0") >/dev/null
88
source config.sh
99

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

1313
popd >/dev/null
1414

compiler/rustc_codegen_gcc/example/mini_core.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ unsafe extern "C" fn _Unwind_Resume() {
1414
#[lang = "sized"]
1515
pub trait Sized {}
1616

17+
#[lang = "destruct"]
18+
pub trait Destruct {}
19+
1720
#[lang = "unsize"]
1821
pub trait Unsize<T: ?Sized> {}
1922

@@ -59,6 +62,7 @@ unsafe impl Copy for i16 {}
5962
unsafe impl Copy for i32 {}
6063
unsafe impl Copy for isize {}
6164
unsafe impl Copy for f32 {}
65+
unsafe impl Copy for f64 {}
6266
unsafe impl Copy for char {}
6367
unsafe impl<'a, T: ?Sized> Copy for &'a T {}
6468
unsafe impl<T: ?Sized> Copy for *const T {}
@@ -443,12 +447,22 @@ pub trait Deref {
443447
fn deref(&self) -> &Self::Target;
444448
}
445449

450+
pub trait Allocator {
451+
}
452+
453+
pub struct Global;
454+
455+
impl Allocator for Global {}
456+
446457
#[lang = "owned_box"]
447-
pub struct Box<T: ?Sized>(*mut T);
458+
pub struct Box<
459+
T: ?Sized,
460+
A: Allocator = Global,
461+
>(*mut T, A);
448462

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

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

470484
#[lang = "box_free"]
471-
unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
485+
unsafe fn box_free<T: ?Sized, A: Allocator>(ptr: *mut T, alloc: A) {
472486
libc::free(ptr as *mut u8);
473487
}
474488

compiler/rustc_codegen_gcc/patches/0022-core-Disable-not-compiling-tests.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ index 0000000..46fd999
2222
+[package]
2323
+name = "core"
2424
+version = "0.0.0"
25-
+edition = "2018"
25+
+edition = "2021"
2626
+
2727
+[lib]
2828
+name = "coretests"

compiler/rustc_codegen_gcc/patches/0023-core-Ignore-failing-tests.patch

-20
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,4 @@ index 4bc44e9..8e3c7a4 100644
4646

4747
#[test]
4848
fn cell_allows_array_cycle() {
49-
diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs
50-
index 3e00e0a..8e5663b 100644
51-
--- a/library/core/tests/slice.rs
52-
+++ b/library/core/tests/slice.rs
53-
@@ -2108,6 +2108,7 @@ fn test_copy_within_panics_src_out_of_bounds() {
54-
bytes.copy_within(usize::MAX..=usize::MAX, 0);
55-
}
56-
57-
+/*
58-
#[test]
59-
fn test_is_sorted() {
60-
let empty: [i32; 0] = [];
61-
@@ -2122,6 +2123,7 @@ fn test_is_sorted() {
62-
assert!(!["c", "bb", "aaa"].is_sorted());
63-
assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
64-
}
65-
+*/
66-
67-
#[test]
68-
fn test_slice_run_destructors() {
6949
-- 2.21.0 (Apple Git-122)

0 commit comments

Comments
 (0)