Skip to content

Commit 6d51c1c

Browse files
authored
Rollup merge of #111772 - liushuyu:ubuntu/mips64-linkage, r=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 #52108
2 parents 3ceff00 + b65c2af commit 6d51c1c

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

compiler/rustc_target/src/spec/mips64_unknown_linux_gnuabi64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn target() -> Target {
1212
endian: Endian::Big,
1313
// NOTE(mips64r2) matches C toolchain
1414
cpu: "mips64r2".into(),
15-
features: "+mips64r2".into(),
15+
features: "+mips64r2,+xgot".into(),
1616
max_atomic_width: Some(64),
1717
mcount: "_mcount".into(),
1818

compiler/rustc_target/src/spec/mips64el_unknown_linux_gnuabi64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn target() -> Target {
1010
abi: "abi64".into(),
1111
// NOTE(mips64r2) matches C toolchain
1212
cpu: "mips64r2".into(),
13-
features: "+mips64r2".into(),
13+
features: "+mips64r2,+xgot".into(),
1414
max_atomic_width: Some(64),
1515
mcount: "_mcount".into(),
1616

src/bootstrap/bootstrap.py

+6
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,12 @@ def build_bootstrap(self, color, verbose_count):
877877

878878
# preserve existing RUSTFLAGS
879879
env.setdefault("RUSTFLAGS", "")
880+
# we need to explicitly add +xgot here so that we can successfully bootstrap
881+
# a usable stage1 compiler
882+
# FIXME: remove this if condition on the next bootstrap bump
883+
# cfg(bootstrap)
884+
if self.build_triple().startswith('mips'):
885+
env["RUSTFLAGS"] += " -Ctarget-feature=+xgot"
880886
target_features = []
881887
if self.get_toml("crt-static", build_section) == "true":
882888
target_features += ["+crt-static"]

tests/assembly/asm/mips-types.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => {
7272

7373
// mips32-LABEL: sym_static_32:
7474
// mips32: #APP
75-
// mips32: lw $3, %got(extern_static)
75+
// mips32: lw $3, %got(extern_static)($gp)
7676
// mips32: #NO_APP
7777
#[cfg(mips32)]
7878
#[no_mangle]
@@ -82,7 +82,7 @@ pub unsafe fn sym_static_32() {
8282

8383
// mips32-LABEL: sym_fn_32:
8484
// mips32: #APP
85-
// mips32: lw $3, %got(extern_func)
85+
// mips32: lw $3, %got(extern_func)($gp)
8686
// mips32: #NO_APP
8787
#[cfg(mips32)]
8888
#[no_mangle]
@@ -92,7 +92,9 @@ pub unsafe fn sym_fn_32() {
9292

9393
// mips64-LABEL: sym_static_64:
9494
// mips64: #APP
95-
// mips64: ld $3, %got_disp(extern_static)
95+
// mips64: lui $3, %got_hi(extern_static)
96+
// mips64: daddu $3, $3, $gp
97+
// mips64: ld $3, %got_lo(extern_static)($3)
9698
// mips64: #NO_APP
9799
#[cfg(mips64)]
98100
#[no_mangle]
@@ -102,7 +104,9 @@ pub unsafe fn sym_static_64() {
102104

103105
// mips64-LABEL: sym_fn_64:
104106
// mips64: #APP
105-
// mips64: ld $3, %got_disp(extern_func)
107+
// mips64: lui $3, %got_hi(extern_func)
108+
// mips64: daddu $3, $3, $gp
109+
// mips64: ld $3, %got_lo(extern_func)($3)
106110
// mips64: #NO_APP
107111
#[cfg(mips64)]
108112
#[no_mangle]

0 commit comments

Comments
 (0)