symbol.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112
  1. #include <dirent.h>
  2. #include <errno.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <linux/kernel.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <sys/param.h>
  10. #include <fcntl.h>
  11. #include <unistd.h>
  12. #include <inttypes.h>
  13. #include "annotate.h"
  14. #include "build-id.h"
  15. #include "util.h"
  16. #include "debug.h"
  17. #include "machine.h"
  18. #include "symbol.h"
  19. #include "strlist.h"
  20. #include "intlist.h"
  21. #include "header.h"
  22. #include "path.h"
  23. #include "sane_ctype.h"
  24. #include <elf.h>
  25. #include <limits.h>
  26. #include <symbol/kallsyms.h>
  27. #include <sys/utsname.h>
  28. static int dso__load_kernel_sym(struct dso *dso, struct map *map);
  29. static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map);
  30. static bool symbol__is_idle(const char *name);
  31. int vmlinux_path__nr_entries;
  32. char **vmlinux_path;
  33. struct symbol_conf symbol_conf = {
  34. .use_modules = true,
  35. .try_vmlinux_path = true,
  36. .annotate_src = true,
  37. .demangle = true,
  38. .demangle_kernel = false,
  39. .cumulate_callchain = true,
  40. .show_hist_headers = true,
  41. .symfs = "",
  42. .event_group = true,
  43. };
  44. static enum dso_binary_type binary_type_symtab[] = {
  45. DSO_BINARY_TYPE__KALLSYMS,
  46. DSO_BINARY_TYPE__GUEST_KALLSYMS,
  47. DSO_BINARY_TYPE__JAVA_JIT,
  48. DSO_BINARY_TYPE__DEBUGLINK,
  49. DSO_BINARY_TYPE__BUILD_ID_CACHE,
  50. DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
  51. DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
  52. DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
  53. DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
  54. DSO_BINARY_TYPE__GUEST_KMODULE,
  55. DSO_BINARY_TYPE__GUEST_KMODULE_COMP,
  56. DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
  57. DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP,
  58. DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO,
  59. DSO_BINARY_TYPE__NOT_FOUND,
  60. };
  61. #define DSO_BINARY_TYPE__SYMTAB_CNT ARRAY_SIZE(binary_type_symtab)
  62. bool symbol_type__is_a(char symbol_type, enum map_type map_type)
  63. {
  64. symbol_type = toupper(symbol_type);
  65. switch (map_type) {
  66. case MAP__FUNCTION:
  67. return symbol_type == 'T' || symbol_type == 'W';
  68. case MAP__VARIABLE:
  69. return symbol_type == 'D';
  70. default:
  71. return false;
  72. }
  73. }
  74. static int prefix_underscores_count(const char *str)
  75. {
  76. const char *tail = str;
  77. while (*tail == '_')
  78. tail++;
  79. return tail - str;
  80. }
  81. int __weak arch__choose_best_symbol(struct symbol *syma,
  82. struct symbol *symb __maybe_unused)
  83. {
  84. /* Avoid "SyS" kernel syscall aliases */
  85. if (strlen(syma->name) >= 3 && !strncmp(syma->name, "SyS", 3))
  86. return SYMBOL_B;
  87. if (strlen(syma->name) >= 10 && !strncmp(syma->name, "compat_SyS", 10))
  88. return SYMBOL_B;
  89. return SYMBOL_A;
  90. }
  91. static int choose_best_symbol(struct symbol *syma, struct symbol *symb)
  92. {
  93. s64 a;
  94. s64 b;
  95. size_t na, nb;
  96. /* Prefer a symbol with non zero length */
  97. a = syma->end - syma->start;
  98. b = symb->end - symb->start;
  99. if ((b == 0) && (a > 0))
  100. return SYMBOL_A;
  101. else if ((a == 0) && (b > 0))
  102. return SYMBOL_B;
  103. /* Prefer a non weak symbol over a weak one */
  104. a = syma->binding == STB_WEAK;
  105. b = symb->binding == STB_WEAK;
  106. if (b && !a)
  107. return SYMBOL_A;
  108. if (a && !b)
  109. return SYMBOL_B;
  110. /* Prefer a global symbol over a non global one */
  111. a = syma->binding == STB_GLOBAL;
  112. b = symb->binding == STB_GLOBAL;
  113. if (a && !b)
  114. return SYMBOL_A;
  115. if (b && !a)
  116. return SYMBOL_B;
  117. /* Prefer a symbol with less underscores */
  118. a = prefix_underscores_count(syma->name);
  119. b = prefix_underscores_count(symb->name);
  120. if (b > a)
  121. return SYMBOL_A;
  122. else if (a > b)
  123. return SYMBOL_B;
  124. /* Choose the symbol with the longest name */
  125. na = strlen(syma->name);
  126. nb = strlen(symb->name);
  127. if (na > nb)
  128. return SYMBOL_A;
  129. else if (na < nb)
  130. return SYMBOL_B;
  131. return arch__choose_best_symbol(syma, symb);
  132. }
  133. void symbols__fixup_duplicate(struct rb_root *symbols)
  134. {
  135. struct rb_node *nd;
  136. struct symbol *curr, *next;
  137. if (symbol_conf.allow_aliases)
  138. return;
  139. nd = rb_first(symbols);
  140. while (nd) {
  141. curr = rb_entry(nd, struct symbol, rb_node);
  142. again:
  143. nd = rb_next(&curr->rb_node);
  144. next = rb_entry(nd, struct symbol, rb_node);
  145. if (!nd)
  146. break;
  147. if (curr->start != next->start)
  148. continue;
  149. if (choose_best_symbol(curr, next) == SYMBOL_A) {
  150. rb_erase(&next->rb_node, symbols);
  151. symbol__delete(next);
  152. goto again;
  153. } else {
  154. nd = rb_next(&curr->rb_node);
  155. rb_erase(&curr->rb_node, symbols);
  156. symbol__delete(curr);
  157. }
  158. }
  159. }
  160. void symbols__fixup_end(struct rb_root *symbols)
  161. {
  162. struct rb_node *nd, *prevnd = rb_first(symbols);
  163. struct symbol *curr, *prev;
  164. if (prevnd == NULL)
  165. return;
  166. curr = rb_entry(prevnd, struct symbol, rb_node);
  167. for (nd = rb_next(prevnd); nd; nd = rb_next(nd)) {
  168. prev = curr;
  169. curr = rb_entry(nd, struct symbol, rb_node);
  170. if (prev->end == prev->start && prev->end != curr->start)
  171. prev->end = curr->start;
  172. }
  173. /* Last entry */
  174. if (curr->end == curr->start)
  175. curr->end = roundup(curr->start, 4096) + 4096;
  176. }
  177. void __map_groups__fixup_end(struct map_groups *mg, enum map_type type)
  178. {
  179. struct maps *maps = &mg->maps[type];
  180. struct map *next, *curr;
  181. pthread_rwlock_wrlock(&maps->lock);
  182. curr = maps__first(maps);
  183. if (curr == NULL)
  184. goto out_unlock;
  185. for (next = map__next(curr); next; next = map__next(curr)) {
  186. curr->end = next->start;
  187. curr = next;
  188. }
  189. /*
  190. * We still haven't the actual symbols, so guess the
  191. * last map final address.
  192. */
  193. curr->end = ~0ULL;
  194. out_unlock:
  195. pthread_rwlock_unlock(&maps->lock);
  196. }
  197. struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name)
  198. {
  199. size_t namelen = strlen(name) + 1;
  200. struct symbol *sym = calloc(1, (symbol_conf.priv_size +
  201. sizeof(*sym) + namelen));
  202. if (sym == NULL)
  203. return NULL;
  204. if (symbol_conf.priv_size) {
  205. if (symbol_conf.init_annotation) {
  206. struct annotation *notes = (void *)sym;
  207. pthread_mutex_init(&notes->lock, NULL);
  208. }
  209. sym = ((void *)sym) + symbol_conf.priv_size;
  210. }
  211. sym->start = start;
  212. sym->end = len ? start + len : start;
  213. sym->binding = binding;
  214. sym->namelen = namelen - 1;
  215. pr_debug4("%s: %s %#" PRIx64 "-%#" PRIx64 "\n",
  216. __func__, name, start, sym->end);
  217. memcpy(sym->name, name, namelen);
  218. return sym;
  219. }
  220. void symbol__delete(struct symbol *sym)
  221. {
  222. free(((void *)sym) - symbol_conf.priv_size);
  223. }
  224. void symbols__delete(struct rb_root *symbols)
  225. {
  226. struct symbol *pos;
  227. struct rb_node *next = rb_first(symbols);
  228. while (next) {
  229. pos = rb_entry(next, struct symbol, rb_node);
  230. next = rb_next(&pos->rb_node);
  231. rb_erase(&pos->rb_node, symbols);
  232. symbol__delete(pos);
  233. }
  234. }
  235. void __symbols__insert(struct rb_root *symbols, struct symbol *sym, bool kernel)
  236. {
  237. struct rb_node **p = &symbols->rb_node;
  238. struct rb_node *parent = NULL;
  239. const u64 ip = sym->start;
  240. struct symbol *s;
  241. if (kernel) {
  242. const char *name = sym->name;
  243. /*
  244. * ppc64 uses function descriptors and appends a '.' to the
  245. * start of every instruction address. Remove it.
  246. */
  247. if (name[0] == '.')
  248. name++;
  249. sym->idle = symbol__is_idle(name);
  250. }
  251. while (*p != NULL) {
  252. parent = *p;
  253. s = rb_entry(parent, struct symbol, rb_node);
  254. if (ip < s->start)
  255. p = &(*p)->rb_left;
  256. else
  257. p = &(*p)->rb_right;
  258. }
  259. rb_link_node(&sym->rb_node, parent, p);
  260. rb_insert_color(&sym->rb_node, symbols);
  261. }
  262. void symbols__insert(struct rb_root *symbols, struct symbol *sym)
  263. {
  264. __symbols__insert(symbols, sym, false);
  265. }
  266. static struct symbol *symbols__find(struct rb_root *symbols, u64 ip)
  267. {
  268. struct rb_node *n;
  269. if (symbols == NULL)
  270. return NULL;
  271. n = symbols->rb_node;
  272. while (n) {
  273. struct symbol *s = rb_entry(n, struct symbol, rb_node);
  274. if (ip < s->start)
  275. n = n->rb_left;
  276. else if (ip > s->end || (ip == s->end && ip != s->start))
  277. n = n->rb_right;
  278. else
  279. return s;
  280. }
  281. return NULL;
  282. }
  283. static struct symbol *symbols__first(struct rb_root *symbols)
  284. {
  285. struct rb_node *n = rb_first(symbols);
  286. if (n)
  287. return rb_entry(n, struct symbol, rb_node);
  288. return NULL;
  289. }
  290. static struct symbol *symbols__last(struct rb_root *symbols)
  291. {
  292. struct rb_node *n = rb_last(symbols);
  293. if (n)
  294. return rb_entry(n, struct symbol, rb_node);
  295. return NULL;
  296. }
  297. static struct symbol *symbols__next(struct symbol *sym)
  298. {
  299. struct rb_node *n = rb_next(&sym->rb_node);
  300. if (n)
  301. return rb_entry(n, struct symbol, rb_node);
  302. return NULL;
  303. }
  304. static void symbols__insert_by_name(struct rb_root *symbols, struct symbol *sym)
  305. {
  306. struct rb_node **p = &symbols->rb_node;
  307. struct rb_node *parent = NULL;
  308. struct symbol_name_rb_node *symn, *s;
  309. symn = container_of(sym, struct symbol_name_rb_node, sym);
  310. while (*p != NULL) {
  311. parent = *p;
  312. s = rb_entry(parent, struct symbol_name_rb_node, rb_node);
  313. if (strcmp(sym->name, s->sym.name) < 0)
  314. p = &(*p)->rb_left;
  315. else
  316. p = &(*p)->rb_right;
  317. }
  318. rb_link_node(&symn->rb_node, parent, p);
  319. rb_insert_color(&symn->rb_node, symbols);
  320. }
  321. static void symbols__sort_by_name(struct rb_root *symbols,
  322. struct rb_root *source)
  323. {
  324. struct rb_node *nd;
  325. for (nd = rb_first(source); nd; nd = rb_next(nd)) {
  326. struct symbol *pos = rb_entry(nd, struct symbol, rb_node);
  327. symbols__insert_by_name(symbols, pos);
  328. }
  329. }
  330. static struct symbol *symbols__find_by_name(struct rb_root *symbols,
  331. const char *name)
  332. {
  333. struct rb_node *n;
  334. struct symbol_name_rb_node *s = NULL;
  335. if (symbols == NULL)
  336. return NULL;
  337. n = symbols->rb_node;
  338. while (n) {
  339. int cmp;
  340. s = rb_entry(n, struct symbol_name_rb_node, rb_node);
  341. cmp = arch__compare_symbol_names(name, s->sym.name);
  342. if (cmp < 0)
  343. n = n->rb_left;
  344. else if (cmp > 0)
  345. n = n->rb_right;
  346. else
  347. break;
  348. }
  349. if (n == NULL)
  350. return NULL;
  351. /* return first symbol that has same name (if any) */
  352. for (n = rb_prev(n); n; n = rb_prev(n)) {
  353. struct symbol_name_rb_node *tmp;
  354. tmp = rb_entry(n, struct symbol_name_rb_node, rb_node);
  355. if (arch__compare_symbol_names(tmp->sym.name, s->sym.name))
  356. break;
  357. s = tmp;
  358. }
  359. return &s->sym;
  360. }
  361. void dso__reset_find_symbol_cache(struct dso *dso)
  362. {
  363. enum map_type type;
  364. for (type = MAP__FUNCTION; type <= MAP__VARIABLE; ++type) {
  365. dso->last_find_result[type].addr = 0;
  366. dso->last_find_result[type].symbol = NULL;
  367. }
  368. }
  369. void dso__insert_symbol(struct dso *dso, enum map_type type, struct symbol *sym)
  370. {
  371. __symbols__insert(&dso->symbols[type], sym, dso->kernel);
  372. /* update the symbol cache if necessary */
  373. if (dso->last_find_result[type].addr >= sym->start &&
  374. (dso->last_find_result[type].addr < sym->end ||
  375. sym->start == sym->end)) {
  376. dso->last_find_result[type].symbol = sym;
  377. }
  378. }
  379. struct symbol *dso__find_symbol(struct dso *dso,
  380. enum map_type type, u64 addr)
  381. {
  382. if (dso->last_find_result[type].addr != addr) {
  383. dso->last_find_result[type].addr = addr;
  384. dso->last_find_result[type].symbol = symbols__find(&dso->symbols[type], addr);
  385. }
  386. return dso->last_find_result[type].symbol;
  387. }
  388. struct symbol *dso__first_symbol(struct dso *dso, enum map_type type)
  389. {
  390. return symbols__first(&dso->symbols[type]);
  391. }
  392. struct symbol *dso__last_symbol(struct dso *dso, enum map_type type)
  393. {
  394. return symbols__last(&dso->symbols[type]);
  395. }
  396. struct symbol *dso__next_symbol(struct symbol *sym)
  397. {
  398. return symbols__next(sym);
  399. }
  400. struct symbol *symbol__next_by_name(struct symbol *sym)
  401. {
  402. struct symbol_name_rb_node *s = container_of(sym, struct symbol_name_rb_node, sym);
  403. struct rb_node *n = rb_next(&s->rb_node);
  404. return n ? &rb_entry(n, struct symbol_name_rb_node, rb_node)->sym : NULL;
  405. }
  406. /*
  407. * Teturns first symbol that matched with @name.
  408. */
  409. struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
  410. const char *name)
  411. {
  412. return symbols__find_by_name(&dso->symbol_names[type], name);
  413. }
  414. void dso__sort_by_name(struct dso *dso, enum map_type type)
  415. {
  416. dso__set_sorted_by_name(dso, type);
  417. return symbols__sort_by_name(&dso->symbol_names[type],
  418. &dso->symbols[type]);
  419. }
  420. int modules__parse(const char *filename, void *arg,
  421. int (*process_module)(void *arg, const char *name,
  422. u64 start))
  423. {
  424. char *line = NULL;
  425. size_t n;
  426. FILE *file;
  427. int err = 0;
  428. file = fopen(filename, "r");
  429. if (file == NULL)
  430. return -1;
  431. while (1) {
  432. char name[PATH_MAX];
  433. u64 start;
  434. char *sep;
  435. ssize_t line_len;
  436. line_len = getline(&line, &n, file);
  437. if (line_len < 0) {
  438. if (feof(file))
  439. break;
  440. err = -1;
  441. goto out;
  442. }
  443. if (!line) {
  444. err = -1;
  445. goto out;
  446. }
  447. line[--line_len] = '\0'; /* \n */
  448. sep = strrchr(line, 'x');
  449. if (sep == NULL)
  450. continue;
  451. hex2u64(sep + 1, &start);
  452. sep = strchr(line, ' ');
  453. if (sep == NULL)
  454. continue;
  455. *sep = '\0';
  456. scnprintf(name, sizeof(name), "[%s]", line);
  457. err = process_module(arg, name, start);
  458. if (err)
  459. break;
  460. }
  461. out:
  462. free(line);
  463. fclose(file);
  464. return err;
  465. }
  466. struct process_kallsyms_args {
  467. struct map *map;
  468. struct dso *dso;
  469. };
  470. /*
  471. * These are symbols in the kernel image, so make sure that
  472. * sym is from a kernel DSO.
  473. */
  474. static bool symbol__is_idle(const char *name)
  475. {
  476. const char * const idle_symbols[] = {
  477. "cpu_idle",
  478. "cpu_startup_entry",
  479. "intel_idle",
  480. "default_idle",
  481. "native_safe_halt",
  482. "enter_idle",
  483. "exit_idle",
  484. "mwait_idle",
  485. "mwait_idle_with_hints",
  486. "poll_idle",
  487. "ppc64_runlatch_off",
  488. "pseries_dedicated_idle_sleep",
  489. NULL
  490. };
  491. int i;
  492. for (i = 0; idle_symbols[i]; i++) {
  493. if (!strcmp(idle_symbols[i], name))
  494. return true;
  495. }
  496. return false;
  497. }
  498. static int map__process_kallsym_symbol(void *arg, const char *name,
  499. char type, u64 start)
  500. {
  501. struct symbol *sym;
  502. struct process_kallsyms_args *a = arg;
  503. struct rb_root *root = &a->dso->symbols[a->map->type];
  504. if (!symbol_type__is_a(type, a->map->type))
  505. return 0;
  506. /*
  507. * module symbols are not sorted so we add all
  508. * symbols, setting length to 0, and rely on
  509. * symbols__fixup_end() to fix it up.
  510. */
  511. sym = symbol__new(start, 0, kallsyms2elf_binding(type), name);
  512. if (sym == NULL)
  513. return -ENOMEM;
  514. /*
  515. * We will pass the symbols to the filter later, in
  516. * map__split_kallsyms, when we have split the maps per module
  517. */
  518. __symbols__insert(root, sym, !strchr(name, '['));
  519. return 0;
  520. }
  521. /*
  522. * Loads the function entries in /proc/kallsyms into kernel_map->dso,
  523. * so that we can in the next step set the symbol ->end address and then
  524. * call kernel_maps__split_kallsyms.
  525. */
  526. static int dso__load_all_kallsyms(struct dso *dso, const char *filename,
  527. struct map *map)
  528. {
  529. struct process_kallsyms_args args = { .map = map, .dso = dso, };
  530. return kallsyms__parse(filename, &args, map__process_kallsym_symbol);
  531. }
  532. static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map)
  533. {
  534. struct map_groups *kmaps = map__kmaps(map);
  535. struct map *curr_map;
  536. struct symbol *pos;
  537. int count = 0;
  538. struct rb_root old_root = dso->symbols[map->type];
  539. struct rb_root *root = &dso->symbols[map->type];
  540. struct rb_node *next = rb_first(root);
  541. if (!kmaps)
  542. return -1;
  543. *root = RB_ROOT;
  544. while (next) {
  545. char *module;
  546. pos = rb_entry(next, struct symbol, rb_node);
  547. next = rb_next(&pos->rb_node);
  548. rb_erase_init(&pos->rb_node, &old_root);
  549. module = strchr(pos->name, '\t');
  550. if (module)
  551. *module = '\0';
  552. curr_map = map_groups__find(kmaps, map->type, pos->start);
  553. if (!curr_map) {
  554. symbol__delete(pos);
  555. continue;
  556. }
  557. pos->start -= curr_map->start - curr_map->pgoff;
  558. if (pos->end)
  559. pos->end -= curr_map->start - curr_map->pgoff;
  560. symbols__insert(&curr_map->dso->symbols[curr_map->type], pos);
  561. ++count;
  562. }
  563. /* Symbols have been adjusted */
  564. dso->adjust_symbols = 1;
  565. return count;
  566. }
  567. /*
  568. * Split the symbols into maps, making sure there are no overlaps, i.e. the
  569. * kernel range is broken in several maps, named [kernel].N, as we don't have
  570. * the original ELF section names vmlinux have.
  571. */
  572. static int dso__split_kallsyms(struct dso *dso, struct map *map, u64 delta)
  573. {
  574. struct map_groups *kmaps = map__kmaps(map);
  575. struct machine *machine;
  576. struct map *curr_map = map;
  577. struct symbol *pos;
  578. int count = 0, moved = 0;
  579. struct rb_root *root = &dso->symbols[map->type];
  580. struct rb_node *next = rb_first(root);
  581. int kernel_range = 0;
  582. if (!kmaps)
  583. return -1;
  584. machine = kmaps->machine;
  585. while (next) {
  586. char *module;
  587. pos = rb_entry(next, struct symbol, rb_node);
  588. next = rb_next(&pos->rb_node);
  589. module = strchr(pos->name, '\t');
  590. if (module) {
  591. if (!symbol_conf.use_modules)
  592. goto discard_symbol;
  593. *module++ = '\0';
  594. if (strcmp(curr_map->dso->short_name, module)) {
  595. if (curr_map != map &&
  596. dso->kernel == DSO_TYPE_GUEST_KERNEL &&
  597. machine__is_default_guest(machine)) {
  598. /*
  599. * We assume all symbols of a module are
  600. * continuous in * kallsyms, so curr_map
  601. * points to a module and all its
  602. * symbols are in its kmap. Mark it as
  603. * loaded.
  604. */
  605. dso__set_loaded(curr_map->dso,
  606. curr_map->type);
  607. }
  608. curr_map = map_groups__find_by_name(kmaps,
  609. map->type, module);
  610. if (curr_map == NULL) {
  611. pr_debug("%s/proc/{kallsyms,modules} "
  612. "inconsistency while looking "
  613. "for \"%s\" module!\n",
  614. machine->root_dir, module);
  615. curr_map = map;
  616. goto discard_symbol;
  617. }
  618. if (curr_map->dso->loaded &&
  619. !machine__is_default_guest(machine))
  620. goto discard_symbol;
  621. }
  622. /*
  623. * So that we look just like we get from .ko files,
  624. * i.e. not prelinked, relative to map->start.
  625. */
  626. pos->start = curr_map->map_ip(curr_map, pos->start);
  627. pos->end = curr_map->map_ip(curr_map, pos->end);
  628. } else if (curr_map != map) {
  629. char dso_name[PATH_MAX];
  630. struct dso *ndso;
  631. if (delta) {
  632. /* Kernel was relocated at boot time */
  633. pos->start -= delta;
  634. pos->end -= delta;
  635. }
  636. if (count == 0) {
  637. curr_map = map;
  638. goto add_symbol;
  639. }
  640. if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
  641. snprintf(dso_name, sizeof(dso_name),
  642. "[guest.kernel].%d",
  643. kernel_range++);
  644. else
  645. snprintf(dso_name, sizeof(dso_name),
  646. "[kernel].%d",
  647. kernel_range++);
  648. ndso = dso__new(dso_name);
  649. if (ndso == NULL)
  650. return -1;
  651. ndso->kernel = dso->kernel;
  652. curr_map = map__new2(pos->start, ndso, map->type);
  653. if (curr_map == NULL) {
  654. dso__put(ndso);
  655. return -1;
  656. }
  657. curr_map->map_ip = curr_map->unmap_ip = identity__map_ip;
  658. map_groups__insert(kmaps, curr_map);
  659. ++kernel_range;
  660. } else if (delta) {
  661. /* Kernel was relocated at boot time */
  662. pos->start -= delta;
  663. pos->end -= delta;
  664. }
  665. add_symbol:
  666. if (curr_map != map) {
  667. rb_erase(&pos->rb_node, root);
  668. symbols__insert(&curr_map->dso->symbols[curr_map->type], pos);
  669. ++moved;
  670. } else
  671. ++count;
  672. continue;
  673. discard_symbol:
  674. rb_erase(&pos->rb_node, root);
  675. symbol__delete(pos);
  676. }
  677. if (curr_map != map &&
  678. dso->kernel == DSO_TYPE_GUEST_KERNEL &&
  679. machine__is_default_guest(kmaps->machine)) {
  680. dso__set_loaded(curr_map->dso, curr_map->type);
  681. }
  682. return count + moved;
  683. }
  684. bool symbol__restricted_filename(const char *filename,
  685. const char *restricted_filename)
  686. {
  687. bool restricted = false;
  688. if (symbol_conf.kptr_restrict) {
  689. char *r = realpath(filename, NULL);
  690. if (r != NULL) {
  691. restricted = strcmp(r, restricted_filename) == 0;
  692. free(r);
  693. return restricted;
  694. }
  695. }
  696. return restricted;
  697. }
  698. struct module_info {
  699. struct rb_node rb_node;
  700. char *name;
  701. u64 start;
  702. };
  703. static void add_module(struct module_info *mi, struct rb_root *modules)
  704. {
  705. struct rb_node **p = &modules->rb_node;
  706. struct rb_node *parent = NULL;
  707. struct module_info *m;
  708. while (*p != NULL) {
  709. parent = *p;
  710. m = rb_entry(parent, struct module_info, rb_node);
  711. if (strcmp(mi->name, m->name) < 0)
  712. p = &(*p)->rb_left;
  713. else
  714. p = &(*p)->rb_right;
  715. }
  716. rb_link_node(&mi->rb_node, parent, p);
  717. rb_insert_color(&mi->rb_node, modules);
  718. }
  719. static void delete_modules(struct rb_root *modules)
  720. {
  721. struct module_info *mi;
  722. struct rb_node *next = rb_first(modules);
  723. while (next) {
  724. mi = rb_entry(next, struct module_info, rb_node);
  725. next = rb_next(&mi->rb_node);
  726. rb_erase(&mi->rb_node, modules);
  727. zfree(&mi->name);
  728. free(mi);
  729. }
  730. }
  731. static struct module_info *find_module(const char *name,
  732. struct rb_root *modules)
  733. {
  734. struct rb_node *n = modules->rb_node;
  735. while (n) {
  736. struct module_info *m;
  737. int cmp;
  738. m = rb_entry(n, struct module_info, rb_node);
  739. cmp = strcmp(name, m->name);
  740. if (cmp < 0)
  741. n = n->rb_left;
  742. else if (cmp > 0)
  743. n = n->rb_right;
  744. else
  745. return m;
  746. }
  747. return NULL;
  748. }
  749. static int __read_proc_modules(void *arg, const char *name, u64 start)
  750. {
  751. struct rb_root *modules = arg;
  752. struct module_info *mi;
  753. mi = zalloc(sizeof(struct module_info));
  754. if (!mi)
  755. return -ENOMEM;
  756. mi->name = strdup(name);
  757. mi->start = start;
  758. if (!mi->name) {
  759. free(mi);
  760. return -ENOMEM;
  761. }
  762. add_module(mi, modules);
  763. return 0;
  764. }
  765. static int read_proc_modules(const char *filename, struct rb_root *modules)
  766. {
  767. if (symbol__restricted_filename(filename, "/proc/modules"))
  768. return -1;
  769. if (modules__parse(filename, modules, __read_proc_modules)) {
  770. delete_modules(modules);
  771. return -1;
  772. }
  773. return 0;
  774. }
  775. int compare_proc_modules(const char *from, const char *to)
  776. {
  777. struct rb_root from_modules = RB_ROOT;
  778. struct rb_root to_modules = RB_ROOT;
  779. struct rb_node *from_node, *to_node;
  780. struct module_info *from_m, *to_m;
  781. int ret = -1;
  782. if (read_proc_modules(from, &from_modules))
  783. return -1;
  784. if (read_proc_modules(to, &to_modules))
  785. goto out_delete_from;
  786. from_node = rb_first(&from_modules);
  787. to_node = rb_first(&to_modules);
  788. while (from_node) {
  789. if (!to_node)
  790. break;
  791. from_m = rb_entry(from_node, struct module_info, rb_node);
  792. to_m = rb_entry(to_node, struct module_info, rb_node);
  793. if (from_m->start != to_m->start ||
  794. strcmp(from_m->name, to_m->name))
  795. break;
  796. from_node = rb_next(from_node);
  797. to_node = rb_next(to_node);
  798. }
  799. if (!from_node && !to_node)
  800. ret = 0;
  801. delete_modules(&to_modules);
  802. out_delete_from:
  803. delete_modules(&from_modules);
  804. return ret;
  805. }
  806. static int do_validate_kcore_modules(const char *filename, struct map *map,
  807. struct map_groups *kmaps)
  808. {
  809. struct rb_root modules = RB_ROOT;
  810. struct map *old_map;
  811. int err;
  812. err = read_proc_modules(filename, &modules);
  813. if (err)
  814. return err;
  815. old_map = map_groups__first(kmaps, map->type);
  816. while (old_map) {
  817. struct map *next = map_groups__next(old_map);
  818. struct module_info *mi;
  819. if (old_map == map || old_map->start == map->start) {
  820. /* The kernel map */
  821. old_map = next;
  822. continue;
  823. }
  824. /* Module must be in memory at the same address */
  825. mi = find_module(old_map->dso->short_name, &modules);
  826. if (!mi || mi->start != old_map->start) {
  827. err = -EINVAL;
  828. goto out;
  829. }
  830. old_map = next;
  831. }
  832. out:
  833. delete_modules(&modules);
  834. return err;
  835. }
  836. /*
  837. * If kallsyms is referenced by name then we look for filename in the same
  838. * directory.
  839. */
  840. static bool filename_from_kallsyms_filename(char *filename,
  841. const char *base_name,
  842. const char *kallsyms_filename)
  843. {
  844. char *name;
  845. strcpy(filename, kallsyms_filename);
  846. name = strrchr(filename, '/');
  847. if (!name)
  848. return false;
  849. name += 1;
  850. if (!strcmp(name, "kallsyms")) {
  851. strcpy(name, base_name);
  852. return true;
  853. }
  854. return false;
  855. }
  856. static int validate_kcore_modules(const char *kallsyms_filename,
  857. struct map *map)
  858. {
  859. struct map_groups *kmaps = map__kmaps(map);
  860. char modules_filename[PATH_MAX];
  861. if (!kmaps)
  862. return -EINVAL;
  863. if (!filename_from_kallsyms_filename(modules_filename, "modules",
  864. kallsyms_filename))
  865. return -EINVAL;
  866. if (do_validate_kcore_modules(modules_filename, map, kmaps))
  867. return -EINVAL;
  868. return 0;
  869. }
  870. static int validate_kcore_addresses(const char *kallsyms_filename,
  871. struct map *map)
  872. {
  873. struct kmap *kmap = map__kmap(map);
  874. if (!kmap)
  875. return -EINVAL;
  876. if (kmap->ref_reloc_sym && kmap->ref_reloc_sym->name) {
  877. u64 start;
  878. start = kallsyms__get_function_start(kallsyms_filename,
  879. kmap->ref_reloc_sym->name);
  880. if (start != kmap->ref_reloc_sym->addr)
  881. return -EINVAL;
  882. }
  883. return validate_kcore_modules(kallsyms_filename, map);
  884. }
  885. struct kcore_mapfn_data {
  886. struct dso *dso;
  887. enum map_type type;
  888. struct list_head maps;
  889. };
  890. static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data)
  891. {
  892. struct kcore_mapfn_data *md = data;
  893. struct map *map;
  894. map = map__new2(start, md->dso, md->type);
  895. if (map == NULL)
  896. return -ENOMEM;
  897. map->end = map->start + len;
  898. map->pgoff = pgoff;
  899. list_add(&map->node, &md->maps);
  900. return 0;
  901. }
  902. static int dso__load_kcore(struct dso *dso, struct map *map,
  903. const char *kallsyms_filename)
  904. {
  905. struct map_groups *kmaps = map__kmaps(map);
  906. struct machine *machine;
  907. struct kcore_mapfn_data md;
  908. struct map *old_map, *new_map, *replacement_map = NULL;
  909. bool is_64_bit;
  910. int err, fd;
  911. char kcore_filename[PATH_MAX];
  912. struct symbol *sym;
  913. if (!kmaps)
  914. return -EINVAL;
  915. machine = kmaps->machine;
  916. /* This function requires that the map is the kernel map */
  917. if (map != machine->vmlinux_maps[map->type])
  918. return -EINVAL;
  919. if (!filename_from_kallsyms_filename(kcore_filename, "kcore",
  920. kallsyms_filename))
  921. return -EINVAL;
  922. /* Modules and kernel must be present at their original addresses */
  923. if (validate_kcore_addresses(kallsyms_filename, map))
  924. return -EINVAL;
  925. md.dso = dso;
  926. md.type = map->type;
  927. INIT_LIST_HEAD(&md.maps);
  928. fd = open(kcore_filename, O_RDONLY);
  929. if (fd < 0) {
  930. pr_debug("Failed to open %s. Note /proc/kcore requires CAP_SYS_RAWIO capability to access.\n",
  931. kcore_filename);
  932. return -EINVAL;
  933. }
  934. /* Read new maps into temporary lists */
  935. err = file__read_maps(fd, md.type == MAP__FUNCTION, kcore_mapfn, &md,
  936. &is_64_bit);
  937. if (err)
  938. goto out_err;
  939. dso->is_64_bit = is_64_bit;
  940. if (list_empty(&md.maps)) {
  941. err = -EINVAL;
  942. goto out_err;
  943. }
  944. /* Remove old maps */
  945. old_map = map_groups__first(kmaps, map->type);
  946. while (old_map) {
  947. struct map *next = map_groups__next(old_map);
  948. if (old_map != map)
  949. map_groups__remove(kmaps, old_map);
  950. old_map = next;
  951. }
  952. /* Find the kernel map using the first symbol */
  953. sym = dso__first_symbol(dso, map->type);
  954. list_for_each_entry(new_map, &md.maps, node) {
  955. if (sym && sym->start >= new_map->start &&
  956. sym->start < new_map->end) {
  957. replacement_map = new_map;
  958. break;
  959. }
  960. }
  961. if (!replacement_map)
  962. replacement_map = list_entry(md.maps.next, struct map, node);
  963. /* Add new maps */
  964. while (!list_empty(&md.maps)) {
  965. new_map = list_entry(md.maps.next, struct map, node);
  966. list_del_init(&new_map->node);
  967. if (new_map == replacement_map) {
  968. map->start = new_map->start;
  969. map->end = new_map->end;
  970. map->pgoff = new_map->pgoff;
  971. map->map_ip = new_map->map_ip;
  972. map->unmap_ip = new_map->unmap_ip;
  973. /* Ensure maps are correctly ordered */
  974. map__get(map);
  975. map_groups__remove(kmaps, map);
  976. map_groups__insert(kmaps, map);
  977. map__put(map);
  978. } else {
  979. map_groups__insert(kmaps, new_map);
  980. }
  981. map__put(new_map);
  982. }
  983. /*
  984. * Set the data type and long name so that kcore can be read via
  985. * dso__data_read_addr().
  986. */
  987. if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
  988. dso->binary_type = DSO_BINARY_TYPE__GUEST_KCORE;
  989. else
  990. dso->binary_type = DSO_BINARY_TYPE__KCORE;
  991. dso__set_long_name(dso, strdup(kcore_filename), true);
  992. close(fd);
  993. if (map->type == MAP__FUNCTION)
  994. pr_debug("Using %s for kernel object code\n", kcore_filename);
  995. else
  996. pr_debug("Using %s for kernel data\n", kcore_filename);
  997. return 0;
  998. out_err:
  999. while (!list_empty(&md.maps)) {
  1000. map = list_entry(md.maps.next, struct map, node);
  1001. list_del_init(&map->node);
  1002. map__put(map);
  1003. }
  1004. close(fd);
  1005. return -EINVAL;
  1006. }
  1007. /*
  1008. * If the kernel is relocated at boot time, kallsyms won't match. Compute the
  1009. * delta based on the relocation reference symbol.
  1010. */
  1011. static int kallsyms__delta(struct map *map, const char *filename, u64 *delta)
  1012. {
  1013. struct kmap *kmap = map__kmap(map);
  1014. u64 addr;
  1015. if (!kmap)
  1016. return -1;
  1017. if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->name)
  1018. return 0;
  1019. addr = kallsyms__get_function_start(filename,
  1020. kmap->ref_reloc_sym->name);
  1021. if (!addr)
  1022. return -1;
  1023. *delta = addr - kmap->ref_reloc_sym->addr;
  1024. return 0;
  1025. }
  1026. int __dso__load_kallsyms(struct dso *dso, const char *filename,
  1027. struct map *map, bool no_kcore)
  1028. {
  1029. u64 delta = 0;
  1030. if (symbol__restricted_filename(filename, "/proc/kallsyms"))
  1031. return -1;
  1032. if (dso__load_all_kallsyms(dso, filename, map) < 0)
  1033. return -1;
  1034. if (kallsyms__delta(map, filename, &delta))
  1035. return -1;
  1036. symbols__fixup_end(&dso->symbols[map->type]);
  1037. symbols__fixup_duplicate(&dso->symbols[map->type]);
  1038. if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
  1039. dso->symtab_type = DSO_BINARY_TYPE__GUEST_KALLSYMS;
  1040. else
  1041. dso->symtab_type = DSO_BINARY_TYPE__KALLSYMS;
  1042. if (!no_kcore && !dso__load_kcore(dso, map, filename))
  1043. return dso__split_kallsyms_for_kcore(dso, map);
  1044. else
  1045. return dso__split_kallsyms(dso, map, delta);
  1046. }
  1047. int dso__load_kallsyms(struct dso *dso, const char *filename,
  1048. struct map *map)
  1049. {
  1050. return __dso__load_kallsyms(dso, filename, map, false);
  1051. }
  1052. static int dso__load_perf_map(struct dso *dso, struct map *map)
  1053. {
  1054. char *line = NULL;
  1055. size_t n;
  1056. FILE *file;
  1057. int nr_syms = 0;
  1058. file = fopen(dso->long_name, "r");
  1059. if (file == NULL)
  1060. goto out_failure;
  1061. while (!feof(file)) {
  1062. u64 start, size;
  1063. struct symbol *sym;
  1064. int line_len, len;
  1065. line_len = getline(&line, &n, file);
  1066. if (line_len < 0)
  1067. break;
  1068. if (!line)
  1069. goto out_failure;
  1070. line[--line_len] = '\0'; /* \n */
  1071. len = hex2u64(line, &start);
  1072. len++;
  1073. if (len + 2 >= line_len)
  1074. continue;
  1075. len += hex2u64(line + len, &size);
  1076. len++;
  1077. if (len + 2 >= line_len)
  1078. continue;
  1079. sym = symbol__new(start, size, STB_GLOBAL, line + len);
  1080. if (sym == NULL)
  1081. goto out_delete_line;
  1082. symbols__insert(&dso->symbols[map->type], sym);
  1083. nr_syms++;
  1084. }
  1085. free(line);
  1086. fclose(file);
  1087. return nr_syms;
  1088. out_delete_line:
  1089. free(line);
  1090. out_failure:
  1091. return -1;
  1092. }
  1093. static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod,
  1094. enum dso_binary_type type)
  1095. {
  1096. switch (type) {
  1097. case DSO_BINARY_TYPE__JAVA_JIT:
  1098. case DSO_BINARY_TYPE__DEBUGLINK:
  1099. case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
  1100. case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
  1101. case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
  1102. case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
  1103. case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:
  1104. return !kmod && dso->kernel == DSO_TYPE_USER;
  1105. case DSO_BINARY_TYPE__KALLSYMS:
  1106. case DSO_BINARY_TYPE__VMLINUX:
  1107. case DSO_BINARY_TYPE__KCORE:
  1108. return dso->kernel == DSO_TYPE_KERNEL;
  1109. case DSO_BINARY_TYPE__GUEST_KALLSYMS:
  1110. case DSO_BINARY_TYPE__GUEST_VMLINUX:
  1111. case DSO_BINARY_TYPE__GUEST_KCORE:
  1112. return dso->kernel == DSO_TYPE_GUEST_KERNEL;
  1113. case DSO_BINARY_TYPE__GUEST_KMODULE:
  1114. case DSO_BINARY_TYPE__GUEST_KMODULE_COMP:
  1115. case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE:
  1116. case DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP:
  1117. /*
  1118. * kernel modules know their symtab type - it's set when
  1119. * creating a module dso in machine__findnew_module_map().
  1120. */
  1121. return kmod && dso->symtab_type == type;
  1122. case DSO_BINARY_TYPE__BUILD_ID_CACHE:
  1123. return true;
  1124. case DSO_BINARY_TYPE__NOT_FOUND:
  1125. default:
  1126. return false;
  1127. }
  1128. }
  1129. int dso__load(struct dso *dso, struct map *map)
  1130. {
  1131. char *name;
  1132. int ret = -1;
  1133. u_int i;
  1134. struct machine *machine;
  1135. char *root_dir = (char *) "";
  1136. int ss_pos = 0;
  1137. struct symsrc ss_[2];
  1138. struct symsrc *syms_ss = NULL, *runtime_ss = NULL;
  1139. bool kmod;
  1140. unsigned char build_id[BUILD_ID_SIZE];
  1141. pthread_mutex_lock(&dso->lock);
  1142. /* check again under the dso->lock */
  1143. if (dso__loaded(dso, map->type)) {
  1144. ret = 1;
  1145. goto out;
  1146. }
  1147. if (dso->kernel) {
  1148. if (dso->kernel == DSO_TYPE_KERNEL)
  1149. ret = dso__load_kernel_sym(dso, map);
  1150. else if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
  1151. ret = dso__load_guest_kernel_sym(dso, map);
  1152. goto out;
  1153. }
  1154. if (map->groups && map->groups->machine)
  1155. machine = map->groups->machine;
  1156. else
  1157. machine = NULL;
  1158. dso->adjust_symbols = 0;
  1159. if (strncmp(dso->name, "/tmp/perf-", 10) == 0) {
  1160. struct stat st;
  1161. if (lstat(dso->name, &st) < 0)
  1162. goto out;
  1163. if (!symbol_conf.force && st.st_uid && (st.st_uid != geteuid())) {
  1164. pr_warning("File %s not owned by current user or root, "
  1165. "ignoring it (use -f to override).\n", dso->name);
  1166. goto out;
  1167. }
  1168. ret = dso__load_perf_map(dso, map);
  1169. dso->symtab_type = ret > 0 ? DSO_BINARY_TYPE__JAVA_JIT :
  1170. DSO_BINARY_TYPE__NOT_FOUND;
  1171. goto out;
  1172. }
  1173. if (machine)
  1174. root_dir = machine->root_dir;
  1175. name = malloc(PATH_MAX);
  1176. if (!name)
  1177. goto out;
  1178. kmod = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE ||
  1179. dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP ||
  1180. dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE ||
  1181. dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
  1182. /*
  1183. * Read the build id if possible. This is required for
  1184. * DSO_BINARY_TYPE__BUILDID_DEBUGINFO to work
  1185. */
  1186. if (!dso->has_build_id &&
  1187. is_regular_file(dso->long_name)) {
  1188. __symbol__join_symfs(name, PATH_MAX, dso->long_name);
  1189. if (filename__read_build_id(name, build_id, BUILD_ID_SIZE) > 0)
  1190. dso__set_build_id(dso, build_id);
  1191. }
  1192. /*
  1193. * Iterate over candidate debug images.
  1194. * Keep track of "interesting" ones (those which have a symtab, dynsym,
  1195. * and/or opd section) for processing.
  1196. */
  1197. for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) {
  1198. struct symsrc *ss = &ss_[ss_pos];
  1199. bool next_slot = false;
  1200. enum dso_binary_type symtab_type = binary_type_symtab[i];
  1201. if (!dso__is_compatible_symtab_type(dso, kmod, symtab_type))
  1202. continue;
  1203. if (dso__read_binary_type_filename(dso, symtab_type,
  1204. root_dir, name, PATH_MAX))
  1205. continue;
  1206. if (!is_regular_file(name))
  1207. continue;
  1208. /* Name is now the name of the next image to try */
  1209. if (symsrc__init(ss, dso, name, symtab_type) < 0)
  1210. continue;
  1211. if (!syms_ss && symsrc__has_symtab(ss)) {
  1212. syms_ss = ss;
  1213. next_slot = true;
  1214. if (!dso->symsrc_filename)
  1215. dso->symsrc_filename = strdup(name);
  1216. }
  1217. if (!runtime_ss && symsrc__possibly_runtime(ss)) {
  1218. runtime_ss = ss;
  1219. next_slot = true;
  1220. }
  1221. if (next_slot) {
  1222. ss_pos++;
  1223. if (syms_ss && runtime_ss)
  1224. break;
  1225. } else {
  1226. symsrc__destroy(ss);
  1227. }
  1228. }
  1229. if (!runtime_ss && !syms_ss)
  1230. goto out_free;
  1231. if (runtime_ss && !syms_ss) {
  1232. syms_ss = runtime_ss;
  1233. }
  1234. /* We'll have to hope for the best */
  1235. if (!runtime_ss && syms_ss)
  1236. runtime_ss = syms_ss;
  1237. if (syms_ss && syms_ss->type == DSO_BINARY_TYPE__BUILD_ID_CACHE)
  1238. if (dso__build_id_is_kmod(dso, name, PATH_MAX))
  1239. kmod = true;
  1240. if (syms_ss)
  1241. ret = dso__load_sym(dso, map, syms_ss, runtime_ss, kmod);
  1242. else
  1243. ret = -1;
  1244. if (ret > 0) {
  1245. int nr_plt;
  1246. nr_plt = dso__synthesize_plt_symbols(dso, runtime_ss, map);
  1247. if (nr_plt > 0)
  1248. ret += nr_plt;
  1249. }
  1250. for (; ss_pos > 0; ss_pos--)
  1251. symsrc__destroy(&ss_[ss_pos - 1]);
  1252. out_free:
  1253. free(name);
  1254. if (ret < 0 && strstr(dso->name, " (deleted)") != NULL)
  1255. ret = 0;
  1256. out:
  1257. dso__set_loaded(dso, map->type);
  1258. pthread_mutex_unlock(&dso->lock);
  1259. return ret;
  1260. }
  1261. struct map *map_groups__find_by_name(struct map_groups *mg,
  1262. enum map_type type, const char *name)
  1263. {
  1264. struct maps *maps = &mg->maps[type];
  1265. struct map *map;
  1266. pthread_rwlock_rdlock(&maps->lock);
  1267. for (map = maps__first(maps); map; map = map__next(map)) {
  1268. if (map->dso && strcmp(map->dso->short_name, name) == 0)
  1269. goto out_unlock;
  1270. }
  1271. map = NULL;
  1272. out_unlock:
  1273. pthread_rwlock_unlock(&maps->lock);
  1274. return map;
  1275. }
  1276. int dso__load_vmlinux(struct dso *dso, struct map *map,
  1277. const char *vmlinux, bool vmlinux_allocated)
  1278. {
  1279. int err = -1;
  1280. struct symsrc ss;
  1281. char symfs_vmlinux[PATH_MAX];
  1282. enum dso_binary_type symtab_type;
  1283. if (vmlinux[0] == '/')
  1284. snprintf(symfs_vmlinux, sizeof(symfs_vmlinux), "%s", vmlinux);
  1285. else
  1286. symbol__join_symfs(symfs_vmlinux, vmlinux);
  1287. if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
  1288. symtab_type = DSO_BINARY_TYPE__GUEST_VMLINUX;
  1289. else
  1290. symtab_type = DSO_BINARY_TYPE__VMLINUX;
  1291. if (symsrc__init(&ss, dso, symfs_vmlinux, symtab_type))
  1292. return -1;
  1293. err = dso__load_sym(dso, map, &ss, &ss, 0);
  1294. symsrc__destroy(&ss);
  1295. if (err > 0) {
  1296. if (dso->kernel == DSO_TYPE_GUEST_KERNEL)
  1297. dso->binary_type = DSO_BINARY_TYPE__GUEST_VMLINUX;
  1298. else
  1299. dso->binary_type = DSO_BINARY_TYPE__VMLINUX;
  1300. dso__set_long_name(dso, vmlinux, vmlinux_allocated);
  1301. dso__set_loaded(dso, map->type);
  1302. pr_debug("Using %s for symbols\n", symfs_vmlinux);
  1303. }
  1304. return err;
  1305. }
  1306. int dso__load_vmlinux_path(struct dso *dso, struct map *map)
  1307. {
  1308. int i, err = 0;
  1309. char *filename = NULL;
  1310. pr_debug("Looking at the vmlinux_path (%d entries long)\n",
  1311. vmlinux_path__nr_entries + 1);
  1312. for (i = 0; i < vmlinux_path__nr_entries; ++i) {
  1313. err = dso__load_vmlinux(dso, map, vmlinux_path[i], false);
  1314. if (err > 0)
  1315. goto out;
  1316. }
  1317. if (!symbol_conf.ignore_vmlinux_buildid)
  1318. filename = dso__build_id_filename(dso, NULL, 0);
  1319. if (filename != NULL) {
  1320. err = dso__load_vmlinux(dso, map, filename, true);
  1321. if (err > 0)
  1322. goto out;
  1323. free(filename);
  1324. }
  1325. out:
  1326. return err;
  1327. }
  1328. static bool visible_dir_filter(const char *name, struct dirent *d)
  1329. {
  1330. if (d->d_type != DT_DIR)
  1331. return false;
  1332. return lsdir_no_dot_filter(name, d);
  1333. }
  1334. static int find_matching_kcore(struct map *map, char *dir, size_t dir_sz)
  1335. {
  1336. char kallsyms_filename[PATH_MAX];
  1337. int ret = -1;
  1338. struct strlist *dirs;
  1339. struct str_node *nd;
  1340. dirs = lsdir(dir, visible_dir_filter);
  1341. if (!dirs)
  1342. return -1;
  1343. strlist__for_each_entry(nd, dirs) {
  1344. scnprintf(kallsyms_filename, sizeof(kallsyms_filename),
  1345. "%s/%s/kallsyms", dir, nd->s);
  1346. if (!validate_kcore_addresses(kallsyms_filename, map)) {
  1347. strlcpy(dir, kallsyms_filename, dir_sz);
  1348. ret = 0;
  1349. break;
  1350. }
  1351. }
  1352. strlist__delete(dirs);
  1353. return ret;
  1354. }
  1355. /*
  1356. * Use open(O_RDONLY) to check readability directly instead of access(R_OK)
  1357. * since access(R_OK) only checks with real UID/GID but open() use effective
  1358. * UID/GID and actual capabilities (e.g. /proc/kcore requires CAP_SYS_RAWIO).
  1359. */
  1360. static bool filename__readable(const char *file)
  1361. {
  1362. int fd = open(file, O_RDONLY);
  1363. if (fd < 0)
  1364. return false;
  1365. close(fd);
  1366. return true;
  1367. }
  1368. static char *dso__find_kallsyms(struct dso *dso, struct map *map)
  1369. {
  1370. u8 host_build_id[BUILD_ID_SIZE];
  1371. char sbuild_id[SBUILD_ID_SIZE];
  1372. bool is_host = false;
  1373. char path[PATH_MAX];
  1374. if (!dso->has_build_id) {
  1375. /*
  1376. * Last resort, if we don't have a build-id and couldn't find
  1377. * any vmlinux file, try the running kernel kallsyms table.
  1378. */
  1379. goto proc_kallsyms;
  1380. }
  1381. if (sysfs__read_build_id("/sys/kernel/notes", host_build_id,
  1382. sizeof(host_build_id)) == 0)
  1383. is_host = dso__build_id_equal(dso, host_build_id);
  1384. /* Try a fast path for /proc/kallsyms if possible */
  1385. if (is_host) {
  1386. /*
  1387. * Do not check the build-id cache, unless we know we cannot use
  1388. * /proc/kcore or module maps don't match to /proc/kallsyms.
  1389. * To check readability of /proc/kcore, do not use access(R_OK)
  1390. * since /proc/kcore requires CAP_SYS_RAWIO to read and access
  1391. * can't check it.
  1392. */
  1393. if (filename__readable("/proc/kcore") &&
  1394. !validate_kcore_addresses("/proc/kallsyms", map))
  1395. goto proc_kallsyms;
  1396. }
  1397. build_id__sprintf(dso->build_id, sizeof(dso->build_id), sbuild_id);
  1398. /* Find kallsyms in build-id cache with kcore */
  1399. scnprintf(path, sizeof(path), "%s/%s/%s",
  1400. buildid_dir, DSO__NAME_KCORE, sbuild_id);
  1401. if (!find_matching_kcore(map, path, sizeof(path)))
  1402. return strdup(path);
  1403. /* Use current /proc/kallsyms if possible */
  1404. if (is_host) {
  1405. proc_kallsyms:
  1406. return strdup("/proc/kallsyms");
  1407. }
  1408. /* Finally, find a cache of kallsyms */
  1409. if (!build_id_cache__kallsyms_path(sbuild_id, path, sizeof(path))) {
  1410. pr_err("No kallsyms or vmlinux with build-id %s was found\n",
  1411. sbuild_id);
  1412. return NULL;
  1413. }
  1414. return strdup(path);
  1415. }
  1416. static int dso__load_kernel_sym(struct dso *dso, struct map *map)
  1417. {
  1418. int err;
  1419. const char *kallsyms_filename = NULL;
  1420. char *kallsyms_allocated_filename = NULL;
  1421. /*
  1422. * Step 1: if the user specified a kallsyms or vmlinux filename, use
  1423. * it and only it, reporting errors to the user if it cannot be used.
  1424. *
  1425. * For instance, try to analyse an ARM perf.data file _without_ a
  1426. * build-id, or if the user specifies the wrong path to the right
  1427. * vmlinux file, obviously we can't fallback to another vmlinux (a
  1428. * x86_86 one, on the machine where analysis is being performed, say),
  1429. * or worse, /proc/kallsyms.
  1430. *
  1431. * If the specified file _has_ a build-id and there is a build-id
  1432. * section in the perf.data file, we will still do the expected
  1433. * validation in dso__load_vmlinux and will bail out if they don't
  1434. * match.
  1435. */
  1436. if (symbol_conf.kallsyms_name != NULL) {
  1437. kallsyms_filename = symbol_conf.kallsyms_name;
  1438. goto do_kallsyms;
  1439. }
  1440. if (!symbol_conf.ignore_vmlinux && symbol_conf.vmlinux_name != NULL) {
  1441. return dso__load_vmlinux(dso, map, symbol_conf.vmlinux_name, false);
  1442. }
  1443. if (!symbol_conf.ignore_vmlinux && vmlinux_path != NULL) {
  1444. err = dso__load_vmlinux_path(dso, map);
  1445. if (err > 0)
  1446. return err;
  1447. }
  1448. /* do not try local files if a symfs was given */
  1449. if (symbol_conf.symfs[0] != 0)
  1450. return -1;
  1451. kallsyms_allocated_filename = dso__find_kallsyms(dso, map);
  1452. if (!kallsyms_allocated_filename)
  1453. return -1;
  1454. kallsyms_filename = kallsyms_allocated_filename;
  1455. do_kallsyms:
  1456. err = dso__load_kallsyms(dso, kallsyms_filename, map);
  1457. if (err > 0)
  1458. pr_debug("Using %s for symbols\n", kallsyms_filename);
  1459. free(kallsyms_allocated_filename);
  1460. if (err > 0 && !dso__is_kcore(dso)) {
  1461. dso->binary_type = DSO_BINARY_TYPE__KALLSYMS;
  1462. dso__set_long_name(dso, DSO__NAME_KALLSYMS, false);
  1463. map__fixup_start(map);
  1464. map__fixup_end(map);
  1465. }
  1466. return err;
  1467. }
  1468. static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map)
  1469. {
  1470. int err;
  1471. const char *kallsyms_filename = NULL;
  1472. struct machine *machine;
  1473. char path[PATH_MAX];
  1474. if (!map->groups) {
  1475. pr_debug("Guest kernel map hasn't the point to groups\n");
  1476. return -1;
  1477. }
  1478. machine = map->groups->machine;
  1479. if (machine__is_default_guest(machine)) {
  1480. /*
  1481. * if the user specified a vmlinux filename, use it and only
  1482. * it, reporting errors to the user if it cannot be used.
  1483. * Or use file guest_kallsyms inputted by user on commandline
  1484. */
  1485. if (symbol_conf.default_guest_vmlinux_name != NULL) {
  1486. err = dso__load_vmlinux(dso, map,
  1487. symbol_conf.default_guest_vmlinux_name,
  1488. false);
  1489. return err;
  1490. }
  1491. kallsyms_filename = symbol_conf.default_guest_kallsyms;
  1492. if (!kallsyms_filename)
  1493. return -1;
  1494. } else {
  1495. sprintf(path, "%s/proc/kallsyms", machine->root_dir);
  1496. kallsyms_filename = path;
  1497. }
  1498. err = dso__load_kallsyms(dso, kallsyms_filename, map);
  1499. if (err > 0)
  1500. pr_debug("Using %s for symbols\n", kallsyms_filename);
  1501. if (err > 0 && !dso__is_kcore(dso)) {
  1502. dso->binary_type = DSO_BINARY_TYPE__GUEST_KALLSYMS;
  1503. machine__mmap_name(machine, path, sizeof(path));
  1504. dso__set_long_name(dso, strdup(path), true);
  1505. map__fixup_start(map);
  1506. map__fixup_end(map);
  1507. }
  1508. return err;
  1509. }
  1510. static void vmlinux_path__exit(void)
  1511. {
  1512. while (--vmlinux_path__nr_entries >= 0)
  1513. zfree(&vmlinux_path[vmlinux_path__nr_entries]);
  1514. vmlinux_path__nr_entries = 0;
  1515. zfree(&vmlinux_path);
  1516. }
  1517. static const char * const vmlinux_paths[] = {
  1518. "vmlinux",
  1519. "/boot/vmlinux"
  1520. };
  1521. static const char * const vmlinux_paths_upd[] = {
  1522. "/boot/vmlinux-%s",
  1523. "/usr/lib/debug/boot/vmlinux-%s",
  1524. "/lib/modules/%s/build/vmlinux",
  1525. "/usr/lib/debug/lib/modules/%s/vmlinux",
  1526. "/usr/lib/debug/boot/vmlinux-%s.debug"
  1527. };
  1528. static int vmlinux_path__add(const char *new_entry)
  1529. {
  1530. vmlinux_path[vmlinux_path__nr_entries] = strdup(new_entry);
  1531. if (vmlinux_path[vmlinux_path__nr_entries] == NULL)
  1532. return -1;
  1533. ++vmlinux_path__nr_entries;
  1534. return 0;
  1535. }
  1536. static int vmlinux_path__init(struct perf_env *env)
  1537. {
  1538. struct utsname uts;
  1539. char bf[PATH_MAX];
  1540. char *kernel_version;
  1541. unsigned int i;
  1542. vmlinux_path = malloc(sizeof(char *) * (ARRAY_SIZE(vmlinux_paths) +
  1543. ARRAY_SIZE(vmlinux_paths_upd)));
  1544. if (vmlinux_path == NULL)
  1545. return -1;
  1546. for (i = 0; i < ARRAY_SIZE(vmlinux_paths); i++)
  1547. if (vmlinux_path__add(vmlinux_paths[i]) < 0)
  1548. goto out_fail;
  1549. /* only try kernel version if no symfs was given */
  1550. if (symbol_conf.symfs[0] != 0)
  1551. return 0;
  1552. if (env) {
  1553. kernel_version = env->os_release;
  1554. } else {
  1555. if (uname(&uts) < 0)
  1556. goto out_fail;
  1557. kernel_version = uts.release;
  1558. }
  1559. for (i = 0; i < ARRAY_SIZE(vmlinux_paths_upd); i++) {
  1560. snprintf(bf, sizeof(bf), vmlinux_paths_upd[i], kernel_version);
  1561. if (vmlinux_path__add(bf) < 0)
  1562. goto out_fail;
  1563. }
  1564. return 0;
  1565. out_fail:
  1566. vmlinux_path__exit();
  1567. return -1;
  1568. }
  1569. int setup_list(struct strlist **list, const char *list_str,
  1570. const char *list_name)
  1571. {
  1572. if (list_str == NULL)
  1573. return 0;
  1574. *list = strlist__new(list_str, NULL);
  1575. if (!*list) {
  1576. pr_err("problems parsing %s list\n", list_name);
  1577. return -1;
  1578. }
  1579. symbol_conf.has_filter = true;
  1580. return 0;
  1581. }
  1582. int setup_intlist(struct intlist **list, const char *list_str,
  1583. const char *list_name)
  1584. {
  1585. if (list_str == NULL)
  1586. return 0;
  1587. *list = intlist__new(list_str);
  1588. if (!*list) {
  1589. pr_err("problems parsing %s list\n", list_name);
  1590. return -1;
  1591. }
  1592. return 0;
  1593. }
  1594. static bool symbol__read_kptr_restrict(void)
  1595. {
  1596. bool value = false;
  1597. FILE *fp = fopen("/proc/sys/kernel/kptr_restrict", "r");
  1598. if (fp != NULL) {
  1599. char line[8];
  1600. if (fgets(line, sizeof(line), fp) != NULL)
  1601. value = ((geteuid() != 0) || (getuid() != 0)) ?
  1602. (atoi(line) != 0) :
  1603. (atoi(line) == 2);
  1604. fclose(fp);
  1605. }
  1606. return value;
  1607. }
  1608. int symbol__annotation_init(void)
  1609. {
  1610. if (symbol_conf.initialized) {
  1611. pr_err("Annotation needs to be init before symbol__init()\n");
  1612. return -1;
  1613. }
  1614. if (symbol_conf.init_annotation) {
  1615. pr_warning("Annotation being initialized multiple times\n");
  1616. return 0;
  1617. }
  1618. symbol_conf.priv_size += sizeof(struct annotation);
  1619. symbol_conf.init_annotation = true;
  1620. return 0;
  1621. }
  1622. int symbol__init(struct perf_env *env)
  1623. {
  1624. const char *symfs;
  1625. if (symbol_conf.initialized)
  1626. return 0;
  1627. symbol_conf.priv_size = PERF_ALIGN(symbol_conf.priv_size, sizeof(u64));
  1628. symbol__elf_init();
  1629. if (symbol_conf.sort_by_name)
  1630. symbol_conf.priv_size += (sizeof(struct symbol_name_rb_node) -
  1631. sizeof(struct symbol));
  1632. if (symbol_conf.try_vmlinux_path && vmlinux_path__init(env) < 0)
  1633. return -1;
  1634. if (symbol_conf.field_sep && *symbol_conf.field_sep == '.') {
  1635. pr_err("'.' is the only non valid --field-separator argument\n");
  1636. return -1;
  1637. }
  1638. if (setup_list(&symbol_conf.dso_list,
  1639. symbol_conf.dso_list_str, "dso") < 0)
  1640. return -1;
  1641. if (setup_list(&symbol_conf.comm_list,
  1642. symbol_conf.comm_list_str, "comm") < 0)
  1643. goto out_free_dso_list;
  1644. if (setup_intlist(&symbol_conf.pid_list,
  1645. symbol_conf.pid_list_str, "pid") < 0)
  1646. goto out_free_comm_list;
  1647. if (setup_intlist(&symbol_conf.tid_list,
  1648. symbol_conf.tid_list_str, "tid") < 0)
  1649. goto out_free_pid_list;
  1650. if (setup_list(&symbol_conf.sym_list,
  1651. symbol_conf.sym_list_str, "symbol") < 0)
  1652. goto out_free_tid_list;
  1653. if (setup_list(&symbol_conf.bt_stop_list,
  1654. symbol_conf.bt_stop_list_str, "symbol") < 0)
  1655. goto out_free_sym_list;
  1656. /*
  1657. * A path to symbols of "/" is identical to ""
  1658. * reset here for simplicity.
  1659. */
  1660. symfs = realpath(symbol_conf.symfs, NULL);
  1661. if (symfs == NULL)
  1662. symfs = symbol_conf.symfs;
  1663. if (strcmp(symfs, "/") == 0)
  1664. symbol_conf.symfs = "";
  1665. if (symfs != symbol_conf.symfs)
  1666. free((void *)symfs);
  1667. symbol_conf.kptr_restrict = symbol__read_kptr_restrict();
  1668. symbol_conf.initialized = true;
  1669. return 0;
  1670. out_free_sym_list:
  1671. strlist__delete(symbol_conf.sym_list);
  1672. out_free_tid_list:
  1673. intlist__delete(symbol_conf.tid_list);
  1674. out_free_pid_list:
  1675. intlist__delete(symbol_conf.pid_list);
  1676. out_free_comm_list:
  1677. strlist__delete(symbol_conf.comm_list);
  1678. out_free_dso_list:
  1679. strlist__delete(symbol_conf.dso_list);
  1680. return -1;
  1681. }
  1682. void symbol__exit(void)
  1683. {
  1684. if (!symbol_conf.initialized)
  1685. return;
  1686. strlist__delete(symbol_conf.bt_stop_list);
  1687. strlist__delete(symbol_conf.sym_list);
  1688. strlist__delete(symbol_conf.dso_list);
  1689. strlist__delete(symbol_conf.comm_list);
  1690. intlist__delete(symbol_conf.tid_list);
  1691. intlist__delete(symbol_conf.pid_list);
  1692. vmlinux_path__exit();
  1693. symbol_conf.sym_list = symbol_conf.dso_list = symbol_conf.comm_list = NULL;
  1694. symbol_conf.bt_stop_list = NULL;
  1695. symbol_conf.initialized = false;
  1696. }
  1697. int symbol__config_symfs(const struct option *opt __maybe_unused,
  1698. const char *dir, int unset __maybe_unused)
  1699. {
  1700. char *bf = NULL;
  1701. int ret;
  1702. symbol_conf.symfs = strdup(dir);
  1703. if (symbol_conf.symfs == NULL)
  1704. return -ENOMEM;
  1705. /* skip the locally configured cache if a symfs is given, and
  1706. * config buildid dir to symfs/.debug
  1707. */
  1708. ret = asprintf(&bf, "%s/%s", dir, ".debug");
  1709. if (ret < 0)
  1710. return -ENOMEM;
  1711. set_buildid_dir(bf);
  1712. free(bf);
  1713. return 0;
  1714. }