Skip to content

Commit

Permalink
Enable fatal errors by default
Browse files Browse the repository at this point in the history
Ignore errors emitted on calls to builtins which are spurious. These
builtins end up being lowered to libcalls to hidden functions, which are
totally OK. See https://reviews.llvm.org/D155894 and
aya-rs/aya#698 for some additional discussion.

There doesn't seem to be a silver bullet here; BPF is fundamentally
adversarial to these memory intrinsics. We can revisit this once we have
DI and can more easily locate the source location that results in their
inclusion.
  • Loading branch information
tamird committed Jul 28, 2023
1 parent 92b7410 commit e474f82
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/bin/bpf-linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct CommandLine {
export: Vec<String>,

/// Whether to treat LLVM errors as fatal.
#[clap(long, action = clap::ArgAction::Set, default_value_t = false)]
#[clap(long, action = clap::ArgAction::Set, default_value_t = true)]
fatal_errors: bool,

// The options below are for wasm-ld compatibility
Expand Down
16 changes: 16 additions & 0 deletions src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,24 @@ impl Linker {

impl llvm::LLVMDiagnosticHandler for Linker {
fn handle_diagnostic(&mut self, severity: llvm_sys::LLVMDiagnosticSeverity, message: &str) {
// TODO(https://reviews.llvm.org/D155894): Remove this when LLVM no longer emits these
// errors.
//
// See https://github.com/rust-lang/compiler-builtins/blob/a61823f/src/mem/mod.rs#L22-L68.
const MATCHERS: &[&str] = &[
"A call to built-in function 'memcpy' is not supported.\n",
"A call to built-in function 'memmove' is not supported.\n",
"A call to built-in function 'memset' is not supported.\n",
"A call to built-in function 'memcmp' is not supported.\n",
"A call to built-in function 'bcmp' is not supported.\n",
"A call to built-in function 'strlen' is not supported.\n",
];

match severity {
llvm_sys::LLVMDiagnosticSeverity::LLVMDSError => {
if MATCHERS.iter().any(|matcher| message.ends_with(matcher)) {
return;
}
self.has_errors = true;

error!("llvm: {}", message)
Expand Down
2 changes: 1 addition & 1 deletion tests/assembly/auxiliary/dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
#[no_mangle]
fn some_dep() -> u8 {
42
}
}
1 change: 0 additions & 1 deletion tests/assembly/auxiliary/loop-panic-handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
fn panic_impl(_: &core::panic::PanicInfo) -> ! {
loop {}
}

2 changes: 1 addition & 1 deletion tests/assembly/elf-sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ static mut COUNTER: u32 = 0;

// CHECK: .section "uprobe/connect","ax"
// CHECK: .section "uprobe/dep","ax"
// CHECK: .section "maps/counter","aw"
// CHECK: .section "maps/counter","aw"
2 changes: 1 addition & 1 deletion tests/assembly/re-export-symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ fn connect() {
}

// CHECK: .globl connect
// CHECK: .globl some_dep
// CHECK: .globl some_dep

0 comments on commit e474f82

Please sign in to comment.