Skip to content

Commit 41f20fa

Browse files
authored
Support 128-bit integers on platforms without native support (rust-lang#103)
* Use sized integer types * Add support for integer types not supported on some platforms * Add feature to test non-native integers in CI
1 parent b7bfb21 commit 41f20fa

File tree

17 files changed

+1215
-350
lines changed

17 files changed

+1215
-350
lines changed

.github/workflows/main.yml renamed to .github/workflows/ci.yml

Lines changed: 15 additions & 2 deletions
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/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ gimple*
1818
res
1919
test-backend
2020
gcc_path
21+
benchmarks

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ Or add a breakpoint to `add_error` in gdb and print the line number using:
109109
110110
```
111111
p loc->m_line
112+
p loc->m_filename->m_buffer
113+
```
114+
115+
To print a debug representation of a tree:
116+
117+
```c
118+
debug_tree(expr);
112119
```
113120

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

build.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#set -x
44
set -e
55

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

16+
features=
17+
18+
if [[ "$1" == "--features" ]]; then
19+
shift
20+
features="--features $1"
21+
shift
22+
fi
23+
1624
if [[ "$1" == "--release" ]]; then
1725
export CHANNEL='release'
18-
CARGO_INCREMENTAL=1 cargo rustc --release
26+
CARGO_INCREMENTAL=1 cargo rustc --release $features
1927
else
2028
echo $LD_LIBRARY_PATH
2129
export CHANNEL='debug'
22-
cargo rustc
30+
cargo rustc $features
2331
fi
2432

2533
source config.sh

build_sysroot/build_sysroot.sh

Lines changed: 1 addition & 1 deletion
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

src/back/write.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, _diag_han
4545
if env::var("CG_GCCJIT_DUMP_MODULE_NAMES").as_deref() == Ok("1") {
4646
println!("Module {}", module.name);
4747
}
48-
if env::var("CG_GCCJIT_DUMP_MODULE").as_deref() == Ok(&module.name) {
48+
if env::var("CG_GCCJIT_DUMP_ALL_MODULES").as_deref() == Ok("1") || env::var("CG_GCCJIT_DUMP_MODULE").as_deref() == Ok(&module.name) {
4949
println!("Dumping reproducer {}", module.name);
5050
let _ = fs::create_dir("/tmp/reproducers");
5151
// FIXME(antoyo): segfault in dump_reproducer_to_file() might be caused by
@@ -54,6 +54,11 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, _diag_han
5454
context.dump_reproducer_to_file(&format!("/tmp/reproducers/{}.c", module.name));
5555
println!("Dumped reproducer {}", module.name);
5656
}
57+
if env::var("CG_GCCJIT_DUMP_TO_FILE").as_deref() == Ok("1") {
58+
let _ = fs::create_dir("/tmp/gccjit_dumps");
59+
let path = &format!("/tmp/gccjit_dumps/{}.c", module.name);
60+
context.dump_to_file(path, true);
61+
}
5762
context.compile_to_file(OutputKind::ObjectFile, obj_out.to_str().expect("path to str"));
5863
}
5964

src/base.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ pub fn linkage_to_gcc(linkage: Linkage) -> FunctionType {
5252
}
5353
}
5454

55-
pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol) -> (ModuleCodegen<GccContext>, u64) {
55+
pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol, supports_128bit_integers: bool) -> (ModuleCodegen<GccContext>, u64) {
5656
let prof_timer = tcx.prof.generic_activity("codegen_module");
5757
let start_time = Instant::now();
5858

5959
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
6060
let (module, _) = tcx.dep_graph.with_task(
6161
dep_node,
6262
tcx,
63-
cgu_name,
63+
(cgu_name, supports_128bit_integers),
6464
module_codegen,
6565
Some(dep_graph::hash_result),
6666
);
@@ -71,7 +71,7 @@ pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol) -> (Modul
7171
// the time we needed for codegenning it.
7272
let cost = time_to_codegen.as_secs() * 1_000_000_000 + time_to_codegen.subsec_nanos() as u64;
7373

74-
fn module_codegen(tcx: TyCtxt<'_>, cgu_name: Symbol) -> ModuleCodegen<GccContext> {
74+
fn module_codegen(tcx: TyCtxt<'_>, (cgu_name, supports_128bit_integers): (Symbol, bool)) -> ModuleCodegen<GccContext> {
7575
let cgu = tcx.codegen_unit(cgu_name);
7676
// Instantiate monomorphizations without filling out definitions yet...
7777
//let llvm_module = ModuleLlvm::new(tcx, &cgu_name.as_str());
@@ -106,7 +106,7 @@ pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol) -> (Modul
106106
}
107107

108108
{
109-
let cx = CodegenCx::new(&context, cgu, tcx);
109+
let cx = CodegenCx::new(&context, cgu, tcx, supports_128bit_integers);
110110

111111
let mono_items = cgu.items_in_deterministic_order(tcx);
112112
for &(mono_item, (linkage, visibility)) in &mono_items {

0 commit comments

Comments
 (0)