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

Update Rust to 1.75.0 #88

Merged
merged 100 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
fd2bb85
[SOL] Use Solana's LLVM fork
jackcmay Feb 13, 2019
ff860ee
[SOL] Enable LLVM backend
jackcmay Feb 13, 2019
2a9c2f2
[SOL] Implement C abi modifier
jackcmay Feb 14, 2019
5055958
[SOL] Add custom build configuration
jackcmay Feb 14, 2019
aeba635
[SOL] Don't build rustdoc to save time
jackcmay Feb 14, 2019
d6c5784
[SOL] Custom README.md
jackcmay Feb 14, 2019
048e84c
[SOL] Add build script
jackcmay Feb 20, 2019
9eac64d
[SOL] Preserve lib dir, needed for sysroot building
jackcmay Feb 20, 2019
5a2fbc2
[SOL] Allow older gcc, debian does not support a newer one yet
jackcmay Feb 20, 2019
d84abc8
[SOL] Reduce size of output binaries
jackcmay Feb 23, 2019
3bcbaf3
[SOL] Add BPF as a built-in target
jackcmay Feb 27, 2019
abf8c7b
[SOL] Add bin dir later
jackcmay Feb 28, 2019
936906f
[SOL] Update README.md
jackcmay Mar 2, 2019
61fce1f
[SOL] Script nit
jackcmay Jun 4, 2019
b8c731d
[SOL] BPF Spec use os=unknown
jackcmay Sep 19, 2019
3a19b1c
[SOL] Rust libstd requires atomic cas support
jackcmay Sep 25, 2019
6bb03a0
[SOL] Updates from latest config.example.toml
jackcmay Dec 10, 2019
f342fe9
[SOL] Updates from rust 1.39
jackcmay Dec 10, 2019
875ed2b
[SOL] Allow all nightly options to help interactions with newer Cargo
jackcmay Apr 28, 2020
ca68c1c
[SOL] Update README.md
veryoddthomas Jul 26, 2020
b04b686
[SOL] Renames to match the upstream changes
Lichtso Sep 7, 2020
8d2104c
[SOL] Disable eh_frame_hdr linker option
dmakarov Feb 10, 2021
967de63
[SOL] Build llvm tools from llvm-project
jackcmay Feb 16, 2021
d75161f
[SOL] Link llvm tools statically
jackcmay Feb 17, 2021
e28e9c0
[SOL] Do not disable all builtins for BPF target
dmakarov Feb 17, 2021
2d55891
[SOL] Adjust ABI implementation to pass 128-bit arguments by value
dmakarov Feb 26, 2021
621bfcc
[SOL] Adjust BPF target spec to upstream changes
dmakarov Feb 28, 2021
5a8a2c7
[SOL] Adjust for building in tree the bpf target with std library
dmakarov Apr 2, 2021
23da387
[SOL] Update build script to automatically build for correct targets
dmakarov Apr 2, 2021
a12b51e
[SOL] Use +solana feature when compiling for BPF target
dmakarov Apr 12, 2021
2ef222a
[SOL] Document source tree upgrade and bpf-tools release process
dmakarov Apr 12, 2021
54fec5c
[SOL] Enable test harness for BPF programs
dmakarov May 7, 2021
09fda82
[SOL] Fix github actions configuration
dmakarov May 11, 2021
8d98fad
[SOL] Add linker script and command line options to BPF target spec
dmakarov May 13, 2021
392e9e8
[SOL] Fix BPF target spec after upgrade to rust 1.52.1
dmakarov May 17, 2021
1c7ba75
[SOL] Adjust BPF customization after upgrading to rust 1.52.1
dmakarov May 18, 2021
b1add85
[SOL] Strip full paths from source filenames referred in messages
dmakarov Jun 17, 2021
0ae40e5
[SOL] Adjust BPF customization after upgrading to rust 1.53.0
dmakarov Jul 4, 2021
0cc266e
[SOL] Make adjustments to work around CI failures
dmakarov Jul 5, 2021
89d66ab
[SOL] Adjust BPF customization after upgrading to rust 1.54.0
dmakarov Aug 5, 2021
cee3af3
[SOL] Disable channel check in CI as we use different branch names
dmakarov Aug 7, 2021
b9d716e
[SOL] Add support for windows in build script
joncinque Sep 27, 2021
b2f6cf0
[SOL] Adjust BPF customization after upgrading to rust 1.56.0
dmakarov Nov 3, 2021
aafec15
[SOL] Enable build on apple silicon
dmakarov Nov 10, 2021
c33e351
[SOL] Adjust test harness entrypoint function generation
dmakarov Nov 18, 2021
2e54402
[SOL] rework test harness codegen a bit
alessandrod Nov 26, 2021
7310935
[SOL] libtest: disable should_panic tests and benchmarks
alessandrod Nov 26, 2021
564267f
[SOL] tests: core: depend on dummy getrandom
alessandrod Nov 26, 2021
7fa2baf
[SOL] tests: disable failing core tests
alessandrod Nov 26, 2021
377f7a4
[SOL] link using rust-lld
alessandrod Dec 1, 2021
d17b35c
[SOL] CI: run tests for the bpfel-unknown-unknown target
alessandrod Dec 1, 2021
cd65e3f
[SOL] CI: run tests on push and improve run times
alessandrod Dec 6, 2021
8029b57
[SOL] CI: run push job on solana-* branches instead of master
alessandrod Dec 8, 2021
7ac5596
[SOL] Install rustup and use more recent cargo and rustc
dmakarov Dec 9, 2021
b4ff881
[SOL] Rename bpf target to sbf
dmakarov Dec 9, 2021
b82a6f9
[SOL] make all core tests (but atomics) pass
alessandrod Dec 16, 2021
b579c47
[SOL] Fix missing SBF customizations
dmakarov Dec 22, 2021
230e39f
[SOL] CI: build and test sbf target
dmakarov Dec 15, 2021
23b8808
[SOL] CI: speed up PR runs
alessandrod Jan 3, 2022
94b54c4
[SOL] remove stubs for atomics
alessandrod Jan 3, 2022
0989b9c
[SOL] use codegen-units=1 by default for SBF
alessandrod Feb 4, 2022
4639198
[SOL] build: add aarch64-linux target
lithdew Jan 24, 2022
c5ac539
[SOL] Update run-bpf-tests revision in CI
dmakarov Feb 22, 2022
896f166
[SOL] Adjust BPF customization after upgrading to rust 1.59.0
dmakarov Mar 30, 2022
b8a3d65
[SOL] Skip 'ensure the stable version number is correct' step in CI
dmakarov Apr 2, 2022
1f8c68a
[SOL] Update run-bpf-tests revision in CI
dmakarov Apr 2, 2022
c6a2e08
[SOL] Temporary disable some failing core tests
dmakarov Apr 2, 2022
c15cdaa
[SOL] Don't create invalid string slices in stdout/stderr on Solana
brson Feb 18, 2022
03540e6
[SOL] tweak linker script
alessandrod Mar 25, 2022
04c9e68
[SOL] Update run-bpf-tests revision in CI
dmakarov Apr 27, 2022
a19ec41
[SOL] Update run-bpf-tests revision in CI
dmakarov May 2, 2022
8465503
[SOL] Prefer command line supplied linker script over embedded one
dmakarov May 2, 2022
26e2fdf
[SOL] Enable the std backtrace API
Aimeedeer Mar 26, 2022
2d67925
[SOL] Add os field to SBF target specification
dmakarov May 10, 2022
678b663
[SOL] sbf: implement static-syscalls target feature
alessandrod May 7, 2022
aaf3ec0
[SOL] sbfv2: place the rodata segment at MM_PROGRAM_START
alessandrod May 14, 2022
4fdc87d
[SOL] sbfv2: output _RELATIVE relocations in a separate SHT_RELR section
alessandrod May 14, 2022
306ae1e
[SOL] tests: update docker image name
alessandrod May 17, 2022
606c944
[SOL] Update run-bpf-tests revision in CI
dmakarov Jul 7, 2022
a44a1c9
[SOL] Update run-bpf-tests revision in CI
dmakarov Jul 9, 2022
71b23af
[SOL] Adjust BPF customization after upgrading to rust 1.62.0
dmakarov Jul 21, 2022
5d82320
[SOL] Update cargo-run-bpf-test revision for CI
dmakarov Aug 1, 2022
235f439
[SOL] Update run-sbf-tests revision in CI
dmakarov Oct 14, 2022
869ffd7
[SOL] switch to new SBF LLVM backend
dmakarov Oct 24, 2022
61817e6
[SOL] Adjust SBF customization after upgrading to rust 1.65.0
dmakarov Dec 5, 2022
a579ea6
[SOL] Update run-sbf-tests revision in CI
dmakarov Dec 7, 2022
0a37947
[SOL] Temporarily patch BPF ELF file header with SBF machine code
dmakarov Dec 8, 2022
47f08f7
[SOL] Update run-sbf-tests revision in CI
dmakarov Dec 13, 2022
876947c
[SOL] Add lldb to enabled projects in [llvm] section of config.toml
dmakarov Jan 31, 2023
672d7bc
[SOL] Fix Ci error caused by insufficient git history fetched
dmakarov Feb 2, 2023
ff57430
[SOL] Temporarily patch BPF ELF file header only for SBFv2 cpu
dmakarov Feb 20, 2023
900683a
[SOL] Update run-sbf-tests revision in CI
dmakarov Mar 5, 2023
cb8ed9c
[SOL] Adjust SBF customization after upgrading to rust 1.68.0
dmakarov Mar 21, 2023
4383239
[SOL] Set default visibility of symbols in SBF binaries to hidden
dmakarov Aug 16, 2023
96993e4
[SOL] Update run-sbf-tests revision in CI
dmakarov Aug 19, 2023
0da9b0a
[SOL] Adjust SBF customization after upgrading to rust 1.72.0
dmakarov Sep 26, 2023
224302f
[SOL] Fix CI failures
dmakarov Oct 19, 2023
bf80789
[SOL] Adjust compiler after upgrade to 1.75.0
LucasSte Feb 2, 2024
bcaa393
[SOL] Adjust flaky CI test
LucasSte Feb 7, 2024
64b2ec1
[SOL] Free up space in github runner
LucasSte Feb 20, 2024
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
280 changes: 215 additions & 65 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Session.vim
!/tests/run-make/thumb-none-qemu/example/.cargo

