From 96f5eba4f5603c612464d6b1e961677e9d7084d3 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 18 Aug 2014 14:15:05 -0400 Subject: [PATCH] work around MinGW linker bug for ASLR on Windows Closes #16514 --- src/librustc/middle/trans/base.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 2098f923dbe..e3dfd4f534d 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -87,7 +87,7 @@ use std::cell::{Cell, RefCell}; use std::rc::Rc; use std::{i8, i16, i32, i64}; use syntax::abi::{X86, X86_64, Arm, Mips, Mipsel, Rust, RustCall}; -use syntax::abi::{RustIntrinsic, Abi}; +use syntax::abi::{RustIntrinsic, Abi, OsWindows}; use syntax::ast_util::{local_def, is_local}; use syntax::attr::AttrMetaMethods; use syntax::attr; @@ -2446,6 +2446,13 @@ pub fn create_entry_wrapper(ccx: &CrateContext, &ccx.int_type); let llfn = decl_cdecl_fn(ccx, "main", llfty, ty::mk_nil()); + + // FIXME: #16581: Marking a symbol in the executable with `dllexport` + // linkage forces MinGW's linker to output a `.reloc` section for ASLR + if ccx.sess().targ_cfg.os == OsWindows { + unsafe { llvm::LLVMRustSetDLLExportStorageClass(llfn) } + } + let llbb = "top".with_c_str(|buf| { unsafe { llvm::LLVMAppendBasicBlockInContext(ccx.llcx, llfn, buf)