<div dir="ltr"><div>Reviewed-by: Marek Olšák <<a href="mailto:marek.olsak@amd.com">marek.olsak@amd.com</a>></div><div><br></div><div>Marek<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 17, 2019 at 2:47 PM Haehnle, Nicolai <<a href="mailto:Nicolai.Haehnle@amd.com">Nicolai.Haehnle@amd.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The following hunk needs to be added:<br>
<br>
> @@ -503,7 +521,9 @@ static bool resolve_symbol(const struct ac_rtld_upload_info *u,<br>
>                            unsigned part_idx, const Elf64_Sym *sym,<br>
>                            const char *name, uint64_t *value)<br>
>  {<br>
> -       if (sym->st_shndx == SHN_UNDEF) {<br>
> +       /* TODO: properly disentangle the undef and the LDS cases once<br>
> +        * STT_AMDGPU_LDS is retired. */<br>
> +       if (sym->st_shndx == SHN_UNDEF || sym->st_shndx == SHN_AMDGPU_LDS) {<br>
>                 const struct ac_rtld_symbol *lds_sym =<br>
>                         find_symbol(&u->binary->lds_symbols, name, part_idx);<br>
>  <br>
<br>
Cheers,<br>
Nicolai<br>
<br>
On 17.06.19 01:34, Nicolai Hähnle wrote:<br>
> From: Nicolai Hähnle <<a href="mailto:nicolai.haehnle@amd.com" target="_blank">nicolai.haehnle@amd.com</a>><br>
> <br>
> The initial prototype used a processor-specific symbol type, but<br>
> feedback suggests that an approach using processor-specific section<br>
> name that encodes the alignment analogous to SHN_COMMON symbols is<br>
> preferred.<br>
> <br>
> This patch keeps both variants around for now to reduce problems<br>
> with LLVM compatibility as we switch branches around.<br>
> <br>
> This also cleans up the error reporting in this function.<br>
> ---<br>
>   src/amd/common/ac_rtld.c | 30 ++++++++++++++++++++++++------<br>
>   1 file changed, 24 insertions(+), 6 deletions(-)<br>
> <br>
> diff --git a/src/amd/common/ac_rtld.c b/src/amd/common/ac_rtld.c<br>
> index dc9cc04705b..6379e55120d 100644<br>
> --- a/src/amd/common/ac_rtld.c<br>
> +++ b/src/amd/common/ac_rtld.c<br>
> @@ -32,21 +32,25 @@<br>
>   <br>
>   #include "ac_binary.h"<br>
>   #include "ac_gpu_info.h"<br>
>   #include "util/u_dynarray.h"<br>
>   #include "util/u_math.h"<br>
>   <br>
>   // Old distributions may not have this enum constant<br>
>   #define MY_EM_AMDGPU 224<br>
>   <br>
>   #ifndef STT_AMDGPU_LDS<br>
> -#define STT_AMDGPU_LDS 13<br>
> +#define STT_AMDGPU_LDS 13 // this is deprecated -- remove<br>
> +#endif<br>
> +<br>
> +#ifndef SHN_AMDGPU_LDS<br>
> +#define SHN_AMDGPU_LDS 0xff00<br>
>   #endif<br>
>   <br>
>   #ifndef R_AMDGPU_NONE<br>
>   #define R_AMDGPU_NONE 0<br>
>   #define R_AMDGPU_ABS32_LO 1<br>
>   #define R_AMDGPU_ABS32_HI 2<br>
>   #define R_AMDGPU_ABS64 3<br>
>   #define R_AMDGPU_REL32 4<br>
>   #define R_AMDGPU_REL64 5<br>
>   #define R_AMDGPU_ABS32 6<br>
> @@ -169,47 +173,60 @@ static bool layout_symbols(struct ac_rtld_symbol *symbols, unsigned num_symbols,<br>
>    * Read LDS symbols from the given \p section of the ELF of \p part and append<br>
>    * them to the LDS symbols list.<br>
>    *<br>
>    * Shared LDS symbols are filtered out.<br>
>    */<br>
>   static bool read_private_lds_symbols(struct ac_rtld_binary *binary,<br>
>                                    unsigned part_idx,<br>
>                                    Elf_Scn *section,<br>
>                                    uint32_t *lds_end_align)<br>
>   {<br>
> -#define report_elf_if(cond) \<br>
> +#define report_if(cond) \<br>
>       do { \<br>
>               if ((cond)) { \<br>
>                       report_errorf(#cond); \<br>
>                       return false; \<br>
>               } \<br>
>       } while (false)<br>
> +#define report_elf_if(cond) \<br>
> +     do { \<br>
> +             if ((cond)) { \<br>
> +                     report_elf_errorf(#cond); \<br>
> +                     return false; \<br>
> +             } \<br>
> +     } while (false)<br>
>   <br>
>       struct ac_rtld_part *part = &binary->parts[part_idx];<br>
>       Elf64_Shdr *shdr = elf64_getshdr(section);<br>
>       uint32_t strtabidx = shdr->sh_link;<br>
>       Elf_Data *symbols_data = elf_getdata(section, NULL);<br>
>       report_elf_if(!symbols_data);<br>
>   <br>
>       const Elf64_Sym *symbol = symbols_data->d_buf;<br>
>       size_t num_symbols = symbols_data->d_size / sizeof(Elf64_Sym);<br>
>   <br>
>       for (size_t j = 0; j < num_symbols; ++j, ++symbol) {<br>
> -             if (ELF64_ST_TYPE(symbol->st_info) != STT_AMDGPU_LDS)<br>
> +             struct ac_rtld_symbol s = {};<br>
> +<br>
> +             if (ELF64_ST_TYPE(symbol->st_info) == STT_AMDGPU_LDS) {<br>
> +                     /* old-style LDS symbols from initial prototype -- remove eventually */<br>
> +                     s.align = MIN2(1u << (symbol->st_other >> 3), 1u << 16);<br>
> +             } else if (symbol->st_shndx == SHN_AMDGPU_LDS) {<br>
> +                     s.align = MIN2(symbol->st_value, 1u << 16);<br>
> +                     report_if(!util_is_power_of_two_nonzero(s.align));<br>
> +             } else<br>
>                       continue;<br>
>   <br>
> -             report_elf_if(symbol->st_size > 1u << 29);<br>
> +             report_if(symbol->st_size > 1u << 29);<br>
>   <br>
> -             struct ac_rtld_symbol s = {};<br>
>               <a href="http://s.name" rel="noreferrer" target="_blank">s.name</a> = elf_strptr(part->elf, strtabidx, symbol->st_name);<br>
>               s.size = symbol->st_size;<br>
> -             s.align = MIN2(1u << (symbol->st_other >> 3), 1u << 16);<br>
>               s.part_idx = part_idx;<br>
>   <br>
>               if (!strcmp(<a href="http://s.name" rel="noreferrer" target="_blank">s.name</a>, "__lds_end")) {<br>
>                       report_elf_if(s.size != 0);<br>
>                       *lds_end_align = MAX2(*lds_end_align, s.align);<br>
>                       continue;<br>
>               }<br>
>   <br>
>               const struct ac_rtld_symbol *shared =<br>
>                       find_symbol(&binary->lds_symbols, <a href="http://s.name" rel="noreferrer" target="_blank">s.name</a>, part_idx);<br>
> @@ -217,20 +234,21 @@ static bool read_private_lds_symbols(struct ac_rtld_binary *binary,<br>
>                       report_elf_if(s.align > shared->align);<br>
>                       report_elf_if(s.size > shared->size);<br>
>                       continue;<br>
>               }<br>
>   <br>
>               util_dynarray_append(&binary->lds_symbols, struct ac_rtld_symbol, s);<br>
>       }<br>
>   <br>
>       return true;<br>
>   <br>
> +#undef report_if<br>
>   #undef report_elf_if<br>
>   }<br>
>   <br>
>   /**<br>
>    * Open a binary consisting of one or more shader parts.<br>
>    *<br>
>    * \param binary the uninitialized struct<br>
>    * \param i binary opening parameters<br>
>    */<br>
>   bool ac_rtld_open(struct ac_rtld_binary *binary,<br>
> <br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a></blockquote></div>