[PATCH] D60555: [llvm-objcopy] Fill .symtab_shndx section correctly

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 12 05:34:24 PDT 2019


jhenderson added a comment.

In D60555#1464071 <https://reviews.llvm.org/D60555#1464071>, @evgeny777 wrote:

> > Looks to me like you've hit a bug here
>
> Are you sure it's a bug? According to sources it looks like some extension to original readelf output:
>
>   // Find if:
>   // Processor specific
>   if (SectionIndex >= ELF::SHN_LOPROC && SectionIndex <= ELF::SHN_HIPROC)
>     return std::string("PRC[0x") +
>            to_string(format_hex_no_prefix(SectionIndex, 4)) + "]";
>   // OS specific
>   if (SectionIndex >= ELF::SHN_LOOS && SectionIndex <= ELF::SHN_HIOS)
>     return std::string("OS[0x") +
>            to_string(format_hex_no_prefix(SectionIndex, 4)) + "]";
>   // Architecture reserved:
>   if (SectionIndex >= ELF::SHN_LORESERVE &&
>       SectionIndex <= ELF::SHN_HIRESERVE)
>     return std::string("RSV[0x") +
>            to_string(format_hex_no_prefix(SectionIndex, 4)) + "]";
>   
>   
>
> Anyway I'll switch to llvm-readobj in the test


Yes, it's a bug. Where the original st_shndx field is between SHN_LORESERVE and SHN_HIRESERVE (and not SHN_XINDEX), it should be decorated in this way. In all other cases it shouldn't be. It's a little complicated to explain in detail, but I'll do my best. If we look at the section header table, there are sections with index 0xff00, 0xff01, etc. Thus when we generally refer to sections with index 0xff00 etc we are talking about those sections. The symbol st_shndx field (i.e. the field indicating the symbol's section) however is only 16 bits, and the upper few values are reserved for various purposes. The SHN_XINDEX value (0xffff) in this context means look up the section index in the SHT_SYMTAB_SHNDX section instead. Other values in this range have other meanings (e.g. absolute and common symbols). If the real section index for the symbol's section is >= SHN_LORESERVE, it is impossible to represent it in directly in st_shndx, so it will be SHN_XINDEX.

llvm-readelf should print the real section index in the section index column, or a special interpretation where the value in the st_shndx field is a reserved value, such as SHN_ABS. The code in llvm-readelf should only do that special interpretation for the raw st_shndx field value, not the interpreted value (i.e. the value after lookups in SHT_SYMTAB_SHNDX) which I think is what it is doing (though I haven't looked in depth at the code yet to be 100% sure).


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60555/new/

https://reviews.llvm.org/D60555





More information about the llvm-commits mailing list