Skip to content

Commit 795f6ae

Browse files
committed
auto merge of rust-lang#16213 : huonw/rust/more-token-numbers, r=pnkfelix
Using the Show impl for Names created global symbols with names like `"str\"str\"(1027)"`. This adjusts strings, binaries and vtables to avoid using that impl.
2 parents 765a23f + e753dbb commit 795f6ae

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

src/librustc/middle/trans/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> Va
574574
!null_terminated as Bool);
575575

576576
let gsym = token::gensym("str");
577-
let g = format!("str{}", gsym).with_c_str(|buf| {
577+
let g = format!("str{}", gsym.uint()).with_c_str(|buf| {
578578
llvm::LLVMAddGlobal(cx.llmod, val_ty(sc).to_ref(), buf)
579579
});
580580
llvm::LLVMSetInitializer(g, sc);
@@ -603,7 +603,7 @@ pub fn C_binary_slice(cx: &CrateContext, data: &[u8]) -> ValueRef {
603603
let lldata = C_bytes(cx, data);
604604

605605
let gsym = token::gensym("binary");
606-
let g = format!("binary{}", gsym).with_c_str(|buf| {
606+
let g = format!("binary{}", gsym.uint()).with_c_str(|buf| {
607607
llvm::LLVMAddGlobal(cx.llmod, val_ty(lldata).to_ref(), buf)
608608
});
609609
llvm::LLVMSetInitializer(g, lldata);

src/librustc/middle/trans/meth.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ pub fn make_vtable<I: Iterator<ValueRef>>(ccx: &CrateContext,
528528
unsafe {
529529
let tbl = C_struct(ccx, components.as_slice(), false);
530530
let sym = token::gensym("vtable");
531-
let vt_gvar = format!("vtable{}", sym).with_c_str(|buf| {
531+
let vt_gvar = format!("vtable{}", sym.uint()).with_c_str(|buf| {
532532
llvm::LLVMAddGlobal(ccx.llmod, val_ty(tbl).to_ref(), buf)
533533
});
534534
llvm::LLVMSetInitializer(vt_gvar, tbl);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-include ../tools.mk
2+
3+
# check that the compile generated symbols for strings, binaries,
4+
# vtables, etc. have semisane names (e.g. `str1234`); it's relatively
5+
# easy to accidentally modify the compiler internals to make them
6+
# become things like `str"str"(1234)`.
7+
8+
OUT=$(TMPDIR)/lib.s
9+
10+
all:
11+
$(RUSTC) lib.rs --emit=asm --crate-type=staticlib
12+
# just check for symbol declarations with the names we're expecting.
13+
grep 'str[0-9]\+:' $(OUT)
14+
grep 'binary[0-9]\+:' $(OUT)
15+
grep 'vtable[0-9]\+' $(OUT)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub static X: &'static str = "foobarbaz";
12+
pub static Y: &'static [u8] = include_bin!("lib.rs");
13+
14+
trait Foo {}
15+
impl Foo for uint {}
16+
17+
pub fn dummy() {
18+
// force the vtable to be created
19+
let _x = &1u as &Foo;
20+
}

0 commit comments

Comments
 (0)