Skip to content

Commit f07f4ef

Browse files
committed
Auto merge of #28427 - DiamondLovesYou:gdb-debug-script-load, r=alexcrichton
This is so LLVM isn't forced to load every byte of it. Also sets the alignment of the load. Adds a test for the debug script section. r? @alexcrichton
2 parents e9d2587 + 9a24025 commit f07f4ef

File tree

10 files changed

+50
-4
lines changed

10 files changed

+50
-4
lines changed

src/compiletest/runtest.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1669,8 +1669,7 @@ fn compile_test_and_save_ir(config: &Config, props: &TestProps,
16691669
// FIXME (#9639): This needs to handle non-utf8 paths
16701670
let mut link_args = vec!("-L".to_owned(),
16711671
aux_dir.to_str().unwrap().to_owned());
1672-
let llvm_args = vec!("--emit=llvm-ir".to_owned(),
1673-
"--crate-type=lib".to_owned());
1672+
let llvm_args = vec!("--emit=llvm-ir".to_owned(),);
16741673
link_args.extend(llvm_args);
16751674
let args = make_compile_args(config,
16761675
props,

src/librustc_trans/trans/debuginfo/gdb.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use llvm;
1414
use llvm::ValueRef;
1515

16-
use trans::common::{C_bytes, CrateContext};
16+
use trans::common::{C_bytes, CrateContext, C_i32};
1717
use trans::declare;
1818
use trans::type_::Type;
1919
use session::config::NoDebugInfo;
@@ -31,11 +31,21 @@ pub fn insert_reference_to_gdb_debug_scripts_section_global(ccx: &CrateContext)
3131
let gdb_debug_scripts_section_global =
3232
get_or_insert_gdb_debug_scripts_section_global(ccx);
3333
unsafe {
34+
// Load just the first byte as that's all that's necessary to force
35+
// LLVM to keep around the reference to the global.
36+
let indices = [C_i32(ccx, 0), C_i32(ccx, 0)];
37+
let element =
38+
llvm::LLVMBuildInBoundsGEP(ccx.raw_builder(),
39+
gdb_debug_scripts_section_global,
40+
indices.as_ptr(),
41+
indices.len() as ::libc::c_uint,
42+
empty.as_ptr());
3443
let volative_load_instruction =
3544
llvm::LLVMBuildLoad(ccx.raw_builder(),
36-
gdb_debug_scripts_section_global,
45+
element,
3746
empty.as_ptr());
3847
llvm::LLVMSetVolatile(volative_load_instruction, llvm::True);
48+
llvm::LLVMSetAlignment(volative_load_instruction, 1);
3949
}
4050
}
4151
}

src/test/codegen/adjustments.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// compile-flags: -C no-prepopulate-passes
1212

13+
#![crate_type = "lib"]
14+
1315
// Hack to get the correct size for the length part in slices
1416
// CHECK: @helper([[USIZE:i[0-9]+]])
1517
#[no_mangle]

src/test/codegen/coercions.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// compile-flags: -C no-prepopulate-passes
1212

13+
#![crate_type = "lib"]
14+
1315
static X: i32 = 5;
1416

1517
// CHECK-LABEL: @raw_ptr_to_raw_ptr_noop

src/test/codegen/extern-functions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
// compile-flags: -C no-prepopulate-passes
1212

13+
#![crate_type = "lib"]
1314
#![feature(unwind_attributes)]
1415

1516
extern {

src/test/codegen/function-arguments.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
// compile-flags: -C no-prepopulate-passes
1212

13+
#![crate_type = "lib"]
1314
#![feature(allocator)]
1415

1516
pub struct S {
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2015 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+
// ignore-tidy-linelength
12+
// ignore-windows
13+
// ignore-macos
14+
15+
// compile-flags: -g -C no-prepopulate-passes
16+
17+
#![feature(start)]
18+
19+
// CHECK-LABEL: @main
20+
// CHECK: load volatile i8, i8* getelementptr inbounds ([[B:\[[0-9]* x i8\]]], [[B]]* @__rustc_debug_gdb_scripts_section__, i32 0, i32 0), align 1
21+
22+
#[start]
23+
fn start(_: isize, _: *const *const u8) -> isize {
24+
return 0;
25+
}

src/test/codegen/link_section.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// compile-flags: -C no-prepopulate-passes
1212

13+
#![crate_type = "lib"]
14+
1315
// CHECK: @VAR1 = constant i32 1, section ".test_one"
1416
#[no_mangle]
1517
#[link_section = ".test_one"]

src/test/codegen/loads.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// compile-flags: -C no-prepopulate-passes
1212

13+
#![crate_type = "lib"]
14+
1315
pub struct Bytes {
1416
a: u8,
1517
b: u8,

src/test/codegen/stores.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// compile-flags: -C no-prepopulate-passes
1212

13+
#![crate_type = "lib"]
14+
1315
pub struct Bytes {
1416
a: u8,
1517
b: u8,

0 commit comments

Comments
 (0)