Skip to content

Commit beb1767

Browse files
committed
Don't export global allocs which are not statics
They aren't be referenced outside of the current cgu anyway. This should make optimizations a bit more effective.
1 parent 710b741 commit beb1767

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

src/consts.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
170170
match kind {
171171
Some(kind) if !self.tcx.sess.fewer_names() => {
172172
let name = self.generate_local_symbol_name(kind);
173-
// TODO(antoyo): check if it's okay that TLS is off here.
174-
// TODO(antoyo): check if it's okay that link_section is None here.
173+
// TODO(antoyo): check if it's okay that no link_section is set.
175174
// TODO(antoyo): set alignment here as well.
176-
let global = self.define_global(&name[..], self.val_ty(cv), false, None);
177-
// TODO(antoyo): set linkage.
175+
let global = self.declare_private_global(&name[..], self.val_ty(cv));
178176
global
179177
}
180178
_ => {
@@ -183,8 +181,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
183181
global
184182
},
185183
};
186-
// FIXME(antoyo): I think the name coming from generate_local_symbol_name() above cannot be used
187-
// globally.
188184
global.global_set_initializer_rvalue(cv);
189185
// TODO(antoyo): set unnamed address.
190186
let rvalue = global.get_address(None);

src/context.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDat
1818
use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
1919

2020
use crate::callee::get_fn;
21-
use crate::declare::mangle_name;
2221

2322
#[derive(Clone)]
2423
pub struct FuncSig<'gcc> {
@@ -96,7 +95,6 @@ pub struct CodegenCx<'gcc, 'tcx> {
9695

9796
/// A counter that is used for generating local symbol names
9897
local_gen_sym_counter: Cell<usize>,
99-
pub global_gen_sym_counter: Cell<usize>,
10098

10199
eh_personality: Cell<Option<RValue<'gcc>>>,
102100

@@ -221,7 +219,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
221219
struct_types: Default::default(),
222220
types_with_fields_to_set: Default::default(),
223221
local_gen_sym_counter: Cell::new(0),
224-
global_gen_sym_counter: Cell::new(0),
225222
eh_personality: Cell::new(None),
226223
pointee_infos: Default::default(),
227224
structs_as_pointer: Default::default(),
@@ -503,11 +500,6 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
503500
}
504501
}
505502

506-
pub fn unit_name<'tcx>(codegen_unit: &CodegenUnit<'tcx>) -> String {
507-
let name = &codegen_unit.name().to_string();
508-
mangle_name(&name.replace('-', "_"))
509-
}
510-
511503
fn to_gcc_tls_mode(tls_model: TlsModel) -> gccjit::TlsModel {
512504
match tls_model {
513505
TlsModel::GeneralDynamic => gccjit::TlsModel::GlobalDynamic,

src/declare.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_span::Symbol;
55
use rustc_target::abi::call::FnAbi;
66

77
use crate::abi::FnAbiGccExt;
8-
use crate::context::{CodegenCx, unit_name};
8+
use crate::context::CodegenCx;
99
use crate::intrinsic::llvm;
1010

1111
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
@@ -27,10 +27,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
2727
}
2828

2929
pub fn declare_unnamed_global(&self, ty: Type<'gcc>) -> LValue<'gcc> {
30-
let index = self.global_gen_sym_counter.get();
31-
self.global_gen_sym_counter.set(index + 1);
32-
let name = format!("global_{}_{}", index, unit_name(&self.codegen_unit));
33-
self.context.new_global(None, GlobalKind::Exported, ty, &name)
30+
let name = self.generate_local_symbol_name("global");
31+
self.context.new_global(None, GlobalKind::Internal, ty, &name)
3432
}
3533

3634
pub fn declare_global_with_linkage(&self, name: &str, ty: Type<'gcc>, linkage: GlobalKind) -> LValue<'gcc> {

0 commit comments

Comments
 (0)