kallsyms.c 18 KB

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