~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/sorttable.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/sorttable.c (Version linux-6.12-rc7) and /scripts/sorttable.c (Version linux-5.16.20)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*                                                  2 /*
  3  * sorttable.c: Sort the kernel's table             3  * sorttable.c: Sort the kernel's table
  4  *                                                  4  *
  5  * Added ORC unwind tables sort support and ot      5  * Added ORC unwind tables sort support and other updates:
  6  * Copyright (C) 1999-2019 Alibaba Group Holdi      6  * Copyright (C) 1999-2019 Alibaba Group Holding Limited. by:
  7  * Shile Zhang <shile.zhang@linux.alibaba.com>      7  * Shile Zhang <shile.zhang@linux.alibaba.com>
  8  *                                                  8  *
  9  * Copyright 2011 - 2012 Cavium, Inc.               9  * Copyright 2011 - 2012 Cavium, Inc.
 10  *                                                 10  *
 11  * Based on code taken from recortmcount.c whi     11  * Based on code taken from recortmcount.c which is:
 12  *                                                 12  *
 13  * Copyright 2009 John F. Reiser <jreiser@BitW     13  * Copyright 2009 John F. Reiser <jreiser@BitWagon.com>.  All rights reserved.
 14  *                                                 14  *
 15  * Restructured to fit Linux format, as well a     15  * Restructured to fit Linux format, as well as other updates:
 16  * Copyright 2010 Steven Rostedt <srostedt@red     16  * Copyright 2010 Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
 17  */                                                17  */
 18                                                    18 
 19 /*                                                 19 /*
 20  * Strategy: alter the vmlinux file in-place.      20  * Strategy: alter the vmlinux file in-place.
 21  */                                                21  */
 22                                                    22 
 23 #include <sys/types.h>                             23 #include <sys/types.h>
 24 #include <sys/mman.h>                              24 #include <sys/mman.h>
 25 #include <sys/stat.h>                              25 #include <sys/stat.h>
 26 #include <getopt.h>                                26 #include <getopt.h>
 27 #include <elf.h>                                   27 #include <elf.h>
 28 #include <fcntl.h>                                 28 #include <fcntl.h>
 29 #include <stdio.h>                                 29 #include <stdio.h>
 30 #include <stdlib.h>                                30 #include <stdlib.h>
 31 #include <string.h>                                31 #include <string.h>
 32 #include <unistd.h>                                32 #include <unistd.h>
 33 #include <errno.h>                             << 
 34 #include <pthread.h>                           << 
 35                                                    33 
 36 #include <tools/be_byteshift.h>                    34 #include <tools/be_byteshift.h>
 37 #include <tools/le_byteshift.h>                    35 #include <tools/le_byteshift.h>
 38                                                    36 
 39 #ifndef EM_ARCOMPACT                               37 #ifndef EM_ARCOMPACT
 40 #define EM_ARCOMPACT    93                         38 #define EM_ARCOMPACT    93
 41 #endif                                             39 #endif
 42                                                    40 
 43 #ifndef EM_XTENSA                                  41 #ifndef EM_XTENSA
 44 #define EM_XTENSA       94                         42 #define EM_XTENSA       94
 45 #endif                                             43 #endif
 46                                                    44 
 47 #ifndef EM_AARCH64                                 45 #ifndef EM_AARCH64
 48 #define EM_AARCH64      183                        46 #define EM_AARCH64      183
 49 #endif                                             47 #endif
 50                                                    48 
 51 #ifndef EM_MICROBLAZE                              49 #ifndef EM_MICROBLAZE
 52 #define EM_MICROBLAZE   189                        50 #define EM_MICROBLAZE   189
 53 #endif                                             51 #endif
 54                                                    52 
 55 #ifndef EM_ARCV2                                   53 #ifndef EM_ARCV2
 56 #define EM_ARCV2        195                        54 #define EM_ARCV2        195
 57 #endif                                             55 #endif
 58                                                    56 
 59 #ifndef EM_RISCV                                   57 #ifndef EM_RISCV
 60 #define EM_RISCV        243                        58 #define EM_RISCV        243
 61 #endif                                             59 #endif
 62                                                    60 
 63 #ifndef EM_LOONGARCH                           << 
 64 #define EM_LOONGARCH    258                    << 
 65 #endif                                         << 
 66                                                << 
 67 static uint32_t (*r)(const uint32_t *);            61 static uint32_t (*r)(const uint32_t *);
 68 static uint16_t (*r2)(const uint16_t *);           62 static uint16_t (*r2)(const uint16_t *);
 69 static uint64_t (*r8)(const uint64_t *);           63 static uint64_t (*r8)(const uint64_t *);
 70 static void (*w)(uint32_t, uint32_t *);            64 static void (*w)(uint32_t, uint32_t *);
 71 static void (*w2)(uint16_t, uint16_t *);           65 static void (*w2)(uint16_t, uint16_t *);
 72 static void (*w8)(uint64_t, uint64_t *);           66 static void (*w8)(uint64_t, uint64_t *);
 73 typedef void (*table_sort_t)(char *, int);         67 typedef void (*table_sort_t)(char *, int);
 74                                                    68 
 75 /*                                                 69 /*
 76  * Get the whole file as a programming conveni     70  * Get the whole file as a programming convenience in order to avoid
 77  * malloc+lseek+read+free of many pieces.  If      71  * malloc+lseek+read+free of many pieces.  If successful, then mmap
 78  * avoids copying unused pieces; else just rea     72  * avoids copying unused pieces; else just read the whole file.
 79  * Open for both read and write.                   73  * Open for both read and write.
 80  */                                                74  */
 81 static void *mmap_file(char const *fname, size     75 static void *mmap_file(char const *fname, size_t *size)
 82 {                                                  76 {
 83         int fd;                                    77         int fd;
 84         struct stat sb;                            78         struct stat sb;
 85         void *addr = NULL;                         79         void *addr = NULL;
 86                                                    80 
 87         fd = open(fname, O_RDWR);                  81         fd = open(fname, O_RDWR);
 88         if (fd < 0) {                              82         if (fd < 0) {
 89                 perror(fname);                     83                 perror(fname);
 90                 return NULL;                       84                 return NULL;
 91         }                                          85         }
 92         if (fstat(fd, &sb) < 0) {                  86         if (fstat(fd, &sb) < 0) {
 93                 perror(fname);                     87                 perror(fname);
 94                 goto out;                          88                 goto out;
 95         }                                          89         }
 96         if (!S_ISREG(sb.st_mode)) {                90         if (!S_ISREG(sb.st_mode)) {
 97                 fprintf(stderr, "not a regular     91                 fprintf(stderr, "not a regular file: %s\n", fname);
 98                 goto out;                          92                 goto out;
 99         }                                          93         }
100                                                    94 
101         addr = mmap(0, sb.st_size, PROT_READ|P     95         addr = mmap(0, sb.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
102         if (addr == MAP_FAILED) {                  96         if (addr == MAP_FAILED) {
103                 fprintf(stderr, "Could not mma     97                 fprintf(stderr, "Could not mmap file: %s\n", fname);
104                 goto out;                          98                 goto out;
105         }                                          99         }
106                                                   100 
107         *size = sb.st_size;                       101         *size = sb.st_size;
108                                                   102 
109 out:                                              103 out:
110         close(fd);                                104         close(fd);
111         return addr;                              105         return addr;
112 }                                                 106 }
113                                                   107 
114 static uint32_t rbe(const uint32_t *x)            108 static uint32_t rbe(const uint32_t *x)
115 {                                                 109 {
116         return get_unaligned_be32(x);             110         return get_unaligned_be32(x);
117 }                                                 111 }
118                                                   112 
119 static uint16_t r2be(const uint16_t *x)           113 static uint16_t r2be(const uint16_t *x)
120 {                                                 114 {
121         return get_unaligned_be16(x);             115         return get_unaligned_be16(x);
122 }                                                 116 }
123                                                   117 
124 static uint64_t r8be(const uint64_t *x)           118 static uint64_t r8be(const uint64_t *x)
125 {                                                 119 {
126         return get_unaligned_be64(x);             120         return get_unaligned_be64(x);
127 }                                                 121 }
128                                                   122 
129 static uint32_t rle(const uint32_t *x)            123 static uint32_t rle(const uint32_t *x)
130 {                                                 124 {
131         return get_unaligned_le32(x);             125         return get_unaligned_le32(x);
132 }                                                 126 }
133                                                   127 
134 static uint16_t r2le(const uint16_t *x)           128 static uint16_t r2le(const uint16_t *x)
135 {                                                 129 {
136         return get_unaligned_le16(x);             130         return get_unaligned_le16(x);
137 }                                                 131 }
138                                                   132 
139 static uint64_t r8le(const uint64_t *x)           133 static uint64_t r8le(const uint64_t *x)
140 {                                                 134 {
141         return get_unaligned_le64(x);             135         return get_unaligned_le64(x);
142 }                                                 136 }
143                                                   137 
144 static void wbe(uint32_t val, uint32_t *x)        138 static void wbe(uint32_t val, uint32_t *x)
145 {                                                 139 {
146         put_unaligned_be32(val, x);               140         put_unaligned_be32(val, x);
147 }                                                 141 }
148                                                   142 
149 static void w2be(uint16_t val, uint16_t *x)       143 static void w2be(uint16_t val, uint16_t *x)
150 {                                                 144 {
151         put_unaligned_be16(val, x);               145         put_unaligned_be16(val, x);
152 }                                                 146 }
153                                                   147 
154 static void w8be(uint64_t val, uint64_t *x)       148 static void w8be(uint64_t val, uint64_t *x)
155 {                                                 149 {
156         put_unaligned_be64(val, x);               150         put_unaligned_be64(val, x);
157 }                                                 151 }
158                                                   152 
159 static void wle(uint32_t val, uint32_t *x)        153 static void wle(uint32_t val, uint32_t *x)
160 {                                                 154 {
161         put_unaligned_le32(val, x);               155         put_unaligned_le32(val, x);
162 }                                                 156 }
163                                                   157 
164 static void w2le(uint16_t val, uint16_t *x)       158 static void w2le(uint16_t val, uint16_t *x)
165 {                                                 159 {
166         put_unaligned_le16(val, x);               160         put_unaligned_le16(val, x);
167 }                                                 161 }
168                                                   162 
169 static void w8le(uint64_t val, uint64_t *x)       163 static void w8le(uint64_t val, uint64_t *x)
170 {                                                 164 {
171         put_unaligned_le64(val, x);               165         put_unaligned_le64(val, x);
172 }                                                 166 }
173                                                   167 
174 /*                                                168 /*
175  * Move reserved section indices SHN_LORESERVE    169  * Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of
176  * the way to -256..-1, to avoid conflicting w    170  * the way to -256..-1, to avoid conflicting with real section
177  * indices.                                       171  * indices.
178  */                                               172  */
179 #define SPECIAL(i) ((i) - (SHN_HIRESERVE + 1))    173 #define SPECIAL(i) ((i) - (SHN_HIRESERVE + 1))
180                                                   174 
181 static inline int is_shndx_special(unsigned in    175 static inline int is_shndx_special(unsigned int i)
182 {                                                 176 {
183         return i != SHN_XINDEX && i >= SHN_LOR    177         return i != SHN_XINDEX && i >= SHN_LORESERVE && i <= SHN_HIRESERVE;
184 }                                                 178 }
185                                                   179 
186 /* Accessor for sym->st_shndx, hides ugliness     180 /* Accessor for sym->st_shndx, hides ugliness of "64k sections" */
187 static inline unsigned int get_secindex(unsign    181 static inline unsigned int get_secindex(unsigned int shndx,
188                                         unsign    182                                         unsigned int sym_offs,
189                                         const     183                                         const Elf32_Word *symtab_shndx_start)
190 {                                                 184 {
191         if (is_shndx_special(shndx))              185         if (is_shndx_special(shndx))
192                 return SPECIAL(shndx);            186                 return SPECIAL(shndx);
193         if (shndx != SHN_XINDEX)                  187         if (shndx != SHN_XINDEX)
194                 return shndx;                     188                 return shndx;
195         return r(&symtab_shndx_start[sym_offs]    189         return r(&symtab_shndx_start[sym_offs]);
196 }                                                 190 }
197                                                   191 
198 /* 32 bit and 64 bit are very similar */          192 /* 32 bit and 64 bit are very similar */
199 #include "sorttable.h"                            193 #include "sorttable.h"
200 #define SORTTABLE_64                              194 #define SORTTABLE_64
201 #include "sorttable.h"                            195 #include "sorttable.h"
202                                                   196 
203 static int compare_relative_table(const void *    197 static int compare_relative_table(const void *a, const void *b)
204 {                                                 198 {
205         int32_t av = (int32_t)r(a);               199         int32_t av = (int32_t)r(a);
206         int32_t bv = (int32_t)r(b);               200         int32_t bv = (int32_t)r(b);
207                                                   201 
208         if (av < bv)                              202         if (av < bv)
209                 return -1;                        203                 return -1;
210         if (av > bv)                              204         if (av > bv)
211                 return 1;                         205                 return 1;
212         return 0;                                 206         return 0;
213 }                                                 207 }
214                                                   208 
215 static void sort_relative_table(char *extab_im    209 static void sort_relative_table(char *extab_image, int image_size)
216 {                                                 210 {
217         int i = 0;                                211         int i = 0;
218                                                   212 
219         /*                                        213         /*
220          * Do the same thing the runtime sort     214          * Do the same thing the runtime sort does, first normalize to
221          * being relative to the start of the     215          * being relative to the start of the section.
222          */                                       216          */
223         while (i < image_size) {                  217         while (i < image_size) {
224                 uint32_t *loc = (uint32_t *)(e    218                 uint32_t *loc = (uint32_t *)(extab_image + i);
225                 w(r(loc) + i, loc);               219                 w(r(loc) + i, loc);
226                 i += 4;                           220                 i += 4;
227         }                                         221         }
228                                                   222 
229         qsort(extab_image, image_size / 8, 8,     223         qsort(extab_image, image_size / 8, 8, compare_relative_table);
230                                                   224 
231         /* Now denormalize. */                    225         /* Now denormalize. */
232         i = 0;                                    226         i = 0;
233         while (i < image_size) {                  227         while (i < image_size) {
234                 uint32_t *loc = (uint32_t *)(e    228                 uint32_t *loc = (uint32_t *)(extab_image + i);
235                 w(r(loc) - i, loc);               229                 w(r(loc) - i, loc);
236                 i += 4;                           230                 i += 4;
237         }                                         231         }
238 }                                                 232 }
239                                                   233 
240 static void sort_relative_table_with_data(char !! 234 static void arm64_sort_relative_table(char *extab_image, int image_size)
241 {                                                 235 {
242         int i = 0;                                236         int i = 0;
243                                                   237 
244         while (i < image_size) {                  238         while (i < image_size) {
245                 uint32_t *loc = (uint32_t *)(e    239                 uint32_t *loc = (uint32_t *)(extab_image + i);
246                                                   240 
247                 w(r(loc) + i, loc);               241                 w(r(loc) + i, loc);
248                 w(r(loc + 1) + i + 4, loc + 1)    242                 w(r(loc + 1) + i + 4, loc + 1);
249                 /* Don't touch the fixup type     243                 /* Don't touch the fixup type or data */
250                                                   244 
251                 i += sizeof(uint32_t) * 3;        245                 i += sizeof(uint32_t) * 3;
252         }                                         246         }
253                                                   247 
254         qsort(extab_image, image_size / 12, 12    248         qsort(extab_image, image_size / 12, 12, compare_relative_table);
255                                                   249 
256         i = 0;                                    250         i = 0;
257         while (i < image_size) {                  251         while (i < image_size) {
258                 uint32_t *loc = (uint32_t *)(e    252                 uint32_t *loc = (uint32_t *)(extab_image + i);
259                                                   253 
260                 w(r(loc) - i, loc);               254                 w(r(loc) - i, loc);
261                 w(r(loc + 1) - (i + 4), loc +     255                 w(r(loc + 1) - (i + 4), loc + 1);
262                 /* Don't touch the fixup type     256                 /* Don't touch the fixup type or data */
263                                                   257 
264                 i += sizeof(uint32_t) * 3;        258                 i += sizeof(uint32_t) * 3;
265         }                                         259         }
266 }                                                 260 }
267                                                   261 
                                                   >> 262 static void x86_sort_relative_table(char *extab_image, int image_size)
                                                   >> 263 {
                                                   >> 264         int i = 0;
                                                   >> 265 
                                                   >> 266         while (i < image_size) {
                                                   >> 267                 uint32_t *loc = (uint32_t *)(extab_image + i);
                                                   >> 268 
                                                   >> 269                 w(r(loc) + i, loc);
                                                   >> 270                 w(r(loc + 1) + i + 4, loc + 1);
                                                   >> 271                 /* Don't touch the fixup type */
                                                   >> 272 
                                                   >> 273                 i += sizeof(uint32_t) * 3;
                                                   >> 274         }
                                                   >> 275 
                                                   >> 276         qsort(extab_image, image_size / 12, 12, compare_relative_table);
                                                   >> 277 
                                                   >> 278         i = 0;
                                                   >> 279         while (i < image_size) {
                                                   >> 280                 uint32_t *loc = (uint32_t *)(extab_image + i);
                                                   >> 281 
                                                   >> 282                 w(r(loc) - i, loc);
                                                   >> 283                 w(r(loc + 1) - (i + 4), loc + 1);
                                                   >> 284                 /* Don't touch the fixup type */
                                                   >> 285 
                                                   >> 286                 i += sizeof(uint32_t) * 3;
                                                   >> 287         }
                                                   >> 288 }
                                                   >> 289 
                                                   >> 290 static void s390_sort_relative_table(char *extab_image, int image_size)
                                                   >> 291 {
                                                   >> 292         int i;
                                                   >> 293 
                                                   >> 294         for (i = 0; i < image_size; i += 16) {
                                                   >> 295                 char *loc = extab_image + i;
                                                   >> 296                 uint64_t handler;
                                                   >> 297 
                                                   >> 298                 w(r((uint32_t *)loc) + i, (uint32_t *)loc);
                                                   >> 299                 w(r((uint32_t *)(loc + 4)) + (i + 4), (uint32_t *)(loc + 4));
                                                   >> 300                 /*
                                                   >> 301                  * 0 is a special self-relative handler value, which means that
                                                   >> 302                  * handler should be ignored. It is safe, because it means that
                                                   >> 303                  * handler field points to itself, which should never happen.
                                                   >> 304                  * When creating extable-relative values, keep it as 0, since
                                                   >> 305                  * this should never occur either: it would mean that handler
                                                   >> 306                  * field points to the first extable entry.
                                                   >> 307                  */
                                                   >> 308                 handler = r8((uint64_t *)(loc + 8));
                                                   >> 309                 if (handler)
                                                   >> 310                         handler += i + 8;
                                                   >> 311                 w8(handler, (uint64_t *)(loc + 8));
                                                   >> 312         }
                                                   >> 313 
                                                   >> 314         qsort(extab_image, image_size / 16, 16, compare_relative_table);
                                                   >> 315 
                                                   >> 316         for (i = 0; i < image_size; i += 16) {
                                                   >> 317                 char *loc = extab_image + i;
                                                   >> 318                 uint64_t handler;
                                                   >> 319 
                                                   >> 320                 w(r((uint32_t *)loc) - i, (uint32_t *)loc);
                                                   >> 321                 w(r((uint32_t *)(loc + 4)) - (i + 4), (uint32_t *)(loc + 4));
                                                   >> 322                 handler = r8((uint64_t *)(loc + 8));
                                                   >> 323                 if (handler)
                                                   >> 324                         handler -= i + 8;
                                                   >> 325                 w8(handler, (uint64_t *)(loc + 8));
                                                   >> 326         }
                                                   >> 327 }
                                                   >> 328 
268 static int do_file(char const *const fname, vo    329 static int do_file(char const *const fname, void *addr)
269 {                                                 330 {
270         int rc = -1;                              331         int rc = -1;
271         Elf32_Ehdr *ehdr = addr;                  332         Elf32_Ehdr *ehdr = addr;
272         table_sort_t custom_sort = NULL;          333         table_sort_t custom_sort = NULL;
273                                                   334 
274         switch (ehdr->e_ident[EI_DATA]) {         335         switch (ehdr->e_ident[EI_DATA]) {
275         case ELFDATA2LSB:                         336         case ELFDATA2LSB:
276                 r       = rle;                    337                 r       = rle;
277                 r2      = r2le;                   338                 r2      = r2le;
278                 r8      = r8le;                   339                 r8      = r8le;
279                 w       = wle;                    340                 w       = wle;
280                 w2      = w2le;                   341                 w2      = w2le;
281                 w8      = w8le;                   342                 w8      = w8le;
282                 break;                            343                 break;
283         case ELFDATA2MSB:                         344         case ELFDATA2MSB:
284                 r       = rbe;                    345                 r       = rbe;
285                 r2      = r2be;                   346                 r2      = r2be;
286                 r8      = r8be;                   347                 r8      = r8be;
287                 w       = wbe;                    348                 w       = wbe;
288                 w2      = w2be;                   349                 w2      = w2be;
289                 w8      = w8be;                   350                 w8      = w8be;
290                 break;                            351                 break;
291         default:                                  352         default:
292                 fprintf(stderr, "unrecognized     353                 fprintf(stderr, "unrecognized ELF data encoding %d: %s\n",
293                         ehdr->e_ident[EI_DATA]    354                         ehdr->e_ident[EI_DATA], fname);
294                 return -1;                        355                 return -1;
295         }                                         356         }
296                                                   357 
297         if (memcmp(ELFMAG, ehdr->e_ident, SELF    358         if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0 ||
298             (r2(&ehdr->e_type) != ET_EXEC && r    359             (r2(&ehdr->e_type) != ET_EXEC && r2(&ehdr->e_type) != ET_DYN) ||
299             ehdr->e_ident[EI_VERSION] != EV_CU    360             ehdr->e_ident[EI_VERSION] != EV_CURRENT) {
300                 fprintf(stderr, "unrecognized     361                 fprintf(stderr, "unrecognized ET_EXEC/ET_DYN file %s\n", fname);
301                 return -1;                        362                 return -1;
302         }                                         363         }
303                                                   364 
304         switch (r2(&ehdr->e_machine)) {           365         switch (r2(&ehdr->e_machine)) {
305         case EM_386:                              366         case EM_386:
306         case EM_AARCH64:                       << 
307         case EM_LOONGARCH:                     << 
308         case EM_RISCV:                         << 
309         case EM_S390:                          << 
310         case EM_X86_64:                           367         case EM_X86_64:
311                 custom_sort = sort_relative_ta !! 368                 custom_sort = x86_sort_relative_table;
                                                   >> 369                 break;
                                                   >> 370         case EM_S390:
                                                   >> 371                 custom_sort = s390_sort_relative_table;
                                                   >> 372                 break;
                                                   >> 373         case EM_AARCH64:
                                                   >> 374                 custom_sort = arm64_sort_relative_table;
312                 break;                            375                 break;
313         case EM_PARISC:                           376         case EM_PARISC:
314         case EM_PPC:                              377         case EM_PPC:
315         case EM_PPC64:                            378         case EM_PPC64:
316                 custom_sort = sort_relative_ta    379                 custom_sort = sort_relative_table;
317                 break;                            380                 break;
318         case EM_ARCOMPACT:                        381         case EM_ARCOMPACT:
319         case EM_ARCV2:                            382         case EM_ARCV2:
320         case EM_ARM:                              383         case EM_ARM:
321         case EM_MICROBLAZE:                       384         case EM_MICROBLAZE:
322         case EM_MIPS:                             385         case EM_MIPS:
                                                   >> 386         case EM_RISCV:
323         case EM_XTENSA:                           387         case EM_XTENSA:
324                 break;                            388                 break;
325         default:                                  389         default:
326                 fprintf(stderr, "unrecognized     390                 fprintf(stderr, "unrecognized e_machine %d %s\n",
327                         r2(&ehdr->e_machine),     391                         r2(&ehdr->e_machine), fname);
328                 return -1;                        392                 return -1;
329         }                                         393         }
330                                                   394 
331         switch (ehdr->e_ident[EI_CLASS]) {        395         switch (ehdr->e_ident[EI_CLASS]) {
332         case ELFCLASS32:                          396         case ELFCLASS32:
333                 if (r2(&ehdr->e_ehsize) != siz    397                 if (r2(&ehdr->e_ehsize) != sizeof(Elf32_Ehdr) ||
334                     r2(&ehdr->e_shentsize) !=     398                     r2(&ehdr->e_shentsize) != sizeof(Elf32_Shdr)) {
335                         fprintf(stderr,           399                         fprintf(stderr,
336                                 "unrecognized     400                                 "unrecognized ET_EXEC/ET_DYN file: %s\n", fname);
337                         break;                    401                         break;
338                 }                                 402                 }
339                 rc = do_sort_32(ehdr, fname, c    403                 rc = do_sort_32(ehdr, fname, custom_sort);
340                 break;                            404                 break;
341         case ELFCLASS64:                          405         case ELFCLASS64:
342                 {                                 406                 {
343                 Elf64_Ehdr *const ghdr = (Elf6    407                 Elf64_Ehdr *const ghdr = (Elf64_Ehdr *)ehdr;
344                 if (r2(&ghdr->e_ehsize) != siz    408                 if (r2(&ghdr->e_ehsize) != sizeof(Elf64_Ehdr) ||
345                     r2(&ghdr->e_shentsize) !=     409                     r2(&ghdr->e_shentsize) != sizeof(Elf64_Shdr)) {
346                         fprintf(stderr,           410                         fprintf(stderr,
347                                 "unrecognized     411                                 "unrecognized ET_EXEC/ET_DYN file: %s\n",
348                                 fname);           412                                 fname);
349                         break;                    413                         break;
350                 }                                 414                 }
351                 rc = do_sort_64(ghdr, fname, c    415                 rc = do_sort_64(ghdr, fname, custom_sort);
352                 }                                 416                 }
353                 break;                            417                 break;
354         default:                                  418         default:
355                 fprintf(stderr, "unrecognized     419                 fprintf(stderr, "unrecognized ELF class %d %s\n",
356                         ehdr->e_ident[EI_CLASS    420                         ehdr->e_ident[EI_CLASS], fname);
357                 break;                            421                 break;
358         }                                         422         }
359                                                   423 
360         return rc;                                424         return rc;
361 }                                                 425 }
362                                                   426 
363 int main(int argc, char *argv[])                  427 int main(int argc, char *argv[])
364 {                                                 428 {
365         int i, n_error = 0;  /* gcc-4.3.0 fals    429         int i, n_error = 0;  /* gcc-4.3.0 false positive complaint */
366         size_t size = 0;                          430         size_t size = 0;
367         void *addr = NULL;                        431         void *addr = NULL;
368                                                   432 
369         if (argc < 2) {                           433         if (argc < 2) {
370                 fprintf(stderr, "usage: sortta    434                 fprintf(stderr, "usage: sorttable vmlinux...\n");
371                 return 0;                         435                 return 0;
372         }                                         436         }
373                                                   437 
374         /* Process each file in turn, allowing    438         /* Process each file in turn, allowing deep failure. */
375         for (i = 1; i < argc; i++) {              439         for (i = 1; i < argc; i++) {
376                 addr = mmap_file(argv[i], &siz    440                 addr = mmap_file(argv[i], &size);
377                 if (!addr) {                      441                 if (!addr) {
378                         ++n_error;                442                         ++n_error;
379                         continue;                 443                         continue;
380                 }                                 444                 }
381                                                   445 
382                 if (do_file(argv[i], addr))       446                 if (do_file(argv[i], addr))
383                         ++n_error;                447                         ++n_error;
384                                                   448 
385                 munmap(addr, size);               449                 munmap(addr, size);
386         }                                         450         }
387                                                   451 
388         return !!n_error;                         452         return !!n_error;
389 }                                                 453 }
390                                                   454 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php