Skip to content

Commit 6b6000b

Browse files
committed
Only embed GIMPLE when EMBED_LTO_BITCODE is set
1 parent 188816d commit 6b6000b

17 files changed

+81
-192
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,12 @@ jobs:
4646

4747
- name: Install packages
4848
# `llvm-14-tools` is needed to install the `FileCheck` binary which is used for asm tests.
49-
run: |
50-
sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa
51-
sudo apt update
52-
sudo apt-get install ninja-build ripgrep llvm-14-tools
49+
run: sudo apt-get install ninja-build ripgrep llvm-14-tools
5350

5451
- name: Install libgccjit12
5552
if: matrix.libgccjit_version.gcc == 'libgccjit12.so'
5653
run: sudo apt-get install libgccjit-12-dev
5754

58-
- name: Download artifact
59-
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
60-
uses: dawidd6/action-download-artifact@v2
61-
with:
62-
workflow: main.yml
63-
name: ${{ matrix.libgccjit_version.gcc }}
64-
path: gcc-build
65-
repo: antoyo/gcc
66-
branch: ${{ matrix.libgccjit_version.artifacts_branch }}
67-
event: push
68-
search_artifacts: true # Because, instead, the action only check the last job ran and that won't work since we want multiple artifacts.
69-
7055
- name: Download artifact
7156
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
7257
uses: dawidd6/action-download-artifact@v2
@@ -89,60 +74,6 @@ jobs:
8974
sudo dpkg --force-overwrite -i gcc-13/gcc-13.deb
9075
echo /usr/lib/ > gcc_path
9176
92-
#echo stddef.h
93-
#find / -name stddef.h 2> /dev/null || true
94-
#echo "************"
95-
96-
#echo lto1
97-
#find / -name lto1 2> /dev/null || true
98-
#echo "************"
99-
# /usr/libexec/gcc/x86_64-linux-gnu/13/lto1
100-
# /usr/lib/gcc/x86_64-linux-gnu/12/lto1
101-
102-
#echo lto-wrapper
103-
#find / -name lto-wrapper 2> /dev/null || true
104-
#echo "************"
105-
# /usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper
106-
# /usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper
107-
108-
#echo gcc
109-
#find / -name gcc 2> /dev/null || true
110-
#echo "************"
111-
112-
#echo liblto_plugin.so
113-
#find / -name liblto_plugin.so 2> /dev/null || true
114-
#echo "************"
115-
# /usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so
116-
# /usr/lib/gcc/x86_64-linux-gnu/12/liblto_plugin.so
117-
# /usr/lib/gcc/x86_64-linux-gnu/13/liblto_plugin.so
118-
119-
#echo $(readlink -f gcc-build/build/gcc) > gcc_path
120-
## NOTE: the filename is still libgccjit.so even when the artifact name is different.
121-
#ln gcc-build/build/gcc/libgccjit.so gcc-build/build/gcc/libgccjit.so.0
122-
##mkdir -p /opt/gcc/libexec/gcc/x86_64-linux-gnu/13 /opt/gcc/libexec/x86_64-linux-gnu/13/
123-
#sudo mkdir -p /usr/lib/gcc/x86_64-pc-linux-gnu/13.0.0/ /usr/libexec/gcc/x86_64-pc-linux-gnu/13.0.0
124-
#sudo cp gcc-build/install/bin/gcc /usr/bin/gcc-13
125-
#cd gcc-build/build/gcc
126-
#chmod +x lto-wrapper lto1
127-
##sudo cp liblto_plugin.so /usr/lib/gcc/x86_64-pc-linux-gnu/13.0.0/liblto_plugin.so # FIXME: might not work.
128-
#sudo cp liblto_plugin.so /usr/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/liblto_plugin.so # TODO: should work.
129-
#sudo cp lto1 /usr/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/lto1
130-
#sudo cp lto-wrapper /usr/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/lto-wrapper
131-
132-
# TODO TODO TODO: probably need to build gcc with --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
133-
# TODO TODO TODO: bundle that into a .deb file.
134-
# https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=gcc11
135-
136-
##cp /usr/lib/gcc/x86_64-linux-gnu/12/libgcc_s.so /opt/gcc/libexec/x86_64-linux-gnu/13/
137-
## TODO: copy from version 13.
138-
## TODO: understand why it doesn't pick the one from the version 13 automatically.
139-
#sudo cp /usr/lib/gcc/x86_64-linux-gnu/12/libgcc_s.so /usr/lib/
140-
#sudo cp /usr/lib/gcc/x86_64-linux-gnu/12/libgcc.a /usr/lib
141-
##cp /usr/lib/gcc/x86_64-linux-gnu/12/libgcc.a /opt/gcc/libexec/
142-
##cp /usr/libexec/gcc/x86_64-linux-gnu/13/cc1 /opt/gcc/libexec/gcc/cc1
143-
#sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 13
144-
#sudo update-alternatives --all
145-
14677
- name: Set env
14778
run: |
14879
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV

