Skip to content

Commit 17bed33

Browse files
committed
scripts/sorttable: Add helper functions for Elf_Sym
In order to remove the double #include of sorttable.h for 64 and 32 bit to create duplicate functions, add helper functions for Elf_Sym. This will create a function pointer for each helper that will get assigned to the appropriate function to handle either the 64bit or 32bit version. This also removes the last references of etype and _r() macros from the sorttable.h file as their references are now just defined in the appropriate architecture version of the helper functions. All read functions now exist in the helper functions which makes it easier to maintain, as the helper functions define the necessary architecture sizes. Cc: bpf <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nicolas Schier <[email protected]> Cc: Zheng Yejian <[email protected]> Cc: Martin Kelly <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Josh Poimboeuf <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 67afb7f commit 17bed33

File tree

2 files changed

+63
-14
lines changed

2 files changed

+63
-14
lines changed

scripts/sorttable.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,53 @@ SHDR_WORD(link)
152152
SHDR_WORD(name)
153153
SHDR_WORD(type)
154154

155+
#define SYM_ADDR(fn_name) \
156+
static uint64_t sym64_##fn_name(Elf_Sym *sym) \
157+
{ \
158+
return r8(&sym->e64.st_##fn_name); \
159+
} \
160+
\
161+
static uint64_t sym32_##fn_name(Elf_Sym *sym) \
162+
{ \
163+
return r(&sym->e32.st_##fn_name); \
164+
}
165+
166+
#define SYM_WORD(fn_name) \
167+
static uint32_t sym64_##fn_name(Elf_Sym *sym) \
168+
{ \
169+
return r(&sym->e64.st_##fn_name); \
170+
} \
171+
\
172+
static uint32_t sym32_##fn_name(Elf_Sym *sym) \
173+
{ \
174+
return r(&sym->e32.st_##fn_name); \
175+
}
176+
177+
#define SYM_HALF(fn_name) \
178+
static uint16_t sym64_##fn_name(Elf_Sym *sym) \
179+
{ \
180+
return r2(&sym->e64.st_##fn_name); \
181+
} \
182+
\
183+
static uint16_t sym32_##fn_name(Elf_Sym *sym) \
184+
{ \
185+
return r2(&sym->e32.st_##fn_name); \
186+
}
187+
188+
static uint8_t sym64_type(Elf_Sym *sym)
189+
{
190+
return ELF64_ST_TYPE(sym->e64.st_info);
191+
}
192+
193+
static uint8_t sym32_type(Elf_Sym *sym)
194+
{
195+
return ELF32_ST_TYPE(sym->e32.st_info);
196+
}
197+
198+
SYM_ADDR(value)
199+
SYM_WORD(name)
200+
SYM_HALF(shndx)
201+
155202
/*
156203
* Get the whole file as a programming convenience in order to avoid
157204
* malloc+lseek+read+free of many pieces. If successful, then mmap

scripts/sorttable.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
#undef sort_mcount_loc
2424
#undef elf_mcount_loc
2525
#undef do_sort
26-
#undef ELF_ST_TYPE
2726
#undef uint_t
28-
#undef _r
29-
#undef etype
3027
#undef ehdr_shoff
3128
#undef ehdr_shentsize
3229
#undef ehdr_shstrndx
@@ -38,6 +35,10 @@
3835
#undef shdr_name
3936
#undef shdr_type
4037
#undef shdr_entsize
38+
#undef sym_type
39+
#undef sym_name
40+
#undef sym_value
41+
#undef sym_shndx
4142

4243
#ifdef SORTTABLE_64
4344
# define extable_ent_size 16
@@ -46,10 +47,7 @@
4647
# define sort_mcount_loc sort_mcount_loc_64
4748
# define elf_mcount_loc elf_mcount_loc_64
4849
# define do_sort do_sort_64
49-
# define ELF_ST_TYPE ELF64_ST_TYPE
5050
# define uint_t uint64_t
51-
# define _r r8
52-
# define etype e64
5351
# define ehdr_shoff ehdr64_shoff
5452
# define ehdr_shentsize ehdr64_shentsize
5553
# define ehdr_shstrndx ehdr64_shstrndx
@@ -61,17 +59,18 @@
6159
# define shdr_name shdr64_name
6260
# define shdr_type shdr64_type
6361
# define shdr_entsize shdr64_entsize
62+
# define sym_type sym64_type
63+
# define sym_name sym64_name
64+
# define sym_value sym64_value
65+
# define sym_shndx sym64_shndx
6466
#else
6567
# define extable_ent_size 8
6668
# define compare_extable compare_extable_32
6769
# define get_mcount_loc get_mcount_loc_32
6870
# define sort_mcount_loc sort_mcount_loc_32
6971
# define elf_mcount_loc elf_mcount_loc_32
7072
# define do_sort do_sort_32
71-
# define ELF_ST_TYPE ELF32_ST_TYPE
7273
# define uint_t uint32_t
73-
# define _r r
74-
# define etype e32
7574
# define ehdr_shoff ehdr32_shoff
7675
# define ehdr_shentsize ehdr32_shentsize
7776
# define ehdr_shstrndx ehdr32_shstrndx
@@ -83,6 +82,10 @@
8382
# define shdr_name shdr32_name
8483
# define shdr_type shdr32_type
8584
# define shdr_entsize shdr32_entsize
85+
# define sym_type sym32_type
86+
# define sym_name sym32_name
87+
# define sym_value sym32_value
88+
# define sym_shndx sym32_shndx
8689
#endif
8790

8891
#if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED)
@@ -414,9 +417,9 @@ static int do_sort(Elf_Ehdr *ehdr,
414417

415418
for (sym = sym_start; (void *)sym + symentsize < sym_end;
416419
sym = (void *)sym + symentsize) {
417-
if (ELF_ST_TYPE(sym->etype.st_info) != STT_OBJECT)
420+
if (sym_type(sym) != STT_OBJECT)
418421
continue;
419-
if (!strcmp(strtab + r(&sym->etype.st_name),
422+
if (!strcmp(strtab + sym_name(sym),
420423
"main_extable_sort_needed")) {
421424
sort_needed_sym = sym;
422425
break;
@@ -430,14 +433,13 @@ static int do_sort(Elf_Ehdr *ehdr,
430433
goto out;
431434
}
432435

433-
sort_need_index = get_secindex(r2(&sym->etype.st_shndx),
436+
sort_need_index = get_secindex(sym_shndx(sym),
434437
((void *)sort_needed_sym - (void *)symtab) / symentsize,
435438
symtab_shndx);
436439
sort_needed_sec = get_index(shdr_start, shentsize, sort_need_index);
437440
sort_needed_loc = (void *)ehdr +
438441
shdr_offset(sort_needed_sec) +
439-
_r(&sort_needed_sym->etype.st_value) -
440-
shdr_addr(sort_needed_sec);
442+
sym_value(sort_needed_sym) - shdr_addr(sort_needed_sec);
441443

442444
/* extable has been sorted, clear the flag */
443445
w(0, sort_needed_loc);

0 commit comments

Comments
 (0)