kallsyms.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. /* Generate assembler source containing symbol information
  2. *
  3. * Copyright 2002 by Kai Germaschewski
  4. *
  5. * This software may be used and distributed according to the terms
  6. * of the GNU General Public License, incorporated herein by reference.
  7. *
  8. * Usage: nm -n vmlinux | scripts/kallsyms [--all-symbols] > symbols.S
  9. *
  10. * Table compression uses all the unused char codes on the symbols and
  11. * maps these to the most used substrings (tokens). For instance, it might
  12. * map char code 0xF7 to represent "write_" and then in every symbol where
  13. * "write_" appears it can be replaced by 0xF7, saving 5 bytes.
  14. * The used codes themselves are also placed in the table so that the
  15. * decompresion can work without "special cases".
  16. * Applied to kernel symbols, this usually produces a compression ratio
  17. * of about 50%.
  18. *
  19. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <ctype.h>
  24. #include <limits.h>
  25. #ifndef ARRAY_SIZE
  26. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
  27. #endif
  28. #define KSYM_NAME_LEN 128
  29. struct sym_entry {
  30. unsigned long long addr;
  31. unsigned int len;
  32. unsigned int start_pos;
  33. unsigned char *sym;
  34. unsigned int percpu_absolute;
  35. };
  36. struct addr_range {
  37. const char *start_sym, *end_sym;
  38. unsigned long long start, end;
  39. };
  40. static unsigned long long _text;
  41. static unsigned long long relative_base;
  42. static struct addr_range text_ranges[] = {
  43. { "_stext", "_etext" },
  44. { "_sinittext", "_einittext" },
  45. { "_stext_l1", "_etext_l1" }, /* Blackfin on-chip L1 inst SRAM */
  46. { "_stext_l2", "_etext_l2" }, /* Blackfin on-chip L2 SRAM */
  47. };
  48. #define text_range_text (&text_ranges[0])
  49. #define text_range_inittext (&text_ranges[1])
  50. static struct addr_range percpu_range = {
  51. "__per_cpu_start", "__per_cpu_end", -1ULL, 0
  52. };
  53. static struct sym_entry *table;
  54. static unsigned int table_size, table_cnt;
  55. static int all_symbols = 0;
  56. static int absolute_percpu = 0;
  57. static int base_relative = 0;
  58. int token_profit[0x10000];
  59. /* the table that holds the result of the compression */
  60. unsigned char best_table[256][2];
  61. unsigned char best_table_len[256];
  62. static void usage(void)
  63. {
  64. fprintf(stderr, "Usage: kallsyms [--all-symbols] "
  65. "[--base-relative] < in.map > out.S\n");
  66. exit(1);
  67. }
  68. /*
  69. * This ignores the intensely annoying "mapping symbols" found
  70. * in ARM ELF files: $a, $t and $d.
  71. */
  72. static inline int is_arm_mapping_symbol(const char *str)
  73. {
  74. return str[0] == '$' && strchr("axtd", str[1])
  75. && (str[2] == '\0' || str[2] == '.');
  76. }
  77. static int check_symbol_range(const char *sym, unsigned long long addr,
  78. struct addr_range *ranges, int entries)
  79. {
  80. size_t i;
  81. struct addr_range *ar;
  82. for (i = 0; i < entries; ++i) {
  83. ar = &ranges[i];
  84. if (strcmp(sym, ar->start_sym) == 0) {
  85. ar->start = addr;
  86. return 0;
  87. } else if (strcmp(sym, ar->end_sym) == 0) {
  88. ar->end = addr;
  89. return 0;
  90. }
  91. }
  92. return 1;
  93. }
  94. static int read_symbol(FILE *in, struct sym_entry *s)
  95. {
  96. char sym[500], stype;
  97. int rc;
  98. rc = fscanf(in, "%llx %c %499s\n", &s->addr, &stype, sym);
  99. if (rc != 3) {
  100. if (rc != EOF && fgets(sym, 500, in) == NULL)
  101. fprintf(stderr, "Read error or end of file.\n");
  102. return -1;
  103. }
  104. if (strlen(sym) > KSYM_NAME_LEN) {
  105. fprintf(stderr, "Symbol %s too long for kallsyms (%zu vs %d).\n"
  106. "Please increase KSYM_NAME_LEN both in kernel and kallsyms.c\n",
  107. sym, strlen(sym), KSYM_NAME_LEN);
  108. return -1;
  109. }
  110. /* Ignore most absolute/undefined (?) symbols. */
  111. if (strcmp(sym, "_text") == 0)
  112. _text = s->addr;
  113. else if (check_symbol_range(sym, s->addr, text_ranges,
  114. ARRAY_SIZE(text_ranges)) == 0)
  115. /* nothing to do */;
  116. else if (toupper(stype) == 'A')
  117. {
  118. /* Keep these useful absolute symbols */
  119. if (strcmp(sym, "__kernel_syscall_via_break") &&
  120. strcmp(sym, "__kernel_syscall_via_epc") &&
  121. strcmp(sym, "__kernel_sigtramp") &&
  122. strcmp(sym, "__gp"))
  123. return -1;
  124. }
  125. else if (toupper(stype) == 'U' ||
  126. is_arm_mapping_symbol(sym))
  127. return -1;
  128. /* exclude also MIPS ELF local symbols ($L123 instead of .L123) */
  129. else if (sym[0] == '$')
  130. return -1;
  131. /* exclude debugging symbols */
  132. else if (stype == 'N' || stype == 'n')
  133. return -1;
  134. /* include the type field in the symbol name, so that it gets
  135. * compressed together */
  136. s->len = strlen(sym) + 1;
  137. s->sym = malloc(s->len + 1);
  138. if (!s->sym) {
  139. fprintf(stderr, "kallsyms failure: "
  140. "unable to allocate required amount of memory\n");
  141. exit(EXIT_FAILURE);
  142. }
  143. strcpy((char *)s->sym + 1, sym);
  144. s->sym[0] = stype;
  145. s->percpu_absolute = 0;
  146. /* Record if we've found __per_cpu_start/end. */
  147. check_symbol_range(sym, s->addr, &percpu_range, 1);
  148. return 0;
  149. }
  150. static int symbol_in_range(struct sym_entry *s, struct addr_range *ranges,
  151. int entries)
  152. {
  153. size_t i;
  154. struct addr_range *ar;
  155. for (i = 0; i < entries; ++i) {
  156. ar = &ranges[i];
  157. if (s->addr >= ar->start && s->addr <= ar->end)
  158. return 1;
  159. }
  160. return 0;
  161. }
  162. static int symbol_valid(struct sym_entry *s)
  163. {
  164. /* Symbols which vary between passes. Passes 1 and 2 must have
  165. * identical symbol lists. The kallsyms_* symbols below are only added
  166. * after pass 1, they would be included in pass 2 when --all-symbols is
  167. * specified so exclude them to get a stable symbol list.
  168. */
  169. static char *special_symbols[] = {
  170. "kallsyms_addresses",
  171. "kallsyms_offsets",
  172. "kallsyms_relative_base",
  173. "kallsyms_num_syms",
  174. "kallsyms_names",
  175. "kallsyms_markers",
  176. "kallsyms_token_table",
  177. "kallsyms_token_index",
  178. /* Exclude linker generated symbols which vary between passes */
  179. "_SDA_BASE_", /* ppc */
  180. "_SDA2_BASE_", /* ppc */
  181. NULL };
  182. static char *special_prefixes[] = {
  183. "__crc_", /* modversions */
  184. "__efistub_", /* arm64 EFI stub namespace */
  185. NULL };
  186. static char *special_suffixes[] = {
  187. "_veneer", /* arm */
  188. "_from_arm", /* arm */
  189. "_from_thumb", /* arm */
  190. NULL };
  191. int i;
  192. char *sym_name = (char *)s->sym + 1;
  193. /* if --all-symbols is not specified, then symbols outside the text
  194. * and inittext sections are discarded */
  195. if (!all_symbols) {
  196. if (symbol_in_range(s, text_ranges,
  197. ARRAY_SIZE(text_ranges)) == 0)
  198. return 0;
  199. /* Corner case. Discard any symbols with the same value as
  200. * _etext _einittext; they can move between pass 1 and 2 when
  201. * the kallsyms data are added. If these symbols move then
  202. * they may get dropped in pass 2, which breaks the kallsyms
  203. * rules.
  204. */
  205. if ((s->addr == text_range_text->end &&
  206. strcmp(sym_name,
  207. text_range_text->end_sym)) ||
  208. (s->addr == text_range_inittext->end &&
  209. strcmp(sym_name,
  210. text_range_inittext->end_sym)))
  211. return 0;
  212. }
  213. /* Exclude symbols which vary between passes. */
  214. for (i = 0; special_symbols[i]; i++)
  215. if (strcmp(sym_name, special_symbols[i]) == 0)
  216. return 0;
  217. for (i = 0; special_prefixes[i]; i++) {
  218. int l = strlen(special_prefixes[i]);
  219. if (l <= strlen(sym_name) &&
  220. strncmp(sym_name, special_prefixes[i], l) == 0)
  221. return 0;
  222. }
  223. for (i = 0; special_suffixes[i]; i++) {
  224. int l = strlen(sym_name) - strlen(special_suffixes[i]);
  225. if (l >= 0 && strcmp(sym_name + l, special_suffixes[i]) == 0)
  226. return 0;
  227. }
  228. return 1;
  229. }
  230. static void read_map(FILE *in)
  231. {
  232. while (!feof(in)) {
  233. if (table_cnt >= table_size) {
  234. table_size += 10000;
  235. table = realloc(table, sizeof(*table) * table_size);
  236. if (!table) {
  237. fprintf(stderr, "out of memory\n");
  238. exit (1);
  239. }
  240. }
  241. if (read_symbol(in, &table[table_cnt]) == 0) {
  242. table[table_cnt].start_pos = table_cnt;
  243. table_cnt++;
  244. }
  245. }
  246. }
  247. static void output_label(char *label)
  248. {
  249. printf(".globl %s\n", label);
  250. printf("\tALGN\n");
  251. printf("%s:\n", label);
  252. }
  253. /* uncompress a compressed symbol. When this function is called, the best table
  254. * might still be compressed itself, so the function needs to be recursive */
  255. static int expand_symbol(unsigned char *data, int len, char *result)
  256. {
  257. int c, rlen, total=0;
  258. while (len) {
  259. c = *data;
  260. /* if the table holds a single char that is the same as the one
  261. * we are looking for, then end the search */
  262. if (best_table[c][0]==c && best_table_len[c]==1) {
  263. *result++ = c;
  264. total++;
  265. } else {
  266. /* if not, recurse and expand */
  267. rlen = expand_symbol(best_table[c], best_table_len[c], result);
  268. total += rlen;
  269. result += rlen;
  270. }
  271. data++;
  272. len--;
  273. }
  274. *result=0;
  275. return total;
  276. }
  277. static int symbol_absolute(struct sym_entry *s)
  278. {
  279. return s->percpu_absolute;
  280. }
  281. static void write_src(void)
  282. {
  283. unsigned int i, k, off;
  284. unsigned int best_idx[256];
  285. unsigned int *markers;
  286. char buf[KSYM_NAME_LEN];
  287. printf("#include <asm/types.h>\n");
  288. printf("#if BITS_PER_LONG == 64\n");
  289. printf("#define PTR .quad\n");
  290. printf("#define ALGN .align 8\n");
  291. printf("#else\n");
  292. printf("#define PTR .long\n");
  293. printf("#define ALGN .align 4\n");
  294. printf("#endif\n");
  295. printf("\t.section .rodata, \"a\"\n");
  296. /* Provide proper symbols relocatability by their relativeness
  297. * to a fixed anchor point in the runtime image, either '_text'
  298. * for absolute address tables, in which case the linker will
  299. * emit the final addresses at build time. Otherwise, use the
  300. * offset relative to the lowest value encountered of all relative
  301. * symbols, and emit non-relocatable fixed offsets that will be fixed
  302. * up at runtime.
  303. *
  304. * The symbol names cannot be used to construct normal symbol
  305. * references as the list of symbols contains symbols that are
  306. * declared static and are private to their .o files. This prevents
  307. * .tmp_kallsyms.o or any other object from referencing them.
  308. */
  309. if (!base_relative)
  310. output_label("kallsyms_addresses");
  311. else
  312. output_label("kallsyms_offsets");
  313. for (i = 0; i < table_cnt; i++) {
  314. if (base_relative) {
  315. long long offset;
  316. int overflow;
  317. if (!absolute_percpu) {
  318. offset = table[i].addr - relative_base;
  319. overflow = (offset < 0 || offset > UINT_MAX);
  320. } else if (symbol_absolute(&table[i])) {
  321. offset = table[i].addr;
  322. overflow = (offset < 0 || offset > INT_MAX);
  323. } else {
  324. offset = relative_base - table[i].addr - 1;
  325. overflow = (offset < INT_MIN || offset >= 0);
  326. }
  327. if (overflow) {
  328. fprintf(stderr, "kallsyms failure: "
  329. "%s symbol value %#llx out of range in relative mode\n",
  330. symbol_absolute(&table[i]) ? "absolute" : "relative",
  331. table[i].addr);
  332. exit(EXIT_FAILURE);
  333. }
  334. printf("\t.long\t%#x\n", (int)offset);
  335. } else if (!symbol_absolute(&table[i])) {
  336. if (_text <= table[i].addr)
  337. printf("\tPTR\t_text + %#llx\n",
  338. table[i].addr - _text);
  339. else
  340. printf("\tPTR\t_text - %#llx\n",
  341. _text - table[i].addr);
  342. } else {
  343. printf("\tPTR\t%#llx\n", table[i].addr);
  344. }
  345. }
  346. printf("\n");
  347. if (base_relative) {
  348. output_label("kallsyms_relative_base");
  349. printf("\tPTR\t_text - %#llx\n", _text - relative_base);
  350. printf("\n");
  351. }
  352. output_label("kallsyms_num_syms");
  353. printf("\tPTR\t%u\n", table_cnt);
  354. printf("\n");
  355. /* table of offset markers, that give the offset in the compressed stream
  356. * every 256 symbols */
  357. markers = malloc(sizeof(unsigned int) * ((table_cnt + 255) / 256));
  358. if (!markers) {
  359. fprintf(stderr, "kallsyms failure: "
  360. "unable to allocate required memory\n");
  361. exit(EXIT_FAILURE);
  362. }
  363. output_label("kallsyms_names");
  364. off = 0;
  365. for (i = 0; i < table_cnt; i++) {
  366. if ((i & 0xFF) == 0)
  367. markers[i >> 8] = off;
  368. printf("\t.byte 0x%02x", table[i].len);
  369. for (k = 0; k < table[i].len; k++)
  370. printf(", 0x%02x", table[i].sym[k]);
  371. printf("\n");
  372. off += table[i].len + 1;
  373. }
  374. printf("\n");
  375. output_label("kallsyms_markers");
  376. for (i = 0; i < ((table_cnt + 255) >> 8); i++)
  377. printf("\tPTR\t%d\n", markers[i]);
  378. printf("\n");
  379. free(markers);
  380. output_label("kallsyms_token_table");
  381. off = 0;
  382. for (i = 0; i < 256; i++) {
  383. best_idx[i] = off;
  384. expand_symbol(best_table[i], best_table_len[i], buf);
  385. printf("\t.asciz\t\"%s\"\n", buf);
  386. off += strlen(buf) + 1;
  387. }
  388. printf("\n");
  389. output_label("kallsyms_token_index");
  390. for (i = 0; i < 256; i++)
  391. printf("\t.short\t%d\n", best_idx[i]);
  392. printf("\n");
  393. }
  394. /* table lookup compression functions */
  395. /* count all the possible tokens in a symbol */
  396. static void learn_symbol(unsigned char *symbol, int len)
  397. {
  398. int i;
  399. for (i = 0; i < len - 1; i++)
  400. token_profit[ symbol[i] + (symbol[i + 1] << 8) ]++;
  401. }
  402. /* decrease the count for all the possible tokens in a symbol */
  403. static void forget_symbol(unsigned char *symbol, int len)
  404. {
  405. int i;
  406. for (i = 0; i < len - 1; i++)
  407. token_profit[ symbol[i] + (symbol[i + 1] << 8) ]--;
  408. }
  409. /* remove all the invalid symbols from the table and do the initial token count */
  410. static void build_initial_tok_table(void)
  411. {
  412. unsigned int i, pos;
  413. pos = 0;
  414. for (i = 0; i < table_cnt; i++) {
  415. if ( symbol_valid(&table[i]) ) {
  416. if (pos != i)
  417. table[pos] = table[i];
  418. learn_symbol(table[pos].sym, table[pos].len);
  419. pos++;
  420. }
  421. }
  422. table_cnt = pos;
  423. }
  424. static void *find_token(unsigned char *str, int len, unsigned char *token)
  425. {
  426. int i;
  427. for (i = 0; i < len - 1; i++) {
  428. if (str[i] == token[0] && str[i+1] == token[1])
  429. return &str[i];
  430. }
  431. return NULL;
  432. }
  433. /* replace a given token in all the valid symbols. Use the sampled symbols
  434. * to update the counts */
  435. static void compress_symbols(unsigned char *str, int idx)
  436. {
  437. unsigned int i, len, size;
  438. unsigned char *p1, *p2;
  439. for (i = 0; i < table_cnt; i++) {
  440. len = table[i].len;
  441. p1 = table[i].sym;
  442. /* find the token on the symbol */
  443. p2 = find_token(p1, len, str);
  444. if (!p2) continue;
  445. /* decrease the counts for this symbol's tokens */
  446. forget_symbol(table[i].sym, len);
  447. size = len;
  448. do {
  449. *p2 = idx;
  450. p2++;
  451. size -= (p2 - p1);
  452. memmove(p2, p2 + 1, size);
  453. p1 = p2;
  454. len--;
  455. if (size < 2) break;
  456. /* find the token on the symbol */
  457. p2 = find_token(p1, size, str);
  458. } while (p2);
  459. table[i].len = len;
  460. /* increase the counts for this symbol's new tokens */
  461. learn_symbol(table[i].sym, len);
  462. }
  463. }
  464. /* search the token with the maximum profit */
  465. static int find_best_token(void)
  466. {
  467. int i, best, bestprofit;
  468. bestprofit=-10000;
  469. best = 0;
  470. for (i = 0; i < 0x10000; i++) {
  471. if (token_profit[i] > bestprofit) {
  472. best = i;
  473. bestprofit = token_profit[i];
  474. }
  475. }
  476. return best;
  477. }
  478. /* this is the core of the algorithm: calculate the "best" table */
  479. static void optimize_result(void)
  480. {
  481. int i, best;
  482. /* using the '\0' symbol last allows compress_symbols to use standard
  483. * fast string functions */
  484. for (i = 255; i >= 0; i--) {
  485. /* if this table slot is empty (it is not used by an actual
  486. * original char code */
  487. if (!best_table_len[i]) {
  488. /* find the token with the best profit value */
  489. best = find_best_token();
  490. if (token_profit[best] == 0)
  491. break;
  492. /* place it in the "best" table */
  493. best_table_len[i] = 2;
  494. best_table[i][0] = best & 0xFF;
  495. best_table[i][1] = (best >> 8) & 0xFF;
  496. /* replace this token in all the valid symbols */
  497. compress_symbols(best_table[i], i);
  498. }
  499. }
  500. }
  501. /* start by placing the symbols that are actually used on the table */
  502. static void insert_real_symbols_in_table(void)
  503. {
  504. unsigned int i, j, c;
  505. memset(best_table, 0, sizeof(best_table));
  506. memset(best_table_len, 0, sizeof(best_table_len));
  507. for (i = 0; i < table_cnt; i++) {
  508. for (j = 0; j < table[i].len; j++) {
  509. c = table[i].sym[j];
  510. best_table[c][0]=c;
  511. best_table_len[c]=1;
  512. }
  513. }
  514. }
  515. static void optimize_token_table(void)
  516. {
  517. build_initial_tok_table();
  518. insert_real_symbols_in_table();
  519. /* When valid symbol is not registered, exit to error */
  520. if (!table_cnt) {
  521. fprintf(stderr, "No valid symbol.\n");
  522. exit(1);
  523. }
  524. optimize_result();
  525. }
  526. /* guess for "linker script provide" symbol */
  527. static int may_be_linker_script_provide_symbol(const struct sym_entry *se)
  528. {
  529. const char *symbol = (char *)se->sym + 1;
  530. int len = se->len - 1;
  531. if (len < 8)
  532. return 0;
  533. if (symbol[0] != '_' || symbol[1] != '_')
  534. return 0;
  535. /* __start_XXXXX */
  536. if (!memcmp(symbol + 2, "start_", 6))
  537. return 1;
  538. /* __stop_XXXXX */
  539. if (!memcmp(symbol + 2, "stop_", 5))
  540. return 1;
  541. /* __end_XXXXX */
  542. if (!memcmp(symbol + 2, "end_", 4))
  543. return 1;
  544. /* __XXXXX_start */
  545. if (!memcmp(symbol + len - 6, "_start", 6))
  546. return 1;
  547. /* __XXXXX_end */
  548. if (!memcmp(symbol + len - 4, "_end", 4))
  549. return 1;
  550. return 0;
  551. }
  552. static int prefix_underscores_count(const char *str)
  553. {
  554. const char *tail = str;
  555. while (*tail == '_')
  556. tail++;
  557. return tail - str;
  558. }
  559. static int compare_symbols(const void *a, const void *b)
  560. {
  561. const struct sym_entry *sa;
  562. const struct sym_entry *sb;
  563. int wa, wb;
  564. sa = a;
  565. sb = b;
  566. /* sort by address first */
  567. if (sa->addr > sb->addr)
  568. return 1;
  569. if (sa->addr < sb->addr)
  570. return -1;
  571. /* sort by "weakness" type */
  572. wa = (sa->sym[0] == 'w') || (sa->sym[0] == 'W');
  573. wb = (sb->sym[0] == 'w') || (sb->sym[0] == 'W');
  574. if (wa != wb)
  575. return wa - wb;
  576. /* sort by "linker script provide" type */
  577. wa = may_be_linker_script_provide_symbol(sa);
  578. wb = may_be_linker_script_provide_symbol(sb);
  579. if (wa != wb)
  580. return wa - wb;
  581. /* sort by the number of prefix underscores */
  582. wa = prefix_underscores_count((const char *)sa->sym + 1);
  583. wb = prefix_underscores_count((const char *)sb->sym + 1);
  584. if (wa != wb)
  585. return wa - wb;
  586. /* sort by initial order, so that other symbols are left undisturbed */
  587. return sa->start_pos - sb->start_pos;
  588. }
  589. static void sort_symbols(void)
  590. {
  591. qsort(table, table_cnt, sizeof(struct sym_entry), compare_symbols);
  592. }
  593. static void make_percpus_absolute(void)
  594. {
  595. unsigned int i;
  596. for (i = 0; i < table_cnt; i++)
  597. if (symbol_in_range(&table[i], &percpu_range, 1)) {
  598. /*
  599. * Keep the 'A' override for percpu symbols to
  600. * ensure consistent behavior compared to older
  601. * versions of this tool.
  602. */
  603. table[i].sym[0] = 'A';
  604. table[i].percpu_absolute = 1;
  605. }
  606. }
  607. /* find the minimum non-absolute symbol address */
  608. static void record_relative_base(void)
  609. {
  610. unsigned int i;
  611. relative_base = -1ULL;
  612. for (i = 0; i < table_cnt; i++)
  613. if (!symbol_absolute(&table[i]) &&
  614. table[i].addr < relative_base)
  615. relative_base = table[i].addr;
  616. }
  617. int main(int argc, char **argv)
  618. {
  619. if (argc >= 2) {
  620. int i;
  621. for (i = 1; i < argc; i++) {
  622. if(strcmp(argv[i], "--all-symbols") == 0)
  623. all_symbols = 1;
  624. else if (strcmp(argv[i], "--absolute-percpu") == 0)
  625. absolute_percpu = 1;
  626. else if (strcmp(argv[i], "--base-relative") == 0)
  627. base_relative = 1;
  628. else
  629. usage();
  630. }
  631. } else if (argc != 1)
  632. usage();
  633. read_map(stdin);
  634. if (absolute_percpu)
  635. make_percpus_absolute();
  636. if (base_relative)
  637. record_relative_base();
  638. sort_symbols();
  639. optimize_token_table();
  640. write_src();
  641. return 0;
  642. }