ac/rtld: make ac_rtld_upload returns the code size

This will be useful to keep a copy of the uploaded code.

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9277>
This commit is contained in:
Pierre-Eric Pelloux-Prayer
2021-02-23 15:03:59 +01:00
committed by Marge Bot
parent e5b1e645e7
commit b2ef94943f
2 changed files with 11 additions and 7 deletions

View File

@@ -727,23 +727,24 @@ static bool apply_relocs(const struct ac_rtld_upload_info *u, unsigned part_idx,
* Upload the binary or binaries to the provided GPU buffers, including * Upload the binary or binaries to the provided GPU buffers, including
* relocations. * relocations.
*/ */
bool ac_rtld_upload(struct ac_rtld_upload_info *u) int ac_rtld_upload(struct ac_rtld_upload_info *u)
{ {
#define report_if(cond) \ #define report_if(cond) \
do { \ do { \
if ((cond)) { \ if ((cond)) { \
report_errorf(#cond); \ report_errorf(#cond); \
return false; \ return -1; \
} \ } \
} while (false) } while (false)
#define report_elf_if(cond) \ #define report_elf_if(cond) \
do { \ do { \
if ((cond)) { \ if ((cond)) { \
report_errorf(#cond); \ report_errorf(#cond); \
return false; \ return -1; \
} \ } \
} while (false) } while (false)
int size = 0;
if (u->binary->options.halt_at_entry) { if (u->binary->options.halt_at_entry) {
/* s_sethalt 1 */ /* s_sethalt 1 */
*(uint32_t *)u->rx_ptr = util_cpu_to_le32(0xbf8d0001); *(uint32_t *)u->rx_ptr = util_cpu_to_le32(0xbf8d0001);
@@ -766,6 +767,8 @@ bool ac_rtld_upload(struct ac_rtld_upload_info *u)
Elf_Data *data = elf_getdata(section, NULL); Elf_Data *data = elf_getdata(section, NULL);
report_elf_if(!data || data->d_size != shdr->sh_size); report_elf_if(!data || data->d_size != shdr->sh_size);
memcpy(u->rx_ptr + s->offset, data->d_buf, shdr->sh_size); memcpy(u->rx_ptr + s->offset, data->d_buf, shdr->sh_size);
size = MAX2(size, s->offset + shdr->sh_size);
} }
} }
@@ -773,6 +776,7 @@ bool ac_rtld_upload(struct ac_rtld_upload_info *u)
uint32_t *dst = (uint32_t *)(u->rx_ptr + u->binary->rx_end_markers); uint32_t *dst = (uint32_t *)(u->rx_ptr + u->binary->rx_end_markers);
for (unsigned i = 0; i < DEBUGGER_NUM_MARKERS; ++i) for (unsigned i = 0; i < DEBUGGER_NUM_MARKERS; ++i)
*dst++ = util_cpu_to_le32(DEBUGGER_END_OF_CODE_MARKER); *dst++ = util_cpu_to_le32(DEBUGGER_END_OF_CODE_MARKER);
size += 4 * DEBUGGER_NUM_MARKERS;
} }
/* Second pass: handle relocations, overwriting uploaded data where /* Second pass: handle relocations, overwriting uploaded data where
@@ -786,15 +790,15 @@ bool ac_rtld_upload(struct ac_rtld_upload_info *u)
Elf_Data *relocs = elf_getdata(section, NULL); Elf_Data *relocs = elf_getdata(section, NULL);
report_elf_if(!relocs || relocs->d_size != shdr->sh_size); report_elf_if(!relocs || relocs->d_size != shdr->sh_size);
if (!apply_relocs(u, i, shdr, relocs)) if (!apply_relocs(u, i, shdr, relocs))
return false; return -1;
} else if (shdr->sh_type == SHT_RELA) { } else if (shdr->sh_type == SHT_RELA) {
report_errorf("SHT_RELA not supported"); report_errorf("SHT_RELA not supported");
return false; return -1;
} }
} }
} }
return true; return size;
#undef report_if #undef report_if
#undef report_elf_if #undef report_elf_if

View File

@@ -134,7 +134,7 @@ struct ac_rtld_upload_info {
void *cb_data; void *cb_data;
}; };
bool ac_rtld_upload(struct ac_rtld_upload_info *u); int ac_rtld_upload(struct ac_rtld_upload_info *u);
#ifdef __cplusplus #ifdef __cplusplus
} }