.github/workflows/release.yml

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,18 @@ jobs:
3434
path: llvm
3535

3636
- name: Install packages
37-
run: |
38-
sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa
39-
sudo apt update
40-
sudo apt-get install ninja-build ripgrep gcc-13 gcc-multilib
41-
42-
- name: Download artifact
43-
uses: dawidd6/action-download-artifact@v2
44-
with:
45-
workflow: main.yml
46-
name: ${{ matrix.libgccjit_version.gcc }}
47-
path: gcc-build
48-
repo: antoyo/gcc
49-
branch: ${{ matrix.libgccjit_version.artifacts_branch }}
50-
event: push
51-
search_artifacts: true # Because, instead, the action only check the last job ran and that won't work since we want multiple artifacts.
37+
run: sudo apt-get install ninja-build ripgrep gcc-13
38+
39+
#- name: Download artifact
40+
#uses: dawidd6/action-download-artifact@v2
41+
#with:
42+
#workflow: main.yml
43+
#name: ${{ matrix.libgccjit_version.gcc }}
44+
#path: gcc-build
45+
#repo: antoyo/gcc
46+
#branch: ${{ matrix.libgccjit_version.artifacts_branch }}
47+
#event: push
48+
#search_artifacts: true # Because, instead, the action only check the last job ran and that won't work since we want multiple artifacts.
5249

5350
- name: Download artifact
5451
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
@@ -67,23 +64,6 @@ jobs:
6764
sudo dpkg --force-overwrite -i gcc-13/gcc-13.deb
6865
echo /usr/lib/ > gcc_path
6966
70-
#echo $(readlink -f gcc-build/build/gcc) > gcc_path
71-
## NOTE: the filename is still libgccjit.so even when the artifact name is different.
72-
#ln gcc-build/build/gcc/libgccjit.so gcc-build/build/gcc/libgccjit.so.0
73-
#mkdir -p /opt/gcc/libexec/gcc/x86_64-linux-gnu/13 /opt/gcc/libexec/x86_64-linux-gnu/13/ /opt/gcc/bin
74-
#cp gcc-build/install/bin/gcc /opt/gcc/bin/gcc
75-
#cd gcc-build/build/gcc
76-
#chmod +x lto-wrapper lto1 /opt/gcc/bin/gcc
77-
#cp *lto* /opt/gcc/libexec/gcc/x86_64-linux-gnu/
78-
##cp crt*.o /opt/gcc/libexec/x86_64-linux-gnu/13/
79-
#cp crt*.o /opt/gcc/libexec/x86_64-linux-gnu/
80-
#cp /usr/lib/gcc/x86_64-linux-gnu/12/libgcc_s.so /opt/gcc/libexec/x86_64-linux-gnu/
81-
#cp /usr/lib/gcc/x86_64-linux-gnu/12/libgcc.a /opt/gcc/libexec/
82-
#sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 13
83-
## TODO: add comment if this fixes the -fno-inline errors.
84-
## TODO: do some tests locally to know which binary needs to be copied from the system installation.
85-
##cp /usr/libexec/gcc/x86_64-linux-gnu/13/lto1 /opt/gcc/libexec/gcc/x86_64-linux-gnu/13/
86-
8767
- name: Set env
8868
run: |
8969
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
@@ -120,7 +100,7 @@ jobs:
120100
- name: Build
121101
run: |
122102
./prepare_build.sh
123-
./build.sh --release --release-sysroot
103+
EMBED_LTO_BITCODE=1 ./build.sh --release --release-sysroot
124104
cargo test
125105
./clean_all.sh
126106
@@ -129,6 +109,8 @@ jobs:
129109
git config --global user.email "[email protected]"
130110
git config --global user.name "User"
131111
./prepare.sh
112+
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.
113+
echo -n 'lto = "fat"' >> build_sysroot/Cargo.toml
132114
133115
# Compile is a separate step, as the actions-rs/cargo action supports error annotations
134116
- name: Compile
@@ -137,9 +119,9 @@ jobs:
137119
command: build
138120
args: --release
139121

