kallsyms.c 18 KB

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