hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2021, The Linux Foundation. All rights reserved.
 * Copyright (c) 2023 Rockchip Electronics Co., Ltd.
 */
 
#ifndef __ROCKCHIP_ELF_COMMON_H
#define __ROCKCHIP_ELF_COMMON_H
 
#include <linux/elf.h>
 
/* Generic helpers for ELF use */
/* Return first section header */
static inline struct elf_shdr *elf_sheader(struct elfhdr *hdr)
{
   return (struct elf_shdr *)((size_t)hdr + (size_t)hdr->e_shoff);
}
 
/* Return idx section header */
static inline struct elf_shdr *elf_section(struct elfhdr *hdr, int idx)
{
   return &elf_sheader(hdr)[idx];
}
 
/* Return first program header */
static inline struct elf_phdr *elf_pheader(struct elfhdr *hdr)
{
   return (struct elf_phdr *)((size_t)hdr + (size_t)hdr->e_phoff);
}
 
/* Return idx program header */
static inline struct elf_phdr *elf_program(struct elfhdr *hdr, int idx)
{
   return &elf_pheader(hdr)[idx];
}
 
/* Return section's string table header */
static inline char *elf_str_table(struct elfhdr *hdr)
{
   if (hdr->e_shstrndx == SHN_UNDEF)
       return NULL;
   return (char *)hdr + elf_section(hdr, hdr->e_shstrndx)->sh_offset;
}
 
#endif