Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf symbols: Check compatible symtab type before loading dso

When loading a dso it'll look for symbol tables of all possible types.
However it's just wasted of time to check incompatible types - like
trying kernel module when loading user library.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Cody P Schafer <cody@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1392859976-32760-4-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
1029f9fe 0d3dc5e8

+52 -9
+52 -9
tools/perf/util/symbol.c
··· 1251 1251 return -1; 1252 1252 } 1253 1253 1254 + static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod, 1255 + enum dso_binary_type type) 1256 + { 1257 + switch (type) { 1258 + case DSO_BINARY_TYPE__JAVA_JIT: 1259 + case DSO_BINARY_TYPE__DEBUGLINK: 1260 + case DSO_BINARY_TYPE__SYSTEM_PATH_DSO: 1261 + case DSO_BINARY_TYPE__FEDORA_DEBUGINFO: 1262 + case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO: 1263 + case DSO_BINARY_TYPE__BUILDID_DEBUGINFO: 1264 + case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO: 1265 + return !kmod && dso->kernel == DSO_TYPE_USER; 1266 + 1267 + case DSO_BINARY_TYPE__KALLSYMS: 1268 + case DSO_BINARY_TYPE__VMLINUX: 1269 + case DSO_BINARY_TYPE__KCORE: 1270 + return dso->kernel == DSO_TYPE_KERNEL; 1271 + 1272 + case DSO_BINARY_TYPE__GUEST_KALLSYMS: 1273 + case DSO_BINARY_TYPE__GUEST_VMLINUX: 1274 + case DSO_BINARY_TYPE__GUEST_KCORE: 1275 + return dso->kernel == DSO_TYPE_GUEST_KERNEL; 1276 + 1277 + case DSO_BINARY_TYPE__GUEST_KMODULE: 1278 + case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE: 1279 + /* 1280 + * kernel modules know their symtab type - it's set when 1281 + * creating a module dso in machine__new_module(). 1282 + */ 1283 + return kmod && dso->symtab_type == type; 1284 + 1285 + case DSO_BINARY_TYPE__BUILD_ID_CACHE: 1286 + return true; 1287 + 1288 + case DSO_BINARY_TYPE__NOT_FOUND: 1289 + default: 1290 + return false; 1291 + } 1292 + } 1293 + 1254 1294 int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) 1255 1295 { 1256 1296 char *name; ··· 1301 1261 int ss_pos = 0; 1302 1262 struct symsrc ss_[2]; 1303 1263 struct symsrc *syms_ss = NULL, *runtime_ss = NULL; 1264 + bool kmod; 1304 1265 1305 1266 dso__set_loaded(dso, map->type); 1306 1267 ··· 1342 1301 if (!name) 1343 1302 return -1; 1344 1303 1345 - /* Iterate over candidate debug images. 1304 + kmod = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE || 1305 + dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE; 1306 + 1307 + /* 1308 + * Iterate over candidate debug images. 1346 1309 * Keep track of "interesting" ones (those which have a symtab, dynsym, 1347 1310 * and/or opd section) for processing. 1348 1311 */ ··· 1355 1310 bool next_slot = false; 1356 1311 1357 1312 enum dso_binary_type symtab_type = binary_type_symtab[i]; 1313 + 1314 + if (!dso__is_compatible_symtab_type(dso, kmod, symtab_type)) 1315 + continue; 1358 1316 1359 1317 if (dso__read_binary_type_filename(dso, symtab_type, 1360 1318 root_dir, name, PATH_MAX)) ··· 1399 1351 if (!runtime_ss && syms_ss) 1400 1352 runtime_ss = syms_ss; 1401 1353 1402 - if (syms_ss) { 1403 - int km; 1404 - 1405 - km = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE || 1406 - dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE; 1407 - ret = dso__load_sym(dso, map, syms_ss, runtime_ss, filter, km); 1408 - } else { 1354 + if (syms_ss) 1355 + ret = dso__load_sym(dso, map, syms_ss, runtime_ss, filter, kmod); 1356 + else 1409 1357 ret = -1; 1410 - } 1411 1358 1412 1359 if (ret > 0) { 1413 1360 int nr_plt;