Skip to content

Commit a9f24f3

Browse files
committed
Make globals always have 2+ chars as suffix
As discussed on chat, there currently is the bug where certain suffixes are interpreted by the (m68k) assembler. Example: `move.l #global.w,-44(%fp)` `.w` is interpreted by the assembler as a size hint for #global.
1 parent 9f33f84 commit a9f24f3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/context.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use gccjit::{
66
use rustc_codegen_ssa::base::wants_msvc_seh;
77
use rustc_codegen_ssa::errors as ssa_errors;
88
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeCodegenMethods, MiscCodegenMethods};
9-
use rustc_data_structures::base_n::{ALPHANUMERIC_ONLY, ToBaseN};
9+
use rustc_data_structures::base_n::{ToBaseN, ALPHANUMERIC_ONLY};
1010
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1111
use rustc_middle::mir::mono::CodegenUnit;
1212
use rustc_middle::span_bug;
@@ -17,7 +17,7 @@ use rustc_middle::ty::layout::{
1717
use rustc_middle::ty::{self, Instance, PolyExistentialTraitRef, Ty, TyCtxt};
1818
use rustc_session::Session;
1919
use rustc_span::source_map::respan;
20-
use rustc_span::{DUMMY_SP, Span};
20+
use rustc_span::{Span, DUMMY_SP};
2121
use rustc_target::abi::{HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx};
2222
use rustc_target::spec::{
2323
HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, Target, TlsModel, WasmCAbi, X86Abi,
@@ -606,7 +606,10 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
606606
let mut name = String::with_capacity(prefix.len() + 6);
607607
name.push_str(prefix);
608608
name.push('.');
609-
name.push_str(&(idx as u64).to_base(ALPHANUMERIC_ONLY));
609+
// Offset the index by the base so that always at least two characters
610+
// are generated. This avoids cases where the suffix is interpreted as
611+
// size by the assembler (for m68k: .b, .w, .l).
612+
name.push_str(&(idx as u64 + ALPHANUMERIC_ONLY as u64).to_base(ALPHANUMERIC_ONLY));
610613
name
611614
}
612615
}

0 commit comments

Comments
 (0)