Skip to content

Commit

Permalink
Rollup merge of rust-lang#111772 - liushuyu:ubuntu/mips64-linkage, r=…
Browse files Browse the repository at this point in the history
…jackh726

Fix linkage for large binaries on mips64 platforms

This pull request fixes the linkage for large binaries on mips64 platforms by enabling the `xgot` feature in LLVM.

It is well understood that the generated binary will gain a hefty performance penalty where the external symbol jumps now cost at least three instructions each.

Also, this pull request does not address the same issue on the mips32 counterparts (due to being unable to test the changes thoroughly).

Should fix rust-lang#52108
  • Loading branch information
matthiaskrgr authored May 31, 2023
2 parents 617d3d6 + b65c2af commit fd1c0d8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn target() -> Target {
endian: Endian::Big,
// NOTE(mips64r2) matches C toolchain
cpu: "mips64r2".into(),
features: "+mips64r2".into(),
features: "+mips64r2,+xgot".into(),
max_atomic_width: Some(64),
mcount: "_mcount".into(),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn target() -> Target {
abi: "abi64".into(),
// NOTE(mips64r2) matches C toolchain
cpu: "mips64r2".into(),
features: "+mips64r2".into(),
features: "+mips64r2,+xgot".into(),
max_atomic_width: Some(64),
mcount: "_mcount".into(),

Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,12 @@ def build_bootstrap(self, color, verbose_count):

# preserve existing RUSTFLAGS
env.setdefault("RUSTFLAGS", "")
# we need to explicitly add +xgot here so that we can successfully bootstrap
# a usable stage1 compiler
# FIXME: remove this if condition on the next bootstrap bump
# cfg(bootstrap)
if self.build_triple().startswith('mips'):
env["RUSTFLAGS"] += " -Ctarget-feature=+xgot"
target_features = []
if self.get_toml("crt-static", build_section) == "true":
target_features += ["+crt-static"]
Expand Down
12 changes: 8 additions & 4 deletions tests/assembly/asm/mips-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => {

// mips32-LABEL: sym_static_32:
// mips32: #APP
// mips32: lw $3, %got(extern_static)
// mips32: lw $3, %got(extern_static)($gp)
// mips32: #NO_APP
#[cfg(mips32)]
#[no_mangle]
Expand All @@ -82,7 +82,7 @@ pub unsafe fn sym_static_32() {

// mips32-LABEL: sym_fn_32:
// mips32: #APP
// mips32: lw $3, %got(extern_func)
// mips32: lw $3, %got(extern_func)($gp)
// mips32: #NO_APP
#[cfg(mips32)]
#[no_mangle]
Expand All @@ -92,7 +92,9 @@ pub unsafe fn sym_fn_32() {

// mips64-LABEL: sym_static_64:
// mips64: #APP
// mips64: ld $3, %got_disp(extern_static)
// mips64: lui $3, %got_hi(extern_static)
// mips64: daddu $3, $3, $gp
// mips64: ld $3, %got_lo(extern_static)($3)
// mips64: #NO_APP
#[cfg(mips64)]
#[no_mangle]
Expand All @@ -102,7 +104,9 @@ pub unsafe fn sym_static_64() {

// mips64-LABEL: sym_fn_64:
// mips64: #APP
// mips64: ld $3, %got_disp(extern_func)
// mips64: lui $3, %got_hi(extern_func)
// mips64: daddu $3, $3, $gp
// mips64: ld $3, %got_lo(extern_func)($3)
// mips64: #NO_APP
#[cfg(mips64)]
#[no_mangle]
Expand Down

0 comments on commit fd1c0d8

Please sign in to comment.