/[packages]/cauldron/rust/current/SOURCES/0001-Set-more-llvm-function-attributes-for-__rust_try.patch
ViewVC logotype

Contents of /cauldron/rust/current/SOURCES/0001-Set-more-llvm-function-attributes-for-__rust_try.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1308362 - (show annotations) (download)
Thu Sep 27 11:47:39 2018 UTC (6 years ago) by akien
File size: 7976 byte(s)
- Sync with Fedora: Tue Sep 25 2018 Josh Stone <jistone@redhat.com> - 1.29.1-2
  o Update to 1.29.1.
  o Security fix for str::repeat (pending CVE).
  o Update to 1.29.0.
  o Add a clippy-preview subpackage

1 From 4b95b1a4fd035a73998dc21b265ce4594e35f8ae Mon Sep 17 00:00:00 2001
2 From: Alex Crichton <alex@alexcrichton.com>
3 Date: Thu, 16 Aug 2018 13:19:04 -0700
4 Subject: [PATCH] Set more llvm function attributes for __rust_try
5
6 This shim is generated elsewhere in the compiler so this commit adds support to
7 ensure it goes through similar paths as the rest of the compiler to set llvm
8 function attributes like target features.
9
10 cc #53372
11 ---
12 src/librustc_codegen_llvm/attributes.rs | 52 +++++++++++++++++++------
13 src/librustc_codegen_llvm/base.rs | 21 ----------
14 src/librustc_codegen_llvm/callee.rs | 2 +-
15 src/librustc_codegen_llvm/intrinsic.rs | 2 +
16 src/librustc_codegen_llvm/mono_item.rs | 2 +-
17 5 files changed, 44 insertions(+), 35 deletions(-)
18
19 diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs
20 index 3b5f927d52f0..2a79ce2f2285 100644
21 --- a/src/librustc_codegen_llvm/attributes.rs
22 +++ b/src/librustc_codegen_llvm/attributes.rs
23 @@ -11,7 +11,7 @@
24
25 use std::ffi::{CStr, CString};
26
27 -use rustc::hir::CodegenFnAttrFlags;
28 +use rustc::hir::{CodegenFnAttrFlags, CodegenFnAttrs};
29 use rustc::hir::def_id::{DefId, LOCAL_CRATE};
30 use rustc::session::Session;
31 use rustc::session::config::Sanitizer;
32 @@ -123,11 +123,37 @@ pub fn llvm_target_features(sess: &Session) -> impl Iterator<Item = &str> {
33
34 /// Composite function which sets LLVM attributes for function depending on its AST (#[attribute])
35 /// attributes.
36 -pub fn from_fn_attrs(cx: &CodegenCx, llfn: ValueRef, id: DefId) {
37 - let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(id);
38 +pub fn from_fn_attrs(
39 + cx: &CodegenCx,
40 + llfn: ValueRef,
41 + id: Option<DefId>,
42 +) {
43 + let codegen_fn_attrs = id.map(|id| cx.tcx.codegen_fn_attrs(id))
44 + .unwrap_or(CodegenFnAttrs::new());
45
46 inline(llfn, codegen_fn_attrs.inline);
47
48 + // The `uwtable` attribute according to LLVM is:
49 + //
50 + // This attribute indicates that the ABI being targeted requires that an
51 + // unwind table entry be produced for this function even if we can show
52 + // that no exceptions passes by it. This is normally the case for the
53 + // ELF x86-64 abi, but it can be disabled for some compilation units.
54 + //
55 + // Typically when we're compiling with `-C panic=abort` (which implies this
56 + // `no_landing_pads` check) we don't need `uwtable` because we can't
57 + // generate any exceptions! On Windows, however, exceptions include other
58 + // events such as illegal instructions, segfaults, etc. This means that on
59 + // Windows we end up still needing the `uwtable` attribute even if the `-C
60 + // panic=abort` flag is passed.
61 + //
62 + // You can also find more info on why Windows is whitelisted here in:
63 + // https://bugzilla.mozilla.org/show_bug.cgi?id=1302078
64 + if !cx.sess().no_landing_pads() ||
65 + cx.sess().target.target.options.requires_uwtable {
66 + attributes::emit_uwtable(llfn, true);
67 + }
68 +
69 set_frame_pointer_elimination(cx, llfn);
70 set_probestack(cx, llfn);
71
72 @@ -151,7 +177,7 @@ pub fn from_fn_attrs(cx: &CodegenCx, llfn: ValueRef, id: DefId) {
73 // *in Rust code* may unwind. Foreign items like `extern "C" {
74 // fn foo(); }` are assumed not to unwind **unless** they have
75 // a `#[unwind]` attribute.
76 - } else if !cx.tcx.is_foreign_item(id) {
77 + } else if id.map(|id| !cx.tcx.is_foreign_item(id)).unwrap_or(false) {
78 Some(true)
79 } else {
80 None
81 @@ -188,14 +214,16 @@ pub fn from_fn_attrs(cx: &CodegenCx, llfn: ValueRef, id: DefId) {
82 // Note that currently the `wasm-import-module` doesn't do anything, but
83 // eventually LLVM 7 should read this and ferry the appropriate import
84 // module to the output file.
85 - if cx.tcx.sess.target.target.arch == "wasm32" {
86 - if let Some(module) = wasm_import_module(cx.tcx, id) {
87 - llvm::AddFunctionAttrStringValue(
88 - llfn,
89 - llvm::AttributePlace::Function,
90 - cstr("wasm-import-module\0"),
91 - &module,
92 - );
93 + if let Some(id) = id {
94 + if cx.tcx.sess.target.target.arch == "wasm32" {
95 + if let Some(module) = wasm_import_module(cx.tcx, id) {
96 + llvm::AddFunctionAttrStringValue(
97 + llfn,
98 + llvm::AttributePlace::Function,
99 + cstr("wasm-import-module\0"),
100 + &module,
101 + );
102 + }
103 }
104 }
105 }
106 diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs
107 index 223c04f420f3..b0461582ddcb 100644
108 --- a/src/librustc_codegen_llvm/base.rs
109 +++ b/src/librustc_codegen_llvm/base.rs
110 @@ -486,27 +486,6 @@ pub fn codegen_instance<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, instance: Instance<'
111
112 cx.stats.borrow_mut().n_closures += 1;
113
114 - // The `uwtable` attribute according to LLVM is:
115 - //
116 - // This attribute indicates that the ABI being targeted requires that an
117 - // unwind table entry be produced for this function even if we can show
118 - // that no exceptions passes by it. This is normally the case for the
119 - // ELF x86-64 abi, but it can be disabled for some compilation units.
120 - //
121 - // Typically when we're compiling with `-C panic=abort` (which implies this
122 - // `no_landing_pads` check) we don't need `uwtable` because we can't
123 - // generate any exceptions! On Windows, however, exceptions include other
124 - // events such as illegal instructions, segfaults, etc. This means that on
125 - // Windows we end up still needing the `uwtable` attribute even if the `-C
126 - // panic=abort` flag is passed.
127 - //
128 - // You can also find more info on why Windows is whitelisted here in:
129 - // https://bugzilla.mozilla.org/show_bug.cgi?id=1302078
130 - if !cx.sess().no_landing_pads() ||
131 - cx.sess().target.target.options.requires_uwtable {
132 - attributes::emit_uwtable(lldecl, true);
133 - }
134 -
135 let mir = cx.tcx.instance_mir(instance.def);
136 mir::codegen_mir(cx, lldecl, &mir, instance, sig);
137 }
138 diff --git a/src/librustc_codegen_llvm/callee.rs b/src/librustc_codegen_llvm/callee.rs
139 index 2c01bd42cc77..97f07792ede8 100644
140 --- a/src/librustc_codegen_llvm/callee.rs
141 +++ b/src/librustc_codegen_llvm/callee.rs
142 @@ -97,7 +97,7 @@ pub fn get_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
143 if instance.def.is_inline(tcx) {
144 attributes::inline(llfn, attributes::InlineAttr::Hint);
145 }
146 - attributes::from_fn_attrs(cx, llfn, instance.def.def_id());
147 + attributes::from_fn_attrs(cx, llfn, Some(instance.def.def_id()));
148
149 let instance_def_id = instance.def_id();
150
151 diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs
152 index 9c5c0f730c16..f69fce15dc55 100644
153 --- a/src/librustc_codegen_llvm/intrinsic.rs
154 +++ b/src/librustc_codegen_llvm/intrinsic.rs
155 @@ -10,6 +10,7 @@
156
157 #![allow(non_upper_case_globals)]
158
159 +use attributes;
160 use intrinsics::{self, Intrinsic};
161 use llvm;
162 use llvm::{ValueRef};
163 @@ -936,6 +937,7 @@ fn gen_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
164 Abi::Rust
165 )));
166 let llfn = declare::define_internal_fn(cx, name, rust_fn_ty);
167 + attributes::from_fn_attrs(cx, llfn, None);
168 let bx = Builder::new_block(cx, llfn, "entry-block");
169 codegen(bx);
170 llfn
171 diff --git a/src/librustc_codegen_llvm/mono_item.rs b/src/librustc_codegen_llvm/mono_item.rs
172 index a528008e3b4b..32d8b24e3c15 100644
173 --- a/src/librustc_codegen_llvm/mono_item.rs
174 +++ b/src/librustc_codegen_llvm/mono_item.rs
175 @@ -183,7 +183,7 @@ fn predefine_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
176 if instance.def.is_inline(cx.tcx) {
177 attributes::inline(lldecl, attributes::InlineAttr::Hint);
178 }
179 - attributes::from_fn_attrs(cx, lldecl, instance.def.def_id());
180 + attributes::from_fn_attrs(cx, lldecl, Some(instance.def.def_id()));
181
182 cx.instances.borrow_mut().insert(instance, lldecl);
183 }
184 --
185 2.17.1
186

  ViewVC Help
Powered by ViewVC 1.1.30