Skip to content

Commit 36b0f0d

Browse files
committed
modpost: refactor get_secindex()
SPECIAL() is only used in get_secindex(). Squash it. Make the code more readable with more comments. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent dd29865 commit 36b0f0d

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

scripts/mod/modpost.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,28 @@ static inline int is_shndx_special(unsigned int i)
156156
return i != SHN_XINDEX && i >= SHN_LORESERVE && i <= SHN_HIRESERVE;
157157
}
158158

159-
/*
160-
* Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of
161-
* the way to -256..-1, to avoid conflicting with real section
162-
* indices.
163-
*/
164-
#define SPECIAL(i) ((i) - (SHN_HIRESERVE + 1))
165-
166159
/* Accessor for sym->st_shndx, hides ugliness of "64k sections" */
167160
static inline unsigned int get_secindex(const struct elf_info *info,
168161
const Elf_Sym *sym)
169162
{
170-
if (is_shndx_special(sym->st_shndx))
171-
return SPECIAL(sym->st_shndx);
172-
if (sym->st_shndx != SHN_XINDEX)
173-
return sym->st_shndx;
174-
return info->symtab_shndx_start[sym - info->symtab_start];
163+
unsigned int index = sym->st_shndx;
164+
165+
/*
166+
* Elf{32,64}_Sym::st_shndx is 2 byte. Big section numbers are available
167+
* in the .symtab_shndx section.
168+
*/
169+
if (index == SHN_XINDEX)
170+
return info->symtab_shndx_start[sym - info->symtab_start];
171+
172+
/*
173+
* Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of
174+
* the way to UINT_MAX-255..UINT_MAX, to avoid conflicting with real
175+
* section indices.
176+
*/
177+
if (index >= SHN_LORESERVE && index <= SHN_HIRESERVE)
178+
return index - SHN_HIRESERVE - 1;
179+
180+
return index;
175181
}
176182

177183
/* file2alias.c */

0 commit comments

Comments
 (0)