2 * Copyright 2014-2019 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 #include "util/u_dynarray.h"
32 #include "compiler/shader_enums.h"
39 struct ac_shader_config
;
42 struct ac_rtld_symbol
{
46 uint64_t offset
; /* filled in by ac_rtld_open */
47 unsigned part_idx
; /* shader part in which this symbol appears */
50 struct ac_rtld_options
{
51 /* Loader will insert an s_sethalt 1 instruction as the
52 * first instruction. */
56 /* Lightweight wrapper around underlying ELF objects. */
57 struct ac_rtld_binary
{
58 struct ac_rtld_options options
;
61 /* Required buffer sizes, currently read/executable only. */
64 /* Size of executable code, for reporting purposes. */
67 uint64_t rx_end_markers
;
70 struct ac_rtld_part
*parts
;
72 struct util_dynarray lds_symbols
;
77 * Callback function type used during upload to resolve external symbols that
78 * are not defined in any of the ELF binaries available to the linker.
80 * \param cb_data caller-defined data
81 * \param symbol NUL-terminated symbol name
82 * \param value to be filled in by the callback
83 * \return whether the symbol was found successfully
85 typedef bool (*ac_rtld_get_external_symbol_cb
)(
86 void *cb_data
, const char *symbol
, uint64_t *value
);
89 * Lifetimes of \ref info, in-memory ELF objects, and the names of
90 * \ref shared_lds_symbols must extend until \ref ac_rtld_close is called on
93 struct ac_rtld_open_info
{
94 const struct radeon_info
*info
;
95 struct ac_rtld_options options
;
96 gl_shader_stage shader_type
;
100 const char * const *elf_ptrs
; /* in-memory ELF objects of each part */
101 const size_t *elf_sizes
; /* sizes of corresponding in-memory ELF objects in bytes */
103 /* Shared LDS symbols are layouted such that they are accessible from
104 * all shader parts. Non-shared (private) LDS symbols of one part may
105 * overlap private LDS symbols of another shader part.
107 unsigned num_shared_lds_symbols
;
108 const struct ac_rtld_symbol
*shared_lds_symbols
;
111 bool ac_rtld_open(struct ac_rtld_binary
*binary
,
112 struct ac_rtld_open_info i
);
114 void ac_rtld_close(struct ac_rtld_binary
*binary
);
116 bool ac_rtld_get_section_by_name(struct ac_rtld_binary
*binary
, const char *name
,
117 const char **data
, size_t *nbytes
);
119 bool ac_rtld_read_config(struct ac_rtld_binary
*binary
,
120 struct ac_shader_config
*config
);
122 struct ac_rtld_upload_info
{
123 struct ac_rtld_binary
*binary
;
125 /** GPU mapping of the read/executable buffer. */
128 /** CPU mapping of the read/executable buffer */
131 /** Optional callback function that will be queried for symbols not
132 * defined in any of the binary's parts. */
133 ac_rtld_get_external_symbol_cb get_external_symbol
;
135 /** Caller-defined data that will be passed to callback functions. */
139 bool ac_rtld_upload(struct ac_rtld_upload_info
*u
);
145 #endif /* AC_RTLD_H */