From 83602e05b61217e0a74c0e58560873e4775f26c0 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Wed, 1 Apr 2020 11:13:25 -0400 Subject: [PATCH] cranelift-object: mark output as using non-executable stacks The `faerie` crate does this by default. `object` itself does not, but it seems reasonable to make this change for parity between `cranelift-faerie` and `cranelift-object`. --- cranelift/object/src/backend.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cranelift/object/src/backend.rs b/cranelift/object/src/backend.rs index f651ad69b4..d4b899a460 100644 --- a/cranelift/object/src/backend.rs +++ b/cranelift/object/src/backend.rs @@ -13,7 +13,9 @@ use cranelift_module::{ use object::write::{ Object, Relocation, SectionId, StandardSection, Symbol, SymbolId, SymbolSection, }; -use object::{RelocationEncoding, RelocationKind, SymbolFlags, SymbolKind, SymbolScope}; +use object::{ + RelocationEncoding, RelocationKind, SectionKind, SymbolFlags, SymbolKind, SymbolScope, +}; use std::collections::HashMap; use std::mem; use target_lexicon::{BinaryFormat, PointerWidth}; @@ -380,6 +382,15 @@ impl Backend for ObjectBackend { } } + // Indicate that this object has a non-executable stack. + if self.object.format() == BinaryFormat::Elf { + self.object.add_section( + vec![], + ".note.GNU-stack".as_bytes().to_vec(), + SectionKind::Linker, + ); + } + ObjectProduct { object: self.object, functions: self.functions,