4317cf95ca024 scripts/sortextable.h (Thomas Gleixner 2019-05-31 01:09:38 -0700 1) /* SPDX-License-Identifier: GPL-2.0-only */
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 2) /*
1091670637be8 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:31 +0800 3) * sorttable.h
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 4) *
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 5) * Added ORC unwind tables sort support and other updates:
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 6) * Copyright (C) 1999-2019 Alibaba Group Holding Limited. by:
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 7) * Shile Zhang <shile.zhang@linux.alibaba.com>
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 8) *
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 9) * Copyright 2011 - 2012 Cavium, Inc.
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 10) *
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 11) * Some of code was taken out of arch/x86/kernel/unwind_orc.c, written by:
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 12) * Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 13) *
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 14) * Some of this code was taken out of recordmcount.h written by:
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 15) *
6402e1416255a scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:28 +0800 16) * Copyright 2009 John F. Reiser <jreiser@BitWagon.com>. All rights reserved.
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 17) * Copyright 2010 Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 18) */
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 19)
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 20) #undef extable_ent_size
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 21) #undef compare_extable
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 22) #undef do_sort
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 23) #undef Elf_Addr
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 24) #undef Elf_Ehdr
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 25) #undef Elf_Shdr
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 26) #undef Elf_Rel
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 27) #undef Elf_Rela
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 28) #undef Elf_Sym
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 29) #undef ELF_R_SYM
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 30) #undef Elf_r_sym
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 31) #undef ELF_R_INFO
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 32) #undef Elf_r_info
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 33) #undef ELF_ST_BIND
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 34) #undef ELF_ST_TYPE
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 35) #undef fn_ELF_R_SYM
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 36) #undef fn_ELF_R_INFO
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 37) #undef uint_t
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 38) #undef _r
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 39) #undef _w
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 40)
1091670637be8 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:31 +0800 41) #ifdef SORTTABLE_64
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 42) # define extable_ent_size 16
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 43) # define compare_extable compare_extable_64
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 44) # define do_sort do_sort_64
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 45) # define Elf_Addr Elf64_Addr
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 46) # define Elf_Ehdr Elf64_Ehdr
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 47) # define Elf_Shdr Elf64_Shdr
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 48) # define Elf_Rel Elf64_Rel
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 49) # define Elf_Rela Elf64_Rela
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 50) # define Elf_Sym Elf64_Sym
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 51) # define ELF_R_SYM ELF64_R_SYM
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 52) # define Elf_r_sym Elf64_r_sym
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 53) # define ELF_R_INFO ELF64_R_INFO
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 54) # define Elf_r_info Elf64_r_info
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 55) # define ELF_ST_BIND ELF64_ST_BIND
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 56) # define ELF_ST_TYPE ELF64_ST_TYPE
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 57) # define fn_ELF_R_SYM fn_ELF64_R_SYM
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 58) # define fn_ELF_R_INFO fn_ELF64_R_INFO
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 59) # define uint_t uint64_t
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 60) # define _r r8
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 61) # define _w w8
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 62) #else
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 63) # define extable_ent_size 8
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 64) # define compare_extable compare_extable_32
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 65) # define do_sort do_sort_32
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 66) # define Elf_Addr Elf32_Addr
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 67) # define Elf_Ehdr Elf32_Ehdr
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 68) # define Elf_Shdr Elf32_Shdr
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 69) # define Elf_Rel Elf32_Rel
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 70) # define Elf_Rela Elf32_Rela
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 71) # define Elf_Sym Elf32_Sym
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 72) # define ELF_R_SYM ELF32_R_SYM
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 73) # define Elf_r_sym Elf32_r_sym
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 74) # define ELF_R_INFO ELF32_R_INFO
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 75) # define Elf_r_info Elf32_r_info
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 76) # define ELF_ST_BIND ELF32_ST_BIND
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 77) # define ELF_ST_TYPE ELF32_ST_TYPE
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 78) # define fn_ELF_R_SYM fn_ELF32_R_SYM
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 79) # define fn_ELF_R_INFO fn_ELF32_R_INFO
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 80) # define uint_t uint32_t
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 81) # define _r r
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 82) # define _w w
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 83) #endif
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 84)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 85) #if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 86) /* ORC unwinder only support X86_64 */
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 87) #include <errno.h>
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 88) #include <pthread.h>
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 89) #include <asm/orc_types.h>
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 90)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 91) #define ERRSTR_MAXSZ 256
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 92)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 93) char g_err[ERRSTR_MAXSZ];
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 94) int *g_orc_ip_table;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 95) struct orc_entry *g_orc_table;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 96)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 97) pthread_t orc_sort_thread;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 98)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 99) static inline unsigned long orc_ip(const int *ip)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 100) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 101) return (unsigned long)ip + *ip;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 102) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 103)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 104) static int orc_sort_cmp(const void *_a, const void *_b)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 105) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 106) struct orc_entry *orc_a;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 107) const int *a = g_orc_ip_table + *(int *)_a;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 108) const int *b = g_orc_ip_table + *(int *)_b;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 109) unsigned long a_val = orc_ip(a);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 110) unsigned long b_val = orc_ip(b);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 111)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 112) if (a_val > b_val)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 113) return 1;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 114) if (a_val < b_val)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 115) return -1;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 116)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 117) /*
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 118) * The "weak" section terminator entries need to always be on the left
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 119) * to ensure the lookup code skips them in favor of real entries.
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 120) * These terminator entries exist to handle any gaps created by
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 121) * whitelisted .o files which didn't get objtool generation.
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 122) */
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 123) orc_a = g_orc_table + (a - g_orc_ip_table);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 124) return orc_a->sp_reg == ORC_REG_UNDEFINED && !orc_a->end ? -1 : 1;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 125) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 126)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 127) static void *sort_orctable(void *arg)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 128) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 129) int i;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 130) int *idxs = NULL;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 131) int *tmp_orc_ip_table = NULL;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 132) struct orc_entry *tmp_orc_table = NULL;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 133) unsigned int *orc_ip_size = (unsigned int *)arg;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 134) unsigned int num_entries = *orc_ip_size / sizeof(int);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 135) unsigned int orc_size = num_entries * sizeof(struct orc_entry);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 136)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 137) idxs = (int *)malloc(*orc_ip_size);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 138) if (!idxs) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 139) snprintf(g_err, ERRSTR_MAXSZ, "malloc idxs: %s",
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 140) strerror(errno));
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 141) pthread_exit(g_err);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 142) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 143)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 144) tmp_orc_ip_table = (int *)malloc(*orc_ip_size);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 145) if (!tmp_orc_ip_table) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 146) snprintf(g_err, ERRSTR_MAXSZ, "malloc tmp_orc_ip_table: %s",
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 147) strerror(errno));
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 148) pthread_exit(g_err);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 149) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 150)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 151) tmp_orc_table = (struct orc_entry *)malloc(orc_size);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 152) if (!tmp_orc_table) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 153) snprintf(g_err, ERRSTR_MAXSZ, "malloc tmp_orc_table: %s",
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 154) strerror(errno));
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 155) pthread_exit(g_err);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 156) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 157)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 158) /* initialize indices array, convert ip_table to absolute address */
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 159) for (i = 0; i < num_entries; i++) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 160) idxs[i] = i;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 161) tmp_orc_ip_table[i] = g_orc_ip_table[i] + i * sizeof(int);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 162) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 163) memcpy(tmp_orc_table, g_orc_table, orc_size);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 164)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 165) qsort(idxs, num_entries, sizeof(int), orc_sort_cmp);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 166)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 167) for (i = 0; i < num_entries; i++) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 168) if (idxs[i] == i)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 169) continue;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 170)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 171) /* convert back to relative address */
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 172) g_orc_ip_table[i] = tmp_orc_ip_table[idxs[i]] - i * sizeof(int);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 173) g_orc_table[i] = tmp_orc_table[idxs[i]];
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 174) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 175)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 176) free(idxs);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 177) free(tmp_orc_ip_table);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 178) free(tmp_orc_table);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 179) pthread_exit(NULL);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 180) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 181) #endif
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 182)
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 183) static int compare_extable(const void *a, const void *b)
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 184) {
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 185) Elf_Addr av = _r(a);
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 186) Elf_Addr bv = _r(b);
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 187)
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 188) if (av < bv)
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 189) return -1;
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 190) if (av > bv)
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 191) return 1;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 192) return 0;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 193) }
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 194)
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 195) static int do_sort(Elf_Ehdr *ehdr,
6402e1416255a scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:28 +0800 196) char const *const fname,
6402e1416255a scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:28 +0800 197) table_sort_t custom_sort)
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 198) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 199) int rc = -1;
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 200) Elf_Shdr *s, *shdr = (Elf_Shdr *)((char *)ehdr + _r(&ehdr->e_shoff));
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 201) Elf_Shdr *strtab_sec = NULL;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 202) Elf_Shdr *symtab_sec = NULL;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 203) Elf_Shdr *extab_sec = NULL;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 204) Elf_Sym *sym;
59c36455d061e scripts/sortextable.h (Jamie Iles 2013-11-12 15:06:51 -0800 205) const Elf_Sym *symtab;
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 206) Elf32_Word *symtab_shndx = NULL;
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 207) Elf_Sym *sort_needed_sym = NULL;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 208) Elf_Shdr *sort_needed_sec;
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 209) Elf_Rel *relocs = NULL;
7cbc0ea79da2c scripts/sortextable.h (Tim Gardner 2014-10-13 15:54:20 -0700 210) int relocs_size = 0;
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 211) uint32_t *sort_needed_loc;
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 212) const char *secstrings;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 213) const char *strtab;
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 214) char *extab_image;
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 215) int extab_index = 0;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 216) int i;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 217) int idx;
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 218) unsigned int shnum;
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 219) unsigned int shstrndx;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 220) #if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 221) unsigned int orc_ip_size = 0;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 222) unsigned int orc_size = 0;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 223) unsigned int orc_num_entries = 0;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 224) #endif
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 225)
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 226) shstrndx = r2(&ehdr->e_shstrndx);
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 227) if (shstrndx == SHN_XINDEX)
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 228) shstrndx = r(&shdr[0].sh_link);
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 229) secstrings = (const char *)ehdr + _r(&shdr[shstrndx].sh_offset);
59c36455d061e scripts/sortextable.h (Jamie Iles 2013-11-12 15:06:51 -0800 230)
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 231) shnum = r2(&ehdr->e_shnum);
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 232) if (shnum == SHN_UNDEF)
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 233) shnum = _r(&shdr[0].sh_size);
59c36455d061e scripts/sortextable.h (Jamie Iles 2013-11-12 15:06:51 -0800 234)
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 235) for (i = 0, s = shdr; s < shdr + shnum; i++, s++) {
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 236) idx = r(&s->sh_name);
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 237) if (!strcmp(secstrings + idx, "__ex_table")) {
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 238) extab_sec = s;
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 239) extab_index = i;
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 240) }
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 241) if (!strcmp(secstrings + idx, ".symtab"))
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 242) symtab_sec = s;
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 243) if (!strcmp(secstrings + idx, ".strtab"))
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 244) strtab_sec = s;
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 245)
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 246) if ((r(&s->sh_type) == SHT_REL ||
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 247) r(&s->sh_type) == SHT_RELA) &&
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 248) r(&s->sh_info) == extab_index) {
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 249) relocs = (void *)ehdr + _r(&s->sh_offset);
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 250) relocs_size = _r(&s->sh_size);
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 251) }
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 252) if (r(&s->sh_type) == SHT_SYMTAB_SHNDX)
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 253) symtab_shndx = (Elf32_Word *)((const char *)ehdr +
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 254) _r(&s->sh_offset));
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 255)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 256) #if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 257) /* locate the ORC unwind tables */
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 258) if (!strcmp(secstrings + idx, ".orc_unwind_ip")) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 259) orc_ip_size = s->sh_size;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 260) g_orc_ip_table = (int *)((void *)ehdr +
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 261) s->sh_offset);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 262) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 263) if (!strcmp(secstrings + idx, ".orc_unwind")) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 264) orc_size = s->sh_size;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 265) g_orc_table = (struct orc_entry *)((void *)ehdr +
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 266) s->sh_offset);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 267) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 268) #endif
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 269) } /* for loop */
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 270)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 271) #if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 272) if (!g_orc_ip_table || !g_orc_table) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 273) fprintf(stderr,
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 274) "incomplete ORC unwind tables in file: %s\n", fname);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 275) goto out;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 276) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 277)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 278) orc_num_entries = orc_ip_size / sizeof(int);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 279) if (orc_ip_size % sizeof(int) != 0 ||
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 280) orc_size % sizeof(struct orc_entry) != 0 ||
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 281) orc_num_entries != orc_size / sizeof(struct orc_entry)) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 282) fprintf(stderr,
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 283) "inconsistent ORC unwind table entries in file: %s\n",
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 284) fname);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 285) goto out;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 286) }
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 287)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 288) /* create thread to sort ORC unwind tables concurrently */
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 289) if (pthread_create(&orc_sort_thread, NULL,
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 290) sort_orctable, &orc_ip_size)) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 291) fprintf(stderr,
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 292) "pthread_create orc_sort_thread failed '%s': %s\n",
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 293) strerror(errno), fname);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 294) goto out;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 295) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 296) #endif
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 297) if (!extab_sec) {
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 298) fprintf(stderr, "no __ex_table in file: %s\n", fname);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 299) goto out;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 300) }
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 301)
6402e1416255a scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:28 +0800 302) if (!symtab_sec) {
6402e1416255a scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:28 +0800 303) fprintf(stderr, "no .symtab in file: %s\n", fname);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 304) goto out;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 305) }
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 306)
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 307) if (!strtab_sec) {
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 308) fprintf(stderr, "no .strtab in file: %s\n", fname);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 309) goto out;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 310) }
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 311)
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 312) extab_image = (void *)ehdr + _r(&extab_sec->sh_offset);
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 313) strtab = (const char *)ehdr + _r(&strtab_sec->sh_offset);
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 314) symtab = (const Elf_Sym *)((const char *)ehdr +
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 315) _r(&symtab_sec->sh_offset));
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 316)
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 317) if (custom_sort) {
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 318) custom_sort(extab_image, _r(&extab_sec->sh_size));
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 319) } else {
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 320) int num_entries = _r(&extab_sec->sh_size) / extable_ent_size;
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 321) qsort(extab_image, num_entries,
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 322) extable_ent_size, compare_extable);
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 323) }
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 324)
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 325) /* If there were relocations, we no longer need them. */
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 326) if (relocs)
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 327) memset(relocs, 0, relocs_size);
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 328)
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 329) /* find the flag main_extable_sort_needed */
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 330) for (sym = (void *)ehdr + _r(&symtab_sec->sh_offset);
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 331) sym < sym + _r(&symtab_sec->sh_size) / sizeof(Elf_Sym);
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 332) sym++) {
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 333) if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT)
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 334) continue;
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 335) if (!strcmp(strtab + r(&sym->st_name),
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 336) "main_extable_sort_needed")) {
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 337) sort_needed_sym = sym;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 338) break;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 339) }
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 340) }
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 341)
6402e1416255a scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:28 +0800 342) if (!sort_needed_sym) {
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 343) fprintf(stderr,
6402e1416255a scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:28 +0800 344) "no main_extable_sort_needed symbol in file: %s\n",
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 345) fname);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 346) goto out;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 347) }
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 348)
59c36455d061e scripts/sortextable.h (Jamie Iles 2013-11-12 15:06:51 -0800 349) sort_needed_sec = &shdr[get_secindex(r2(&sym->st_shndx),
59c36455d061e scripts/sortextable.h (Jamie Iles 2013-11-12 15:06:51 -0800 350) sort_needed_sym - symtab,
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 351) symtab_shndx)];
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 352) sort_needed_loc = (void *)ehdr +
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 353) _r(&sort_needed_sec->sh_offset) +
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 354) _r(&sort_needed_sym->st_value) -
d59a16836d917 scripts/sortextable.h (David Daney 2012-04-24 11:23:14 -0700 355) _r(&sort_needed_sec->sh_addr);
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 356)
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 357) /* extable has been sorted, clear the flag */
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 358) w(0, sort_needed_loc);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 359) rc = 0;
57cafdf2a04e1 scripts/sortextable.h (Shile Zhang 2019-12-04 08:46:30 +0800 360)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 361) out:
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 362) #if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 363) if (orc_sort_thread) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 364) void *retval = NULL;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 365) /* wait for ORC tables sort done */
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 366) rc = pthread_join(orc_sort_thread, &retval);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 367) if (rc)
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 368) fprintf(stderr,
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 369) "pthread_join failed '%s': %s\n",
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 370) strerror(errno), fname);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 371) else if (retval) {
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 372) rc = -1;
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 373) fprintf(stderr,
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 374) "failed to sort ORC tables '%s': %s\n",
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 375) (char *)retval, fname);
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 376) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 377) }
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 378) #endif
57fa189942853 scripts/sorttable.h (Shile Zhang 2019-12-04 08:46:32 +0800 379) return rc;
a79f248b9b309 scripts/sortextable.h (David Daney 2012-04-19 14:59:55 -0700 380) }