140-
- name: Add more failing tests because of undefined symbol errors
122+
- name: Add more failing tests because of undefined symbol errors (FIXME)
141123
run: cat failing-lto-tests.txt >> failing-ui-tests.txt
142124

143125
- name: Run tests
144126
run: |
145-
./test.sh --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }}
127+
EMBED_LTO_BITCODE=1 ./test.sh --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }}

.github/workflows/stdarch.yml

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ jobs:
3434
path: llvm
3535

3636
- name: Install packages
37-
run: |
38-
sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa
39-
sudo apt update
40-
sudo apt-get install ninja-build ripgrep gcc-13 gcc-multilib
37+
run: sudo apt-get install ninja-build ripgrep gcc-13 gcc-multilib
4138

4239
- name: Install Intel Software Development Emulator
4340
if: ${{ matrix.cargo_runner }}
@@ -64,23 +61,22 @@ jobs:
6461
event: push
6562
search_artifacts: true # Because, instead, the action only check the last job ran and that won't work since we want multiple artifacts.
6663

64+
- name: Download artifact
65+
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
66+
uses: dawidd6/action-download-artifact@v2
67+
with:
68+
workflow: main.yml
69+
name: gcc-13
70+
path: gcc-13
71+
repo: antoyo/gcc
72+
branch: "master"
73+
event: push
74+
search_artifacts: true # Because, instead, the action only check the last job ran and that won't work since we want multiple artifacts.
75+
6776
- name: Setup path to libgccjit
6877
run: |
69-
echo $(readlink -f gcc-build/build/gcc) > gcc_path
70-
# NOTE: the filename is still libgccjit.so even when the artifact name is different.
71-
# TODO: instead, overwrite the system gcc, lto1, …?
72-
ln gcc-build/build/gcc/libgccjit.so gcc-build/build/gcc/libgccjit.so.0
73-
mkdir -p /opt/gcc/libexec/gcc/x86_64-linux-gnu/13 /opt/gcc/libexec/x86_64-linux-gnu/13/ /opt/gcc/bin /opt/gcc/libexec/gcc/x86_64-linux-gnu/13.0.0
74-
cp gcc-build/install/bin/gcc /opt/gcc/bin/gcc
75-
cd gcc-build/build/gcc
76-
chmod +x lto-wrapper lto1 /opt/gcc/bin/gcc
77-
cp *lto* /opt/gcc/libexec/gcc/x86_64-linux-gnu/13/
78-
cp *lto* /opt/gcc/libexec/gcc/x86_64-linux-gnu/13.0.0/
79-
# TODO: instead of downloading the crt files from the GCC CI, copy them from the system.
80-
cp crt*.o /opt/gcc/libexec/x86_64-linux-gnu/13/
81-
cp /usr/lib/gcc/x86_64-linux-gnu/12/libgcc_s.so /opt/gcc/libexec/x86_64-linux-gnu/13/
82-
cp /usr/lib/gcc/x86_64-linux-gnu/12/libgcc.a /opt/gcc/libexec/
83-
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 13
78+
sudo dpkg --force-overwrite -i gcc-13/gcc-13.deb
79+
echo /usr/lib/ > gcc_path
8480
8581
- name: Set env
8682
run: |
@@ -119,7 +115,7 @@ jobs:
119115
run: |
120116
./prepare_build.sh
121117
./build.sh --release --release-sysroot
122-
GCC_EXEC_PREFIX=/opt/gcc/libexec/gcc/x86_64-pc-linux-gnu cargo test
118+
cargo test
123119
124120
- name: Clean
125121
if: ${{ !matrix.cargo_runner }}
@@ -154,4 +150,5 @@ jobs:
154150
if: ${{ matrix.cargo_runner }}
155151
run: |
156152
cd build_sysroot/sysroot_src/library/stdarch/
153+
# FIXME: these tests fail when the sysroot is compiled with LTO because of a missing symbol in proc-macro.
157154
STDARCH_TEST_EVERYTHING=1 CHANNEL=release CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="${{ matrix.cargo_runner }}" TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features" ../../../../cargo.sh test -- --skip rtm --skip tbm --skip sse4a

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ harness = false
2020
[features]
2121
default = ["master"]
2222
master = ["gccjit/master"]
23-
# TODO: add feature for LTO, given all the setup that is needed (having same versions of gcc, lto1, lto-wrapper, liblto_plugin.so)?
2423

