Skip to content

Commit df48731

Browse files
committed
Merge commit '48d60ab7c505c6c1ebb042eacaafd8dc9f7a9267' into libgccjit-codegen
2 parents 87f8525 + 48d60ab commit df48731

24 files changed

+735
-348
lines changed

compiler/rustc_codegen_gcc/.github/FUNDING.yml

-2
This file was deleted.

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ jobs:
3131
ln gcc-build/libgccjit.so gcc-build/libgccjit.so.0
3232
3333
- name: Set LIBRARY_PATH
34-
run: echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
34+
run: |
35+
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
36+
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
3537
3638
# https://github.com/actions/cache/issues/133
3739
- name: Fixup owner of ~/.cargo/
@@ -66,6 +68,7 @@ jobs:
6668
run: |
6769
./prepare_build.sh
6870
./build.sh
71+
cargo test
6972
./clean_all.sh
7073
7174
- name: Prepare dependencies

compiler/rustc_codegen_gcc/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ perf.data.old
77
*.events
88
*.string*
99
/build_sysroot/sysroot
10+
/build_sysroot/sysroot_src
1011
/build_sysroot/Cargo.lock
1112
/build_sysroot/test_target/Cargo.lock
1213
/rust
14+
/simple-raytracer
1315
/regex
1416
gimple*
1517
*asm
1618
res
1719
test-backend
20+
gcc_path

