1 /* SPDX-License-Identifier: GPL-2.0-only */
6 #include "elfparsing.h"
11 /* Determine if relocation is a valid type for the architecture. */
12 int (*valid_type
)(Elf64_Rela
*rel
);
13 /* Determine if relocation should be emitted. */
14 int (*should_emit
)(Elf64_Rela
*rel
);
18 * The fields in rmod_context are read-only to the user. These are
19 * exposed for easy shareability.
22 /* Ops to process relocations. */
23 const struct arch_ops
*ops
;
25 /* endian conversion ops */
28 /* Parsed ELF structure. */
29 struct parsed_elf pelf
;
30 /* Program segment. */
32 /* Number of loadable segments. */
34 /* Symbol string table. */
37 /* Collection of relocation addresses fixup in the module. */
39 Elf64_Addr
*emitted_relocs
;
41 /* The following fields are addresses within the linked program. */
42 Elf64_Addr parameters_begin
;
43 Elf64_Addr parameters_end
;
49 /* Return < 0 on error. 0 to ignore relocation and 1 to include
51 int (*filter
)(struct reloc_filter
*f
, const Elf64_Rela
*r
);
52 /* Pointer for filter provides */
57 * Parse an ELF file within the elfin buffer and fill in the elfout buffer
58 * with a created rmodule in ELF format. Return 0 on success, < 0 on error.
60 int rmodule_create(const struct buffer
*elfin
, struct buffer
*elfout
);
63 * Initialize an rmodule context from an ELF buffer. Returns 0 on scucess, < 0
66 int rmodule_init(struct rmod_context
*ctx
, const struct buffer
*elfin
);
69 * Collect all the relocations that apply to the program in
70 * nrelocs/emitted_relocs. One can optionally provide a reloc_filter object
71 * to help in relocation filtering. The filter function will be called twice:
72 * once for counting and once for emitting. The same response should be
73 * provided for each call. Returns 0 on success, < 0 on error.
75 int rmodule_collect_relocations(struct rmod_context
*c
, struct reloc_filter
*f
);
77 /* Clean up the memory consumed by the rmodule context. */
78 void rmodule_cleanup(struct rmod_context
*ctx
);
81 * Create an ELF file from the passed in rmodule in the buffer. The buffer
82 * contents will be replaced with an ELF file. Returns 1 if buff doesn't
83 * contain an rmodule and < 0 on failure, 0 on success.
85 int rmodule_stage_to_elf(Elf64_Ehdr
*ehdr
, struct buffer
*buff
);
87 #endif /* TOOL_RMODULE_H */