Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions crates/symbol-check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use std::{env, fs};

use object::read::archive::ArchiveFile;
use object::{
Architecture, BinaryFormat, Endianness, File as ObjFile, Object, ObjectSection, ObjectSymbol,
Result as ObjResult, SectionFlags, Symbol, SymbolKind, SymbolScope, U32, elf,
Architecture, BinaryFormat, Endianness, File as ObjFile, FileFlags, Object, ObjectSection,
ObjectSymbol, Result as ObjResult, SectionFlags, Symbol, SymbolKind, SymbolScope, U32, elf,
};
use regex::Regex;
use serde_json::Value;
Expand Down Expand Up @@ -526,12 +526,15 @@ fn check_elf_exe_stack(obj: &ObjFile) -> Result<(), ExeStack> {
return Ok(());
}

let FileFlags::Elf { e_flags, .. } = obj.flags() else {
unreachable!("only elf files are being checked");
};

// If there is no `.note.GNU-stack` and no executable sections, behavior differs by platform.
match obj.architecture() {
// PPC64 doesn't set `.note.GNU-stack` since GNU nested functions don't need a trampoline,
// <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21098>. From experimentation, it seems
// like this only applies to big endian.
Architecture::PowerPc64 if obj.endianness() == Endianness::Big => Ok(()),
// <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21098>. This only applies to ELFv1.
Architecture::PowerPc64 if e_flags & elf::EF_PPC64_ABI != 2 => Ok(()),

_ => Err(ExeStack::MissingGnuStackSec),
}
Expand Down
15 changes: 11 additions & 4 deletions crates/symbol-check/tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ mod exe_stack {

let assert = t.symcheck_exe().arg(obj).arg("--no-visibility").assert();

if t.is_ppc64be() || t.no_os() || t.binary_obj_format() != BinaryFormat::Elf {
// Ppc64be doesn't emit `.note.GNU-stack`, not relevant without an OS, and non-elf
if (t.is_ppc64be() && t.is_glibc())
|| t.no_os()
|| t.binary_obj_format() != BinaryFormat::Elf
{
// Ppc64be ELFv1 doesn't emit `.note.GNU-stack`, not relevant without an OS, and non-elf
// targets don't use `.note.GNU-stack`.
assert.success();
return;
Expand Down Expand Up @@ -143,8 +146,8 @@ mod exe_stack {

let assert = t.symcheck_exe().arg(obj).arg("--no-visibility").assert();

if t.is_ppc64be() || t.no_os() {
// Ppc64be doesn't emit `.note.GNU-stack`, not relevant without an OS.
if (t.is_ppc64be() && t.is_glibc()) || t.no_os() {
// Ppc64be ELFv1 doesn't emit `.note.GNU-stack`, not relevant without an OS.
assert.success();
return;
}
Expand Down Expand Up @@ -316,6 +319,10 @@ impl TestTarget {
self.triple.starts_with("powerpc64-")
}

fn is_glibc(&self) -> bool {
self.triple.contains("-linux-gnu")
}

/// True if the target needs `--no-os` passed to symcheck.
fn no_os(&self) -> bool {
self.triple.contains("-none")
Expand Down
6 changes: 6 additions & 0 deletions crates/symbol-check/tests/input/missing_gnu_stack_section.S
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
* executability is implied (usually yes on Linux).
*/

/* Unless we set the ABI version, we have no way to differentiate between
big-endian ppc64 ELFv1 or ELFv2 since e_flags is otherwise unspecified */
#if defined(__powerpc64__) && _CALL_ELF == 2
.abiversion 2
#endif

.global func

#ifdef __wasm__
Expand Down
Loading