Skip to content

Commit 425ff2a

Browse files
committed
update
1 parent 30fd257 commit 425ff2a

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

crates/symbol-check/build.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
fn main() {
2-
let intermediates = cc::Build::new()
3-
.file("has_wx.c")
4-
.try_compile_intermediates();
5-
if let Ok(list) = intermediates {
6-
let [obj] = list.as_slice() else {
7-
panic!(">1 output")
8-
};
9-
println!("cargo::rustc-env=HAS_WX_OBJ={}", obj.display());
2+
let objs = cc::Build::new()
3+
.file("tests/no_gnu_stack.S")
4+
.compile_intermediates();
5+
let [obj] = objs.as_slice() else {
6+
panic!(">1 output")
7+
};
8+
println!("cargo::rustc-env=NO_GNU_STACK_OBJ={}", obj.display());
9+
10+
let mut b = cc::Build::new();
11+
if !b.get_compiler().is_like_gnu() {
12+
println!("cargo::warning=Can't run execstack test; non-GNU compiler");
13+
return;
1014
}
15+
16+
let objs = b.file("tests/has_exe_stack.c").compile_intermediates();
17+
let [obj] = objs.as_slice() else {
18+
panic!(">1 output")
19+
};
20+
println!("cargo::rustc-env=HAS_EXE_STACK_OBJ={}", obj.display());
1121
}

crates/symbol-check/src/main.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use std::process::{Command, Stdio};
1010
use object::elf::SHF_EXECINSTR;
1111
use object::read::archive::{ArchiveFile, ArchiveMember};
1212
use object::{
13-
File as ObjFile, Object, ObjectSection, ObjectSymbol, SectionFlags, Symbol, SymbolKind,
14-
SymbolScope,
13+
BinaryFormat, File as ObjFile, Object, ObjectSection, ObjectSymbol, SectionFlags, Symbol,
14+
SymbolKind, SymbolScope,
1515
};
1616
use serde_json::Value;
1717

@@ -309,6 +309,9 @@ fn verify_core_symbols(archive: &Archive) {
309309
/// - A `.note.GNU-stack` section without the exe flag means there is no executable stack needed
310310
/// - Without the section, behavior is target-specific and on some targets means an executable
311311
/// stack is required.
312+
///
313+
/// Now says
314+
/// deprecated <https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0d38576a34ec64a1b4500c9277a8e9d0f07e6774>.
312315
fn verify_no_exec_stack(archive: &Archive) {
313316
let mut problem_objfiles = Vec::new();
314317

@@ -327,7 +330,7 @@ fn verify_no_exec_stack(archive: &Archive) {
327330

328331
fn obj_requires_exe_stack(obj: &ObjFile) -> bool {
329332
// Files other than elf likely do not use the same convention.
330-
if !matches!(obj, ObjFile::Elf32(_) | ObjFile::Elf64(_)) {
333+
if obj.format() != BinaryFormat::Elf {
331334
return false;
332335
}
333336

@@ -395,9 +398,18 @@ impl Archive {
395398
}
396399
}
397400

401+
#[test]
402+
fn check_no_gnu_stack_obj() {
403+
// Should be supported on all Unix platforms
404+
let p = env!("NO_GNU_STACK_OBJ");
405+
let f = fs::read(p).unwrap();
406+
let obj = ObjFile::parse(f.as_slice()).unwrap();
407+
assert!(obj_requires_exe_stack(&obj));
408+
}
409+
398410
#[test]
399411
fn check_obj() {
400-
let p = option_env!("HAS_WX_OBJ").expect("this platform should support the wx test build");
412+
let p = option_env!("HAS_EXE_STACK_OBJ").expect("has_exe_stack.o not present");
401413
let f = fs::read(p).unwrap();
402414
let obj = ObjFile::parse(f.as_slice()).unwrap();
403415
assert!(obj_requires_exe_stack(&obj));

crates/symbol-check/has_wx.c renamed to crates/symbol-check/tests/has_exe_stack.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* GNU nested functions are the only way I could fine to force an executable
2+
* stack. Supported by GCC only, not Clang. */
3+
14
void intermediate(void (*)(int, int), int);
25

36
int hack(int *array, int size) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
; Assembly files do not get a `.note.GNU-stack` section, meaning executable
2+
; by default.
3+
nop

0 commit comments

Comments
 (0)