Skip to content

Commit

Permalink
Consider ifunc symbols also defined
Browse files Browse the repository at this point in the history
Looks like php may be built with certain optimizations causing some symbols to be resolved as ifunc.
The object crate is not recognizing these as definition, but for our purposes, it is one.

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
  • Loading branch information
bwoebi committed Sep 5, 2024
1 parent e899c91 commit 610f2f4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tools/sidecar_mockgen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

use object::{File, Object, ObjectSymbol, SymbolKind};
use object::{File, Object, ObjectSymbol, Symbol, SymbolFlags, SymbolKind};
use std::collections::HashSet;
use std::fmt::Write;
use std::path::Path;
Expand Down Expand Up @@ -41,10 +41,21 @@ pub fn generate_mock_symbols(binary: &Path, objects: &[&Path]) -> Result<String,
}
}
}

fn sym_is_definition(sym: &Symbol) -> bool {
if sym.is_definition() {
return true;
}
match sym.flags() {
// 10 == STT_GNU_IFUNC for ELF files
SymbolFlags::Elf { st_info, .. } => st_info & 0xf == 10,
_ => false,
}
}

let mut generated = String::new();
for sym in so_file.symbols().chain(so_file.dynamic_symbols()) {
if sym.is_definition() {
if sym_is_definition(&sym) {
if let Ok(name) = sym.name() {
if missing_symbols.remove(name) {
// strip leading underscore
Expand Down

0 comments on commit 610f2f4

Please sign in to comment.