kallsyms.c 18 KB

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