2524
[dependencies]
2625
gccjit = { git = "https://github.com/antoyo/gccjit.rs" }

Readme.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ $ CHANNEL="release" $CG_GCCJIT_DIR/cargo.sh run
9191

9292
If you compiled cg_gccjit in debug mode (aka you didn't pass `--release` to `./test.sh`) you should use `CHANNEL="debug"` instead or omit `CHANNEL="release"` completely.
9393

94-
To use LTO, you need to set the variable `FAT_LTO` in addition to setting `lto = "fat"` in the `Cargo.toml`.
94+
To use LTO, you need to set the variable `FAT_LTO=1` and `EMBED_LTO_BITCODE=1` in addition to setting `lto = "fat"` in the `Cargo.toml`.
95+
Don't set `FAT_LTO` when compiling the sysroot, though: only set `EMBED_LTO_BITCODE=1`.
9596

9697
### Rustc
9798

@@ -202,11 +203,11 @@ error: failed to build archive: failed to open object file: No such file or dire
202203
```
203204
204205
That can be caused by the fact that you try to compile with `lto = "fat"`, but you didn't compile the sysroot with LTO.
205-
TODO: check this ^ .
206+
(Not sure if that's the reason since I cannot reproduce anymore. Maybe it happened when forgetting setting `FAT_LTO`.)
206207
207208
### How to debug GCC LTO
208209
209-
Run do the command with `-v -save-temps` and then extract the `lto1` line from the output and run that under the debugger
210+
Run do the command with `-v -save-temps` and then extract the `lto1` line from the output and run that under the debugger.
210211
211212
### How to send arguments to the GCC linker
212213

build_sysroot/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ rustc-std-workspace-std = { path = "./sysroot_src/library/rustc-std-workspace-st
1919

2020
[profile.release]
2121
debug = true
22-
# FIXME: is this actually needed?
23-
lto = "fat"
22+
#lto = "fat" # TODO(antoyo): re-enable when the failing LTO tests regarding proc-macros are fixed.

build_sysroot/build_sysroot.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ rm -r sysroot/ 2>/dev/null || true
1919
export RUSTFLAGS="$RUSTFLAGS -Z force-unstable-if-unmarked"
2020
if [[ "$1" == "--release" ]]; then
2121
sysroot_channel='release'
22-
# To avoid the -fno-inline errors, use /opt/gcc/bin/gcc instead of cc. With:
23-
# -Clinker=/opt/gcc/bin/gcc
24-
#LIBRARY_PATH=gcc-build GCC_EXEC_PREFIX=/opt/gcc/libexec/gcc/x86_64-pc-linux-gnu
2522
RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3" cargo build --target $TARGET_TRIPLE --release
26-
#CG_GCCJIT_DUMP_TREE_ALL=1 CG_GCCJIT_KEEP_INTERMEDIATES=1 RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3" cargo build --target $TARGET_TRIPLE --release
2723
else
2824
sysroot_channel='debug'
2925
cargo build --target $TARGET_TRIPLE --features compiler_builtins/c

cargo.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,4 @@ fi
2020
cmd=$1
2121
shift
2222

23-
# TODO: remove LIBRARY_PATH and GCC_EXEC_PREFIX. Those are used to debug the LTO front-end.
24-
#LIBRARY_PATH=/home/bouanto/Ordinateur/Programmation/Projets/gcc-repo/gcc-build/build/gcc GCC_EXEC_PREFIX=/opt/gcc/libexec/gcc/x86_64-pc-linux-gnu
25-
#PATH=$PATH:/opt/gcc/bin
2623
RUSTDOCFLAGS="$RUSTFLAGS" cargo +${TOOLCHAIN} $cmd $@

config.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ export RUSTC_LOG=warn # display metadata load errors
5555

5656
export LD_LIBRARY_PATH="$(pwd)/target/out:$(pwd)/build_sysroot/sysroot/lib/rustlib/$TARGET_TRIPLE/lib:$GCC_PATH"
5757
export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH
58+
# NOTE: To avoid the -fno-inline errors, use /opt/gcc/bin/gcc instead of cc.
59+
# To do so, add a symlink for cc to /opt/gcc/bin/gcc in our PATH.
60+
# Another option would be to add the following Rust flag: -Clinker=/opt/gcc/bin/gcc
61+
export PATH="/opt/gcc/bin:$PATH"

failing-non-lto-tests.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ tests/ui/lto/lto-rustc-loads-linker-plugin.rs
77
tests/ui/panic-runtime/lto-unwind.rs
88
tests/ui/sanitize/issue-111184-generator-witness.rs
99
tests/ui/sepcomp/sepcomp-lib-lto.rs
10+
tests/ui/lto/lto-opt-level-s.rs
11+
tests/ui/lto/lto-opt-level-z.rs
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
From c3821e02fbd6cb5ad6e06d759fccdc9073712375 Mon Sep 17 00:00:00 2001
1+
From b8f3eed3053c9333b5dfbeaeb2a6a65a4b3156df Mon Sep 17 00:00:00 2001
22
From: Antoni Boucher <[email protected]>
3-
Date: Tue, 7 Jun 2022 21:40:13 -0400
4-
Subject: [PATCH] Add stdarch Cargo.toml for testing
3+
Date: Tue, 29 Aug 2023 13:06:34 -0400
4+
Subject: [PATCH] Patch 0001-Add-stdarch-Cargo.toml-for-testing.patch
55

66
---
7-
library/stdarch/Cargo.toml | 20 ++++++++++++++++++++
8-
1 file changed, 20 insertions(+)
7+
library/stdarch/Cargo.toml | 23 +++++++++++++++++++++++
8+
1 file changed, 23 insertions(+)
99
create mode 100644 library/stdarch/Cargo.toml
1010

1111
diff --git a/library/stdarch/Cargo.toml b/library/stdarch/Cargo.toml
1212
new file mode 100644
13-
index 0000000..fbe0a95
13+
index 0000000..4c63700
1414
--- /dev/null
1515
+++ b/library/stdarch/Cargo.toml
16-
@@ -0,0 +1,20 @@
16+
@@ -0,0 +1,21 @@
1717
+[workspace]
18+
+resolver = "1"
1819
+members = [
1920
+ "crates/core_arch",
2021
+ "crates/std_detect",
2122
+ "crates/stdarch-gen",
22-
+ "examples/"
23+
+ #"examples/"
2324
+]
2425
+exclude = [
2526
+ "crates/wasm-assert-instr-tests"
@@ -35,5 +36,5 @@ index 0000000..fbe0a95
3536
+opt-level = 3
3637
+incremental = true
3738
--
38-
2.26.2.7.g19db9cfb68.dirty
39+
2.42.0
3940

patches/0001-Disable-examples.patch

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)