Skip to content

rustc: Anti-copy police #5899

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct EncodeParams {
reachable: reachable::map,
reexports2: middle::resolve::ExportMap2,
item_symbols: @mut HashMap<ast::node_id, ~str>,
discrim_symbols: @mut HashMap<ast::node_id, ~str>,
discrim_symbols: @mut HashMap<ast::node_id, @~str>,
link_meta: LinkMeta,
cstore: @mut cstore::CStore,
encode_inlined_item: encode_inlined_item
Expand All @@ -90,7 +90,7 @@ pub struct EncodeContext {
reachable: reachable::map,
reexports2: middle::resolve::ExportMap2,
item_symbols: @mut HashMap<ast::node_id, ~str>,
discrim_symbols: @mut HashMap<ast::node_id, ~str>,
discrim_symbols: @mut HashMap<ast::node_id, @~str>,
link_meta: LinkMeta,
cstore: @mut cstore::CStore,
encode_inlined_item: encode_inlined_item,
Expand Down Expand Up @@ -285,7 +285,7 @@ fn encode_symbol(ecx: @EncodeContext, ebml_w: writer::Encoder, id: node_id) {
fn encode_discriminant(ecx: @EncodeContext, ebml_w: writer::Encoder,
id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
ebml_w.writer.write(str::to_bytes(*ecx.discrim_symbols.get(&id)));
ebml_w.writer.write(str::to_bytes(**ecx.discrim_symbols.get(&id)));
ebml_w.end_tag();
}

Expand Down
13 changes: 5 additions & 8 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,9 @@ pub fn set_glue_inlining(f: ValueRef, t: ty::t) {

// Double-check that we never ask LLVM to declare the same symbol twice. It
// silently mangles such symbols, breaking our linkage model.
pub fn note_unique_llvm_symbol(ccx: @CrateContext, +sym: ~str) {
// XXX: this should not be necessary
use core::container::Set;
pub fn note_unique_llvm_symbol(ccx: @CrateContext, sym: @~str) {
if ccx.all_llvm_symbols.contains(&sym) {
ccx.sess.bug(~"duplicate LLVM symbol: " + sym);
ccx.sess.bug(~"duplicate LLVM symbol: " + *sym);
}
ccx.all_llvm_symbols.insert(sym);
}
Expand Down Expand Up @@ -2576,11 +2574,10 @@ pub fn trans_constant(ccx: @CrateContext, it: @ast::item) {
path_name(variant.node.name),
path_name(special_idents::descrim)
]);
let s = mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
let s = @mangle_exported_name(ccx, p, ty::mk_int(ccx.tcx));
let disr_val = vi[i].disr_val;
// XXX: Bad copy.
note_unique_llvm_symbol(ccx, copy s);
let discrim_gvar = str::as_c_str(s, |buf| {
note_unique_llvm_symbol(ccx, s);
let discrim_gvar = str::as_c_str(*s, |buf| {
unsafe {
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub struct CrateContext {
link_meta: LinkMeta,
enum_sizes: @mut HashMap<ty::t, uint>,
discrims: @mut HashMap<ast::def_id, ValueRef>,
discrim_symbols: @mut HashMap<ast::node_id, ~str>,
discrim_symbols: @mut HashMap<ast::node_id, @~str>,
tydescs: @mut HashMap<ty::t, @mut tydesc_info>,
// Set when running emit_tydescs to enforce that no more tydescs are
// created.
Expand Down Expand Up @@ -215,7 +215,7 @@ pub struct CrateContext {
symbol_hasher: @hash::State,
type_hashcodes: @mut HashMap<ty::t, @str>,
type_short_names: @mut HashMap<ty::t, ~str>,
all_llvm_symbols: @mut HashSet<~str>,
all_llvm_symbols: @mut HashSet<@~str>,
tcx: ty::ctxt,
maps: astencode::Maps,
stats: @mut Stats,
Expand Down
26 changes: 12 additions & 14 deletions src/librustc/middle/trans/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,15 +684,14 @@ pub fn declare_tydesc(ccx: @CrateContext, t: ty::t) -> @mut tydesc_info {
let llalign = llalign_of(ccx, llty);
let addrspace = declare_tydesc_addrspace(ccx, t);
//XXX this triggers duplicate LLVM symbols
let name = if false /*ccx.sess.opts.debuginfo*/ {
let name = @(if false /*ccx.sess.opts.debuginfo*/ {
mangle_internal_name_by_type_only(ccx, t, ~"tydesc")
} else {
mangle_internal_name_by_seq(ccx, ~"tydesc")
};
// XXX: Bad copy.
note_unique_llvm_symbol(ccx, copy name);
debug!("+++ declare_tydesc %s %s", ppaux::ty_to_str(ccx.tcx, t), name);
let gvar = str::as_c_str(name, |buf| {
});
note_unique_llvm_symbol(ccx, name);
debug!("+++ declare_tydesc %s %s", ppaux::ty_to_str(ccx.tcx, t), *name);
let gvar = str::as_c_str(*name, |buf| {
unsafe {
llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type, buf)
}
Expand All @@ -718,17 +717,16 @@ pub fn declare_generic_glue(ccx: @CrateContext, t: ty::t, llfnty: TypeRef,
+name: ~str) -> ValueRef {
let _icx = ccx.insn_ctxt("declare_generic_glue");
let name = name;
let mut fn_nm;
//XXX this triggers duplicate LLVM symbols
if false /*ccx.sess.opts.debuginfo*/ {
fn_nm = mangle_internal_name_by_type_only(ccx, t, (~"glue_" + name));
let fn_nm = @(if false /*ccx.sess.opts.debuginfo*/ {
mangle_internal_name_by_type_only(ccx, t, (~"glue_" + name))
} else {
fn_nm = mangle_internal_name_by_seq(ccx, (~"glue_" + name));
}
debug!("%s is for type %s", fn_nm, ppaux::ty_to_str(ccx.tcx, t));
mangle_internal_name_by_seq(ccx, (~"glue_" + name))
});
debug!("%s is for type %s", *fn_nm, ppaux::ty_to_str(ccx.tcx, t));
// XXX: Bad copy.
note_unique_llvm_symbol(ccx, copy fn_nm);
let llfn = decl_cdecl_fn(ccx.llmod, fn_nm, llfnty);
note_unique_llvm_symbol(ccx, fn_nm);
let llfn = decl_cdecl_fn(ccx.llmod, *fn_nm, llfnty);
set_glue_inlining(llfn, t);
return llfn;
}
Expand Down