/
usr
/
src
/
linux-headers-5.15.0-181
/
scripts
/
/usr/src/linux-headers-5.15.0-181/scripts
mkdir
upload
Name
Size
Mode
Actions
atomic/
-
0755
rm
basic/
-
0755
rm
clang-tools/
-
0755
rm
coccinelle/
-
0755
rm
dtc/
-
0755
rm
dummy-tools/
-
0755
rm
gcc-plugins/
-
0755
rm
gdb/
-
0755
rm
genksyms/
-
0755
rm
kconfig/
-
0755
rm
ksymoops/
-
0755
rm
mod/
-
0755
rm
package/
-
0755
rm
selinux/
-
0755
rm
tracing/
-
0755
rm
.gitignore
160
0644
edit
dl
rm
adjust_autoksyms.sh
2122
0755
edit
dl
rm
as-version.sh
2081
0755
edit
dl
rm
asn1_compiler.c
36180
0644
edit
dl
rm
bin2c.c
743
0644
edit
dl
rm
bloat-o-meter
3445
0755
edit
dl
rm
bootgraph.pl
5780
0755
edit
dl
rm
bpf_doc.py
25582
0755
edit
dl
rm
cc-can-link.sh
166
0755
edit
dl
rm
cc-version.sh
1549
0755
edit
dl
rm
check-sysctl-docs
4472
0755
edit
dl
rm
checkdeclares.pl
1123
0755
edit
dl
rm
checkincludes.pl
1988
0755
edit
dl
rm
checkkconfigsymbols.py
16126
0755
edit
dl
rm
checkpatch.pl
229128
0755
edit
dl
rm
checkstack.pl
6001
0755
edit
dl
rm
checksyscalls.sh
7600
0755
edit
dl
rm
checkversion.pl
2211
0755
edit
dl
rm
check_extable.sh
5048
0755
edit
dl
rm
cleanfile
3542
0755
edit
dl
rm
cleanpatch
5182
0755
edit
dl
rm
coccicheck
8075
0755
edit
dl
rm
config
4899
0755
edit
dl
rm
const_structs.checkpatch
1009
0644
edit
dl
rm
decodecode
2952
0755
edit
dl
rm
decode_stacktrace.sh
7691
0755
edit
dl
rm
depmod.sh
1441
0755
edit
dl
rm
dev-needs.sh
6219
0755
edit
dl
rm
diffconfig
4222
0755
edit
dl
rm
documentation-file-ref-check
5687
0755
edit
dl
rm
export_report.pl
4605
0755
edit
dl
rm
extract-cert.c
3720
0644
edit
dl
rm
extract-ikconfig
1734
0755
edit
dl
rm
extract-module-sig.pl
3746
0755
edit
dl
rm
extract-sys-certs.pl
3836
0755
edit
dl
rm
extract-vmlinux
1695
0755
edit
dl
rm
extract_xc3028.pl
45686
0755
edit
dl
rm
faddr2line
8364
0755
edit
dl
rm
file-size.sh
86
0755
edit
dl
rm
find-unused-docs.sh
1304
0755
edit
dl
rm
gcc-goto.sh
511
0755
edit
dl
rm
gcc-ld
711
0755
edit
dl
rm
gcc-x86_32-has-stack-protector.sh
405
0755
edit
dl
rm
gcc-x86_64-has-stack-protector.sh
195
0755
edit
dl
rm
generate_initcall_order.pl
6090
0755
edit
dl
rm
gen_autoksyms.sh
1509
0755
edit
dl
rm
gen_ksymdeps.sh
556
0755
edit
dl
rm
get_abi.pl
15463
0755
edit
dl
rm
get_dvb_firmware
25128
0755
edit
dl
rm
get_feat.pl
14689
0755
edit
dl
rm
get_maintainer.pl
68744
0755
edit
dl
rm
gfp-translate
1732
0755
edit
dl
rm
headerdep.pl
3587
0755
edit
dl
rm
headers_check.pl
3819
0755
edit
dl
rm
headers_install.sh
3431
0755
edit
dl
rm
insert-sys-cert.c
13392
0644
edit
dl
rm
jobserver-exec
2213
0755
edit
dl
rm
kallsyms.c
18498
0644
edit
dl
rm
Kbuild.include
10392
0644
edit
dl
rm
Kconfig.include
2635
0644
edit
dl
rm
kernel-doc
70388
0755
edit
dl
rm
ld-version.sh
1864
0755
edit
dl
rm
leaking_addresses.pl
13112
0755
edit
dl
rm
Lindent
502
0755
edit
dl
rm
link-vmlinux.sh
11181
0755
edit
dl
rm
Makefile
1681
0644
edit
dl
rm
Makefile.asm-generic
1864
0644
edit
dl
rm
Makefile.build
20135
0644
edit
dl
rm
Makefile.clang
1602
0644
edit
dl
rm
Makefile.clean
2254
0644
edit
dl
rm
Makefile.compiler
2806
0644
edit
dl
rm
Makefile.dtbinst
1007
0644
edit
dl
rm
Makefile.extrawarn
3092
0644
edit
dl
rm
Makefile.gcc-plugins
2778
0644
edit
dl
rm
Makefile.headersinst
2950
0644
edit
dl
rm
Makefile.host
4743
0644
edit
dl
rm
Makefile.kasan
1715
0644
edit
dl
rm
Makefile.kcov
333
0644
edit
dl
rm
Makefile.kcsan
739
0644
edit
dl
rm
Makefile.lib
18455
0644
edit
dl
rm
Makefile.modfinal
2793
0644
edit
dl
rm
Makefile.modinst
2581
0644
edit
dl
rm
Makefile.modpost
4478
0644
edit
dl
rm
Makefile.package
6771
0644
edit
dl
rm
Makefile.ubsan
770
0644
edit
dl
rm
Makefile.userprogs
1607
0644
edit
dl
rm
makelst
808
0755
edit
dl
rm
markup_oops.pl
8110
0755
edit
dl
rm
min-tool-version.sh
558
0755
edit
dl
rm
mkcompile_h
2541
0755
edit
dl
rm
mksysmap
1369
0755
edit
dl
rm
mkuboot.sh
414
0755
edit
dl
rm
module.lds.S
1691
0644
edit
dl
rm
modules-check.sh
427
0755
edit
dl
rm
nsdeps
1765
0644
edit
dl
rm
objdiff
2905
0755
edit
dl
rm
pahole-flags.sh
749
0755
edit
dl
rm
pahole-version.sh
269
0755
edit
dl
rm
parse-maintainers.pl
4646
0755
edit
dl
rm
patch-kernel
10185
0755
edit
dl
rm
profile2linkerlist.pl
414
0755
edit
dl
rm
prune-kernel
708
0755
edit
dl
rm
recordmcount.c
17152
0644
edit
dl
rm
recordmcount.h
19832
0644
edit
dl
rm
recordmcount.pl
18049
0755
edit
dl
rm
remove-stale-files
1336
0755
edit
dl
rm
setlocalversion
3580
0755
edit
dl
rm
show_delta
3087
0755
edit
dl
rm
sign-file.c
10172
0644
edit
dl
rm
sorttable.c
8949
0644
edit
dl
rm
sorttable.h
10063
0644
edit
dl
rm
spdxcheck-test.sh
277
0644
edit
dl
rm
spdxcheck.py
10334
0755
edit
dl
rm
spelling.txt
32646
0644
edit
dl
rm
sphinx-pre-install
25035
0755
edit
dl
rm
split-man.pl
604
0755
edit
dl
rm
stackdelta
1887
0755
edit
dl
rm
stackusage
794
0755
edit
dl
rm
subarch.include
619
0644
edit
dl
rm
syscallhdr.sh
1935
0755
edit
dl
rm
syscallnr.sh
1485
0755
edit
dl
rm
syscalltbl.sh
1489
0755
edit
dl
rm
tags.sh
10110
0755
edit
dl
rm
tools-support-relr.sh
546
0755
edit
dl
rm
ubuntu-retpoline-extract-one
7434
0644
edit
dl
rm
unifdef.c
35637
0644
edit
dl
rm
ver_linux
2648
0755
edit
dl
rm
xen-hypercalls.sh
386
0755
edit
dl
rm
xz_wrap.sh
563
0755
edit
dl
rm
Edit:
/usr/src/linux-headers-5.15.0-181/scripts/sorttable.c
(8949B)
// SPDX-License-Identifier: GPL-2.0-only /* * sorttable.c: Sort the kernel's table * * Added ORC unwind tables sort support and other updates: * Copyright (C) 1999-2019 Alibaba Group Holding Limited. by: * Shile Zhang <shile.zhang@linux.alibaba.com> * * Copyright 2011 - 2012 Cavium, Inc. * * Based on code taken from recortmcount.c which is: * * Copyright 2009 John F. Reiser <jreiser@BitWagon.com>. All rights reserved. * * Restructured to fit Linux format, as well as other updates: * Copyright 2010 Steven Rostedt <srostedt@redhat.com>, Red Hat Inc. */ /* * Strategy: alter the vmlinux file in-place. */ #include <sys/types.h> #include <sys/mman.h> #include <sys/stat.h> #include <getopt.h> #include <elf.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <tools/be_byteshift.h> #include <tools/le_byteshift.h> #ifndef EM_ARCOMPACT #define EM_ARCOMPACT 93 #endif #ifndef EM_XTENSA #define EM_XTENSA 94 #endif #ifndef EM_AARCH64 #define EM_AARCH64 183 #endif #ifndef EM_MICROBLAZE #define EM_MICROBLAZE 189 #endif #ifndef EM_ARCV2 #define EM_ARCV2 195 #endif #ifndef EM_RISCV #define EM_RISCV 243 #endif static uint32_t (*r)(const uint32_t *); static uint16_t (*r2)(const uint16_t *); static uint64_t (*r8)(const uint64_t *); static void (*w)(uint32_t, uint32_t *); static void (*w2)(uint16_t, uint16_t *); static void (*w8)(uint64_t, uint64_t *); typedef void (*table_sort_t)(char *, int); /* * Get the whole file as a programming convenience in order to avoid * malloc+lseek+read+free of many pieces. If successful, then mmap * avoids copying unused pieces; else just read the whole file. * Open for both read and write. */ static void *mmap_file(char const *fname, size_t *size) { int fd; struct stat sb; void *addr = NULL; fd = open(fname, O_RDWR); if (fd < 0) { perror(fname); return NULL; } if (fstat(fd, &sb) < 0) { perror(fname); goto out; } if (!S_ISREG(sb.st_mode)) { fprintf(stderr, "not a regular file: %s\n", fname); goto out; } addr = mmap(0, sb.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { fprintf(stderr, "Could not mmap file: %s\n", fname); goto out; } *size = sb.st_size; out: close(fd); return addr; } static uint32_t rbe(const uint32_t *x) { return get_unaligned_be32(x); } static uint16_t r2be(const uint16_t *x) { return get_unaligned_be16(x); } static uint64_t r8be(const uint64_t *x) { return get_unaligned_be64(x); } static uint32_t rle(const uint32_t *x) { return get_unaligned_le32(x); } static uint16_t r2le(const uint16_t *x) { return get_unaligned_le16(x); } static uint64_t r8le(const uint64_t *x) { return get_unaligned_le64(x); } static void wbe(uint32_t val, uint32_t *x) { put_unaligned_be32(val, x); } static void w2be(uint16_t val, uint16_t *x) { put_unaligned_be16(val, x); } static void w8be(uint64_t val, uint64_t *x) { put_unaligned_be64(val, x); } static void wle(uint32_t val, uint32_t *x) { put_unaligned_le32(val, x); } static void w2le(uint16_t val, uint16_t *x) { put_unaligned_le16(val, x); } static void w8le(uint64_t val, uint64_t *x) { put_unaligned_le64(val, x); } /* * Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of * the way to -256..-1, to avoid conflicting with real section * indices. */ #define SPECIAL(i) ((i) - (SHN_HIRESERVE + 1)) static inline int is_shndx_special(unsigned int i) { return i != SHN_XINDEX && i >= SHN_LORESERVE && i <= SHN_HIRESERVE; } /* Accessor for sym->st_shndx, hides ugliness of "64k sections" */ static inline unsigned int get_secindex(unsigned int shndx, unsigned int sym_offs, const Elf32_Word *symtab_shndx_start) { if (is_shndx_special(shndx)) return SPECIAL(shndx); if (shndx != SHN_XINDEX) return shndx; return r(&symtab_shndx_start[sym_offs]); } /* 32 bit and 64 bit are very similar */ #include "sorttable.h" #define SORTTABLE_64 #include "sorttable.h" static int compare_relative_table(const void *a, const void *b) { int32_t av = (int32_t)r(a); int32_t bv = (int32_t)r(b); if (av < bv) return -1; if (av > bv) return 1; return 0; } static void sort_relative_table(char *extab_image, int image_size) { int i = 0; /* * Do the same thing the runtime sort does, first normalize to * being relative to the start of the section. */ while (i < image_size) { uint32_t *loc = (uint32_t *)(extab_image + i); w(r(loc) + i, loc); i += 4; } qsort(extab_image, image_size / 8, 8, compare_relative_table); /* Now denormalize. */ i = 0; while (i < image_size) { uint32_t *loc = (uint32_t *)(extab_image + i); w(r(loc) - i, loc); i += 4; } } static void x86_sort_relative_table(char *extab_image, int image_size) { int i = 0; while (i < image_size) { uint32_t *loc = (uint32_t *)(extab_image + i); w(r(loc) + i, loc); w(r(loc + 1) + i + 4, loc + 1); /* Don't touch the fixup type */ i += sizeof(uint32_t) * 3; } qsort(extab_image, image_size / 12, 12, compare_relative_table); i = 0; while (i < image_size) { uint32_t *loc = (uint32_t *)(extab_image + i); w(r(loc) - i, loc); w(r(loc + 1) - (i + 4), loc + 1); /* Don't touch the fixup type */ i += sizeof(uint32_t) * 3; } } static void s390_sort_relative_table(char *extab_image, int image_size) { int i; for (i = 0; i < image_size; i += 16) { char *loc = extab_image + i; uint64_t handler; w(r((uint32_t *)loc) + i, (uint32_t *)loc); w(r((uint32_t *)(loc + 4)) + (i + 4), (uint32_t *)(loc + 4)); /* * 0 is a special self-relative handler value, which means that * handler should be ignored. It is safe, because it means that * handler field points to itself, which should never happen. * When creating extable-relative values, keep it as 0, since * this should never occur either: it would mean that handler * field points to the first extable entry. */ handler = r8((uint64_t *)(loc + 8)); if (handler) handler += i + 8; w8(handler, (uint64_t *)(loc + 8)); } qsort(extab_image, image_size / 16, 16, compare_relative_table); for (i = 0; i < image_size; i += 16) { char *loc = extab_image + i; uint64_t handler; w(r((uint32_t *)loc) - i, (uint32_t *)loc); w(r((uint32_t *)(loc + 4)) - (i + 4), (uint32_t *)(loc + 4)); handler = r8((uint64_t *)(loc + 8)); if (handler) handler -= i + 8; w8(handler, (uint64_t *)(loc + 8)); } } static int do_file(char const *const fname, void *addr) { int rc = -1; Elf32_Ehdr *ehdr = addr; table_sort_t custom_sort = NULL; switch (ehdr->e_ident[EI_DATA]) { case ELFDATA2LSB: r = rle; r2 = r2le; r8 = r8le; w = wle; w2 = w2le; w8 = w8le; break; case ELFDATA2MSB: r = rbe; r2 = r2be; r8 = r8be; w = wbe; w2 = w2be; w8 = w8be; break; default: fprintf(stderr, "unrecognized ELF data encoding %d: %s\n", ehdr->e_ident[EI_DATA], fname); return -1; } if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0 || (r2(&ehdr->e_type) != ET_EXEC && r2(&ehdr->e_type) != ET_DYN) || ehdr->e_ident[EI_VERSION] != EV_CURRENT) { fprintf(stderr, "unrecognized ET_EXEC/ET_DYN file %s\n", fname); return -1; } switch (r2(&ehdr->e_machine)) { case EM_386: case EM_X86_64: custom_sort = x86_sort_relative_table; break; case EM_S390: custom_sort = s390_sort_relative_table; break; case EM_AARCH64: case EM_PARISC: case EM_PPC: case EM_PPC64: custom_sort = sort_relative_table; break; case EM_ARCOMPACT: case EM_ARCV2: case EM_ARM: case EM_MICROBLAZE: case EM_MIPS: case EM_RISCV: case EM_XTENSA: break; default: fprintf(stderr, "unrecognized e_machine %d %s\n", r2(&ehdr->e_machine), fname); return -1; } switch (ehdr->e_ident[EI_CLASS]) { case ELFCLASS32: if (r2(&ehdr->e_ehsize) != sizeof(Elf32_Ehdr) || r2(&ehdr->e_shentsize) != sizeof(Elf32_Shdr)) { fprintf(stderr, "unrecognized ET_EXEC/ET_DYN file: %s\n", fname); break; } rc = do_sort_32(ehdr, fname, custom_sort); break; case ELFCLASS64: { Elf64_Ehdr *const ghdr = (Elf64_Ehdr *)ehdr; if (r2(&ghdr->e_ehsize) != sizeof(Elf64_Ehdr) || r2(&ghdr->e_shentsize) != sizeof(Elf64_Shdr)) { fprintf(stderr, "unrecognized ET_EXEC/ET_DYN file: %s\n", fname); break; } rc = do_sort_64(ghdr, fname, custom_sort); } break; default: fprintf(stderr, "unrecognized ELF class %d %s\n", ehdr->e_ident[EI_CLASS], fname); break; } return rc; } int main(int argc, char *argv[]) { int i, n_error = 0; /* gcc-4.3.0 false positive complaint */ size_t size = 0; void *addr = NULL; if (argc < 2) { fprintf(stderr, "usage: sorttable vmlinux...\n"); return 0; } /* Process each file in turn, allowing deep failure. */ for (i = 1; i < argc; i++) { addr = mmap_file(argv[i], &size); if (!addr) { ++n_error; continue; } if (do_file(argv[i], addr)) ++n_error; munmap(addr, size); } return !!n_error; }
Save
cmd:
run