Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/unwinding #253

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,25 +182,35 @@ set substitute-path /usr/src/debug/gcc /path/to/gcc-repo/gcc

TODO(antoyo): but that's not what I remember I was doing.

### How to use a custom-build rustc
### How to emit LLVM IR for a crate in the sysroot

Compile with those flags:

```
cargo rustc -v --target x86_64-unknown-linux-gnu -Zbuild-std
```

Copy the `rustc` command and prefix it with `STD_ENV_ARCH="x86_64-unknown-linux-gnu"` and suffix it with `--emit=llvm-ir`.

## How to use a custom-build rustc

* Build the stage2 compiler (`rustup toolchain link debug-current build/x86_64-unknown-linux-gnu/stage2`).
* Clean and rebuild the codegen with `debug-current` in the file `rust-toolchain`.

### How to use [mem-trace](https://github.com/antoyo/mem-trace)
## How to use [mem-trace](https://github.com/antoyo/mem-trace)

`rustc` needs to be built without `jemalloc` so that `mem-trace` can overload `malloc` since `jemalloc` is linked statically, so a `LD_PRELOAD`-ed library won't a chance to intercept the calls to `malloc`.

### How to build a cross-compiling libgccjit
## How to build a cross-compiling libgccjit

#### Building libgccjit
### Building libgccjit

* Follow these instructions: https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/ with the following changes:
* Configure gcc with `../gcc/configure --enable-host-shared --disable-multilib --enable-languages=c,jit,c++ --disable-bootstrap --enable-checking=release --prefix=/opt/m68k-gcc/ --target=m68k-linux --without-headers`.
* Some shells, like fish, don't define the environment variable `$MACHTYPE`.
* Add `CFLAGS="-Wno-error=attributes -g -O2"` at the end of the configure command for building glibc (`CFLAGS="-Wno-error=attributes -Wno-error=array-parameter -Wno-error=stringop-overflow -Wno-error=array-bounds -g -O2"` for glibc 2.31, which is useful for Debian).

#### Configuring rustc_codegen_gcc
### Configuring rustc_codegen_gcc

* Set `TARGET_TRIPLE="m68k-unknown-linux-gnu"` in config.sh.
* Since rustc doesn't support this architecture yet, set it back to `TARGET_TRIPLE="mips-unknown-linux-gnu"` (or another target having the same attributes). Alternatively, create a [target specification file](https://book.avr-rust.com/005.1-the-target-specification-json-file.html) (note that the `arch` specified in this file must be supported by the rust compiler).
Expand Down
7 changes: 6 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,12 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
}

fn br(&mut self, dest: Block<'gcc>) {
self.llbb().end_with_jump(None, dest)
// NOTE: GCC requires finally to fallthrough in order to prevent an optimization that will
// remove the cleanup landing pads.
// FIXME(antoyo): find a better way to do this, probably by changing the cg_ssa API.
if !self.cleanup_blocks.borrow().contains(&self.block) {
self.llbb().end_with_jump(None, dest)
}
}

fn cond_br(&mut self, cond: RValue<'gcc>, then_block: Block<'gcc>, else_block: Block<'gcc>) {
Expand Down