Skip to content

Commit

Permalink
Never emit INLINE_ORIGIN directives lacking a function name
Browse files Browse the repository at this point in the history
This handles cases where the names of inlined functions are missing.
This is a bit odd because when it comes to symbols the name is an option
and thus is None when it cannot be loaded from the debug information,
but in the case of inlined functions where the name is in a separate
debuginfo file pointed to by the .gnu_debugaltlink section the name is
just empty.

The basic.dwz file used for testing was produced in the following way:
a copy was made of the basic.dbg file then the dwz tool was used to
strip away the shared data (including the .debug_str section) and put it
in a separate file, the separate file was then thrown away so calling
dump_syms on basic.dwz would be unable to find the names for the inlined
functions. The changes to basic.dbg were obviously reverted and only the
modified basic.dwz file was kept.

cp test_data/linux/basic.dbg test_data/linux/basic.dwz
dwz -m basic test_data/linux/basic.dbg test_data/linux/basic.dwz

This fixes issue #475.
  • Loading branch information
gabrielesvelto committed Sep 23, 2022
1 parent fd64871 commit c7df854
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/action.rs
Expand Up @@ -307,4 +307,37 @@ mod tests {

assert_eq!(basic, new);
}

#[test]
fn test_elf_dwz_with_inlines() {
let tmp_dir = Builder::new().prefix("dwz").tempdir().unwrap();
let full = PathBuf::from("./test_data/linux/basic.dwz");
let tmp_out = tmp_dir.path().join("output.sym");

let action = Action::Dump(Config {
output: tmp_out.clone().into(),
symbol_server: None,
debug_id: None,
code_id: None,
arch: common::get_compile_time_arch(),
num_jobs: 1,
mapping_var: None,
mapping_src: None,
mapping_dest: None,
mapping_file: None,
check_cfi: false,
emit_inlines: true,
});

action.action(&[full.to_str().unwrap()]).unwrap();

let data = read(tmp_out).unwrap();
let new: Vec<_> = data.split(|c| *c == b'\n').skip(1).collect();

let basic = PathBuf::from("./test_data/linux/basic.dwz.inlines.sym");
let data = read(basic).unwrap();
let basic: Vec<_> = data.split(|c| *c == b'\n').skip(1).collect();

assert_eq!(basic, new);
}
}
5 changes: 5 additions & 0 deletions src/object_info.rs
Expand Up @@ -59,6 +59,11 @@ impl Display for ObjectInfo {
}

for (n, function_name) in self.inline_origins.iter().enumerate() {
let function_name = if function_name.is_empty() {
"<name omitted>"
} else {
function_name
};
writeln!(f, "INLINE_ORIGIN {} {}", n, function_name)?;
}

Expand Down
Binary file added test_data/linux/basic.dwz
Binary file not shown.
86 changes: 86 additions & 0 deletions test_data/linux/basic.dwz.inlines.sym
@@ -0,0 +1,86 @@
MODULE Linux x86_64 20AD60B0B4C68177552708AA192E77390 basic.dwz
INFO CODE_ID B060AD20C6B47781552708AA192E7739FAC7C84A
FILE 0 /basic.cpp
INLINE_ORIGIN 0 <name omitted>
PUBLIC 1000 0 _init
PUBLIC 1020 0 <.plt ELF section in basic.dwz>
PUBLIC 1030 0 <.plt.got ELF section in basic.dwz>
PUBLIC 1040 0 _start
PUBLIC 1070 0 deregister_tm_clones
PUBLIC 10a0 0 register_tm_clones
PUBLIC 10e0 0 __do_global_dtors_aux
PUBLIC 1120 0 frame_dummy
FUNC 1125 26 0 inline_1(int)
1125 7 2 0
112c 9 3 0
1135 11 4 0
1146 3 5 0
1149 2 6 0
FUNC 114b 2c 0 inline_2(int)
INLINE 0 10 0 0 1158 1d
114b d 9 0
1158 9 3 0
1161 11 4 0
1172 3 5 0
1175 2 11 0
FUNC 1177 33 0 inline_3(int)
INLINE 0 15 0 0 118a 1e
INLINE 1 10 0 0 118a 1d
1177 13 14 0
118a 9 3 0
1193 11 4 0
11a4 3 5 0
11a7 1 10 0
11a8 2 16 0
FUNC 11aa 3a 0 inline_4(int)
INLINE 0 20 0 0 11c3 1f
INLINE 1 15 0 0 11c3 1e
INLINE 2 10 0 0 11c3 1d
11aa 19 19 0
11c3 9 3 0
11cc 11 4 0
11dd 3 5 0
11e0 1 10 0
11e1 1 15 0
11e2 2 21 0
FUNC 11e4 d9 0 foo(int)
INLINE 0 26 0 0 120e 20
INLINE 1 20 0 0 120e 1f 1265 1f
INLINE 2 15 0 0 120e 1e 1265 1e
INLINE 3 10 0 0 120e 1d 1265 1d
INLINE 0 29 0 0 1265 20 1292 1e
INLINE 1 10 0 0 1292 1d
11e4 7 24 0
11eb 9 25 0
11f4 1a 26 0
120e 9 3 0
1217 11 4 0
1228 3 5 0
122b 1 10 0
122c 1 15 0
122d 1 20 0
122e 3 26 0
1231 d 27 0
123e c 28 0
124a 1b 29 0
1265 9 3 0
126e 11 4 0
127f 3 5 0
1282 1 10 0
1283 1 15 0
1284 1 20 0
1285 d 29 0
1292 9 3 0
129b 11 4 0
12ac 3 5 0
12af 1 10 0
12b0 3 29 0
12b3 8 31 0
12bb 2 32 0
FUNC 12bd 1c 0 main
12bd f 35 0
12cc b 36 0
12d7 2 37 0
PUBLIC 12e0 0 __libc_csu_init
PUBLIC 1340 0 __libc_csu_fini
PUBLIC 1344 0 _fini

0 comments on commit c7df854

Please sign in to comment.