## Configuration
/config.toml
/Makefile
config.mk
config.stamp
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
shallow = true
[submodule "src/llvm-project"]
path = src/llvm-project
url = https://github.com/rust-lang/llvm-project.git
branch = rustc/17.0-2023-12-14
url = https://github.com/solana-labs/llvm-project.git
branch = solana-rustc/17.0-2023-12-14
shallow = true
[submodule "src/doc/embedded-book"]
path = src/doc/embedded-book
Expand Down
2 changes: 2 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ Files: compiler/*
tests/*
src/*
.github/*
build.sh
Cargo.lock
Cargo.toml
CODE_OF_CONDUCT.md
config.example.toml
config.toml
configure
CONTRIBUTING.md
COPYRIGHT
Expand Down
35 changes: 26 additions & 9 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,7 @@ checksum = "55b672471b4e9f9e95499ea597ff64941a309b2cdbffcc46f2cc5e2d971fd335"
[[package]]
name = "compiler_builtins"
version = "0.1.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3b73c3443a5fd2438d7ba4853c64e4c8efc2404a9e28a9234cc2d5eebc6c242"
source = "git+https://github.com/solana-labs/compiler-builtins?tag=solana-tools-v1.40#81ef46f3fe1357095acdd089a700890fe4e13974"
dependencies = [
"cc",
"rustc-std-workspace-core",
Expand Down Expand Up @@ -781,6 +780,7 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
name = "core"
version = "0.0.0"
dependencies = [
"getrandom 0.1.16",
"rand",
"rand_xorshift",
]
Expand Down Expand Up @@ -1591,6 +1591,17 @@ dependencies = [
"unicode-width",
]

[[package]]
name = "getrandom"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
dependencies = [
"cfg-if",
"libc",
"wasi 0.9.0+wasi-snapshot-preview1",
]

[[package]]
name = "getrandom"
version = "0.2.10"
Expand All @@ -1599,7 +1610,7 @@ checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"cfg-if",
"libc",
"wasi",
"wasi 0.11.0+wasi-snapshot-preview1",
]

[[package]]
Expand Down Expand Up @@ -2523,7 +2534,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
dependencies = [
"libc",
"wasi",
"wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys 0.48.0",
]

Expand All @@ -2544,7 +2555,7 @@ dependencies = [
"colored",
"ctrlc",
"env_logger 0.10.0",
"getrandom",
"getrandom 0.2.10",
"lazy_static",
"libc",
"libffi",
Expand Down Expand Up @@ -3175,7 +3186,7 @@ version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
"getrandom 0.2.10",
]

[[package]]
Expand Down Expand Up @@ -3240,7 +3251,7 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
dependencies = [
"getrandom",
"getrandom 0.2.10",
"redox_syscall 0.2.16",
"thiserror",
]
Expand Down Expand Up @@ -5137,7 +5148,7 @@ dependencies = [
"rustc-demangle",
"std_detect",
"unwind",
"wasi",
"wasi 0.11.0+wasi-snapshot-preview1",
]

[[package]]
Expand Down Expand Up @@ -5963,7 +5974,7 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d023da39d1fde5a8a3fe1f3e01ca9632ada0a63e9797de55a879d6e2236277be"
dependencies = [
"getrandom",
"getrandom 0.2.10",
]

[[package]]
Expand Down Expand Up @@ -6003,6 +6014,12 @@ dependencies = [
"try-lock",
]

[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"

[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ miniz_oxide.debug = 0
object.debug = 0

[patch.crates-io]
compiler_builtins = { git = "https://github.com/solana-labs/compiler-builtins", tag = "solana-tools-v1.40" }
# See comments in `library/rustc-std-workspace-core/README.md` for what's going on
# here
rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' }
Expand Down
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
# Fork of the Rust Programming Language that supports Berkley Packet Filter (BPF) targets

This fork of Rust contains changes that enable rustc to build BPF
modules. It depends on a customized
[fork](https://github.com/solana-labs/llvm-project) of Rust's LLVM
fork.

Solana SDK does not depend directly on this repo. Instead [bpf-tools]
builds and releases binary packages that the Solana SDK pulls in.

[bpf-tools]: https://github.com/solana-labs/bpf-tools

BPF modules are built using target triple `bpfel-unknown-unknown`
which represents the little endian version of BPF. There is no
support for big endian at this time.

Upgrading the compiler and standard library source tree
-------------------------------------------------------

The source tree has two external dependencies
1. [compiler-builtins]
2. [llvm-project]

If any of the depencies is changed or this repository is updated to
make a new release of the bpf-tools, tag the dependencies, and this
repository with a new bpf-tools-v1.x tag, so that all components of
the released bpf-tools have the same tag, e.g. bpf-tools-v1.6. Thus,
release of every version of the bpf-tools is fully specified by the
release version.

The [llvm-project] is a submodule of this repository, therefore its
version is explicitly committed in this repository. However,
[compiler-builtins] is pulled in as a cargo package. Therefore, it is
necessary to update the `[patch.crates-io]` subsection of the
top-level `Cargo.toml` file, and specify which tag must be used to
pull the correct version of [compiler-builtins].

After this repository is tagged for a new release, update the
`bpf-tools/build.sh` in [bpf-tools] repository to pull the correct
version of the rust repository and make a new release tag in
[bpf-tools] repository.

[compiler-builtins]: https://github.com/solana-labs/compiler-builtins
[llvm-project]: https://github.com/solana-labs/llvm-project

---

# The Rust Programming Language

[![Rust Community](https://img.shields.io/badge/Rust_Community%20-Join_us-brightgreen?style=plastic&logo=rust)](https://www.rust-lang.org/community)
Expand Down
23 changes: 23 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -ex

if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
echo "--llvm to rebuild llvm";
exit;
fi

unameOut="$(uname -s)-$(uname -m)"
case "${unameOut}" in
Linux-x86_64*) HOST_TRIPLE=x86_64-unknown-linux-gnu;;
Linux-aarch64*) HOST_TRIPLE=aarch64-unknown-linux-gnu;;
Darwin-x86_64*) HOST_TRIPLE=x86_64-apple-darwin;;
Darwin-arm64*) HOST_TRIPLE=aarch64-apple-darwin;;
MINGW*) HOST_TRIPLE=x86_64-pc-windows-msvc;;
*) HOST_TRIPLE=x86_64-unknown-linux-gnu
esac

if [ "$1" == "--llvm" ]; then
rm -f build/${HOST_TRIPLE}/llvm/llvm-finished-building;
fi
./x.py build --stage 1 --target ${HOST_TRIPLE},bpfel-unknown-unknown,sbf-solana-solana
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_gcc/src/intrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_codegen_ssa::traits::{ArgAbiMethods, BuilderMethods, ConstMethods, IntrinsicCallMethods};
#[cfg(feature="master")]
use rustc_codegen_ssa::traits::{BaseTypeMethods, MiscMethods};
use rustc_codegen_ssa::traits::MiscMethods;
use rustc_codegen_ssa::traits::BaseTypeMethods;
use rustc_codegen_ssa::errors::InvalidMonomorphization;
use rustc_middle::bug;
use rustc_middle::ty::{self, Instance, Ty};
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_gcc/src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
}
}

pub fn type_void(&self) -> Type<'gcc> {
self.context.new_type::<()>()
}

pub fn type_size_t(&self) -> Type<'gcc> {
self.context.new_type::<usize>()
}
Expand Down Expand Up @@ -126,6 +122,10 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
self.double_type
}

fn type_void(&self) -> Type<'gcc> {
self.context.new_type::<()>()
}

fn type_func(&self, params: &[Type<'gcc>], return_type: Type<'gcc>) -> Type<'gcc> {
self.context.new_function_pointer_type(None, return_type, params, false)
}
Expand Down
14 changes: 8 additions & 6 deletions compiler/rustc_codegen_llvm/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ pub(crate) unsafe fn codegen(
let llval = llvm::LLVMConstInt(i8, val as u64, False);
llvm::LLVMSetInitializer(ll_g, llval);

let name = NO_ALLOC_SHIM_IS_UNSTABLE;
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
if tcx.sess.target.default_hidden_visibility {
llvm::LLVMRustSetVisibility(ll_g, llvm::Visibility::Hidden);
if tcx.sess.target.arch != "sbf" {
let name = NO_ALLOC_SHIM_IS_UNSTABLE;
let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8);
if tcx.sess.target.default_hidden_visibility {
llvm::LLVMRustSetVisibility(ll_g, llvm::Visibility::Hidden);
}
let llval = llvm::LLVMConstInt(i8, 0, False);
llvm::LLVMSetInitializer(ll_g, llval);
}
let llval = llvm::LLVMConstInt(i8, 0, False);
llvm::LLVMSetInitializer(ll_g, llval);

if tcx.sess.opts.debuginfo != DebugInfo::None {
let dbg_cx = debuginfo::CodegenUnitDebugContext::new(llmod);
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_llvm/src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ impl<'ll, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
unsafe { llvm::LLVMDoubleTypeInContext(self.llcx) }
}

fn type_void(&self) -> &'ll Type {
unsafe { llvm::LLVMVoidTypeInContext(self.llcx) }
}

fn type_func(&self, args: &[&'ll Type], ret: &'ll Type) -> &'ll Type {
unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, False) }
}
Expand Down
28 changes: 26 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use std::cell::OnceCell;
use std::collections::BTreeSet;
use std::ffi::OsString;
use std::fs::{read, File, OpenOptions};
use std::io::{BufWriter, Write};
use std::io::{prelude::*, BufWriter, SeekFrom, Write};
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::process::{ExitStatus, Output, Stdio};
Expand Down Expand Up @@ -310,6 +310,10 @@ fn link_rlib<'a>(
let (metadata, metadata_position) =
create_wrapper_file(sess, b".rmeta".to_vec(), codegen_results.metadata.raw_data());
let metadata = emit_wrapper_file(sess, &metadata, tmpdir, METADATA_FILENAME);
if sess.opts.cg.target_cpu.as_ref().unwrap_or(
&sess.target.cpu.as_ref().to_string()) == "sbfv2" {
patch_synthetic_object_file(sess, &metadata);
}
match metadata_position {
MetadataPosition::First => {
// Most of the time metadata in rlib files is wrapped in a "dummy" object
Expand Down Expand Up @@ -1798,14 +1802,19 @@ fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor)
cmd.args(&sess.opts.unstable_opts.pre_link_args);
}

/// Add a link script embedded in the target, if applicable.
/// Add a link script embedded in the target, if applicable and not found in the command line.
fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_type: CrateType) {
match (crate_type, &sess.target.link_script) {
(CrateType::Cdylib | CrateType::Executable, Some(script)) => {
if !sess.target.linker_flavor.is_gnu() {
sess.emit_fatal(errors::LinkScriptUnavailable);
}

if sess.opts.cg.link_args.contains(&String::from("--script"))
|| sess.opts.cg.link_args.contains(&String::from("-T")) {
return;
}

let file_name = ["rustc", &sess.target.llvm_target, "linkfile.ld"].join("-");

let path = tmpdir.join(file_name);
Expand Down Expand Up @@ -1936,9 +1945,24 @@ fn add_linked_symbol_object(
if let Err(error) = result {
sess.emit_fatal(errors::FailedToWrite { path, error });
}
if sess.opts.cg.target_cpu.as_ref().unwrap_or(
&sess.target.cpu.as_ref().to_string()) == "sbfv2" {
patch_synthetic_object_file(sess, &path);
}
cmd.add_object(&path);
}

fn patch_synthetic_object_file(sess: &Session, path: &PathBuf) {
const EM_SBF: [u8; 2] = [0x07, 0x01];
if let Ok(mut sf) = fs::OpenOptions::new().write(true).open(path) {
if let Ok(_) = sf.seek(SeekFrom::Start(0x12)) {
sf.write(&EM_SBF).unwrap();
}
} else {
sess.fatal(format!("failed to patch {}", path.display()));
}
}

/// Add object files containing code from the current crate.
fn add_local_crate_regular_objects(cmd: &mut dyn Linker, codegen_results: &CodegenResults) {
for obj in codegen_results.modules.iter().filter_map(|m| m.object.as_ref()) {
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,17 @@ impl<'a> GccLinker<'a> {
self.linker_arg(&format!("--out-implib={}", (*implib).to_str().unwrap()));
}
}
} else if self.sess.target.arch == "bpf" || self.sess.target.arch == "sbf" {
if self.sess.opts.test {
self.linker_arg("--entry=main");
} else {
self.linker_arg("--entry=entrypoint");
}
if self.sess.opts.cg.target_cpu.as_ref().unwrap_or(&self.sess.target.cpu.as_ref().to_string()) == "sbfv2"
{
self.linker_arg("--section-start=.text=0x100000000");
self.linker_arg("--pack-dyn-relocs=relr");
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,10 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
"avr" => Architecture::Avr,
"msp430" => Architecture::Msp430,
"hexagon" => Architecture::Hexagon,
"bpf" => Architecture::Bpf,
"loongarch64" => Architecture::LoongArch64,
"csky" => Architecture::Csky,
"bpf" => Architecture::Bpf,
"sbf" => Architecture::Bpf,
// Unsupported architecture.
_ => return None,
};
Expand Down
Loading
Loading