compiler/rustc_codegen_gcc/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ dependencies = [
5656
[[package]]
5757
name = "gccjit"
5858
version = "1.0.0"
59-
source = "git+https://github.com/antoyo/gccjit.rs#0572117c7ffdfcb0e6c6526d45266c3f34796bea"
59+
source = "git+https://github.com/antoyo/gccjit.rs#54be27e41fff7b6ab532e2e21a82df50a12b9ad3"
6060
dependencies = [
6161
"gccjit_sys",
6262
]
6363

6464
[[package]]
6565
name = "gccjit_sys"
6666
version = "0.0.1"
67-
source = "git+https://github.com/antoyo/gccjit.rs#0572117c7ffdfcb0e6c6526d45266c3f34796bea"
67+
source = "git+https://github.com/antoyo/gccjit.rs#54be27e41fff7b6ab532e2e21a82df50a12b9ad3"
6868
dependencies = [
6969
"libc 0.1.12",
7070
]

compiler/rustc_codegen_gcc/Readme.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ You can also use my [fork of gcc](https://github.com/antoyo/gcc) which already i
1919
**Put the path to your custom build of libgccjit in the file `gcc_path`.**
2020

2121
```bash
22-
$ git clone https://github.com/antoyo/rustc_codegen_gcc.git
22+
$ git clone https://github.com/rust-lang/rustc_codegen_gcc.git
2323
$ cd rustc_codegen_gcc
2424
$ ./prepare_build.sh # download and patch sysroot src
2525
$ ./build.sh --release
@@ -113,6 +113,5 @@ p loc->m_line
113113
114114
### How to use a custom-build rustc
115115
116-
* Build the stage1 compiler (`rustup toolchain link debug-current stage2 build/x86_64-unknown-linux-gnu/stage1`).
116+
* Build the stage2 compiler (`rustup toolchain link debug-current build/x86_64-unknown-linux-gnu/stage2`).
117117
* Clean and rebuild the codegen with `debug-current` in the file `rust-toolchain`.
118-
* Add `~/.rustup/toolchains/debug-current/lib/rustlib/x86_64-unknown-linux-gnu/lib` to `LD_LIBRARY_PATH`.

compiler/rustc_codegen_gcc/build.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
#set -x
44
set -e
55

6-
export GCC_PATH=$(cat gcc_path)
6+
if [ -f ./gcc_path ]; then
7+
export GCC_PATH=$(cat gcc_path)
8+
else
9+
echo 'Please put the path to your custom build of libgccjit in the file `gcc_path`, see Readme.md for details'
10+
exit 1
11+
fi
712

813
export LD_LIBRARY_PATH="$GCC_PATH"
914
export LIBRARY_PATH="$GCC_PATH"

compiler/rustc_codegen_gcc/cargo.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ fi
2020
cmd=$1
2121
shift
2222

23-
RUSTDOCFLAGS=$RUSTFLAGS cargo +${TOOLCHAIN} $cmd --target $TARGET_TRIPLE $@
23+
RUSTDOCFLAGS="$RUSTFLAGS" cargo +${TOOLCHAIN} $cmd --target $TARGET_TRIPLE $@

compiler/rustc_codegen_gcc/config.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ set -e
22

33
export CARGO_INCREMENTAL=0
44

5-
export GCC_PATH=$(cat gcc_path)
5+
if [ -f ./gcc_path ]; then
6+
export GCC_PATH=$(cat gcc_path)
7+
else
8+
echo 'Please put the path to your custom build of libgccjit in the file `gcc_path`, see Readme.md for details'
9+
exit 1
10+
fi
611

712
unamestr=`uname`
813
if [[ "$unamestr" == 'Linux' ]]; then
@@ -30,7 +35,7 @@ if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
3035
fi
3136
fi
3237

33-
export RUSTFLAGS=$linker' -Cpanic=abort -Cdebuginfo=2 -Zpanic-abort-tests -Zcodegen-backend='$(pwd)'/target/'$CHANNEL'/librustc_codegen_gcc.'$dylib_ext' --sysroot '$(pwd)'/build_sysroot/sysroot'
38+
export RUSTFLAGS="$linker -Cpanic=abort -Cdebuginfo=2 -Clto=off -Zpanic-abort-tests -Zcodegen-backend=$(pwd)/target/${CHANNEL:-debug}/librustc_codegen_gcc.$dylib_ext --sysroot $(pwd)/build_sysroot/sysroot"
3439

3540
# FIXME(antoyo): remove once the atomic shim is gone
3641
if [[ `uname` == 'Darwin' ]]; then

compiler/rustc_codegen_gcc/gcc_path

Whitespace-only changes.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2021-08-12
1+
nightly-2021-09-17

compiler/rustc_codegen_gcc/src/allocator.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_span::symbol::sym;
66

77
use crate::GccContext;
88

9-
pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, kind: AllocatorKind, has_alloc_error_handler: bool) {
9+
pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_name: &str, kind: AllocatorKind, has_alloc_error_handler: bool) {
1010
let context = &mods.context;
1111
let usize =
1212
match tcx.sess.target.pointer_width {
@@ -77,6 +77,9 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, kind: Alloc
7777
else {
7878
block.end_with_void_return(None);
7979
}
80+
81+
// TODO(@Commeownist): Check if we need to emit some extra debugging info in certain circumstances
82+
// as described in https://github.com/rust-lang/rust/commit/77a96ed5646f7c3ee8897693decc4626fe380643
8083
}
8184

8285
let types = [usize, usize];

compiler/rustc_codegen_gcc/src/archive.rs

+21-73
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ use std::fs::File;
22
use std::path::{Path, PathBuf};
33

44
use rustc_session::Session;
5-
use rustc_codegen_ssa::back::archive::{find_library, ArchiveBuilder};
6-
use rustc_codegen_ssa::METADATA_FILENAME;
5+
use rustc_codegen_ssa::back::archive::ArchiveBuilder;
6+
77
use rustc_data_structures::temp_dir::MaybeTempDir;
88
use rustc_middle::middle::cstore::DllImport;
9-
use rustc_span::symbol::Symbol;
9+
1010

1111
struct ArchiveConfig<'a> {
1212
sess: &'a Session,
1313
dst: PathBuf,
14-
lib_search_paths: Vec<PathBuf>,
1514
use_native_ar: bool,
1615
use_gnu_style_archive: bool,
1716
}
@@ -35,11 +34,9 @@ pub struct ArArchiveBuilder<'a> {
3534

3635
impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
3736
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self {
38-
use rustc_codegen_ssa::back::link::archive_search_paths;
3937
let config = ArchiveConfig {
4038
sess,
4139
dst: output.to_path_buf(),
42-
lib_search_paths: archive_search_paths(sess),
4340
use_native_ar: false,
4441
// FIXME test for linux and System V derivatives instead
4542
use_gnu_style_archive: sess.target.options.archive_format == "gnu",
@@ -94,47 +91,27 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
9491
));
9592
}
9693

97-
fn add_native_library(&mut self, name: Symbol, verbatim: bool) {
98-
let location = find_library(name, verbatim, &self.config.lib_search_paths, self.config.sess);
99-
self.add_archive(location.clone(), |_| false)
100-
.unwrap_or_else(|e| {
101-
panic!(
102-
"failed to add native library {}: {}",
103-
location.to_string_lossy(),
104-
e
105-
);
106-
});
107-
}
108-
109-
fn add_rlib(
110-
&mut self,
111-
rlib: &Path,
112-
name: &str,
113-
lto: bool,
114-
skip_objects: bool,
115-
) -> std::io::Result<()> {
116-
let obj_start = name.to_owned();
117-
118-
self.add_archive(rlib.to_owned(), move |fname: &str| {
119-
// Ignore metadata files, no matter the name.
120-
if fname == METADATA_FILENAME {
121-
return true;
122-
}
123-
124-
// Don't include Rust objects if LTO is enabled
125-
if lto && fname.starts_with(&obj_start) && fname.ends_with(".o") {
126-
return true;
127-
}
94+
fn add_archive<F>(&mut self, archive_path: &Path, mut skip: F) -> std::io::Result<()>
95+
where
96+
F: FnMut(&str) -> bool + 'static,
97+
{
98+
let mut archive = ar::Archive::new(std::fs::File::open(&archive_path)?);
99+
let archive_index = self.src_archives.len();
128100

129-
// Otherwise if this is *not* a rust object and we're skipping
130-
// objects then skip this file
131-
if skip_objects && (!fname.starts_with(&obj_start) || !fname.ends_with(".o")) {
132-
return true;
101+
let mut i = 0;
102+
while let Some(entry) = archive.next_entry() {
103+
let entry = entry?;
104+
let file_name = String::from_utf8(entry.header().identifier().to_vec())
105+
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err))?;
106+
if !skip(&file_name) {
107+
self.entries
108+
.push((file_name, ArchiveEntry::FromArchive { archive_index, entry_index: i }));
133109
}
110+
i += 1;
111+
}
134112

135-
// ok, don't skip this
136-
return false;
137-
})
113+
self.src_archives.push((archive_path.to_owned(), archive));
114+
Ok(())
138115
}
139116

140117
fn update_symbols(&mut self) {
@@ -239,32 +216,3 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
239216
unimplemented!();
240217
}
241218
}
242-
243-
impl<'a> ArArchiveBuilder<'a> {
244-
fn add_archive<F>(&mut self, archive_path: PathBuf, mut skip: F) -> std::io::Result<()>
245-
where
246-
F: FnMut(&str) -> bool + 'static,
247-
{
248-
let mut archive = ar::Archive::new(std::fs::File::open(&archive_path)?);
249-
let archive_index = self.src_archives.len();
250-
251-
let mut i = 0;
252-
while let Some(entry) = archive.next_entry() {
253-
let entry = entry.unwrap();
254-
let file_name = String::from_utf8(entry.header().identifier().to_vec()).unwrap();
255-
if !skip(&file_name) {
256-
self.entries.push((
257-
file_name,
258-
ArchiveEntry::FromArchive {
259-
archive_index,
260-
entry_index: i,
261-
},
262-
));
263-
}
264-
i += 1;
265-
}
266-
267-
self.src_archives.push((archive_path, archive));
268-
Ok(())
269-
}
270-
}

0 commit comments

Comments
 (0)