[PATCH] D111181: [llvm-objcopy][ELF] Don't assume RELA sections are dynamic if they carry the SHF_ALLOC flag
Ard Biesheuvel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 7 03:07:13 PDT 2021
ardb added a comment.
In D111181#3047405 <https://reviews.llvm.org/D111181#3047405>, @jhenderson wrote:
> In D111181#3047360 <https://reviews.llvm.org/D111181#3047360>, @ardb wrote:
>
>> In D111181#3047338 <https://reviews.llvm.org/D111181#3047338>, @jhenderson wrote:
>>
>>> A simpler approach than inspecting the dynamic table might be to inspect the type of the sh_link-ed section: SHT_SYMTAB implies a static relocation section, and SHT_DYNSYM a dynamic one. There is a small corner case this approach doesn't cover, namely relocation sections with sh_link=0, but in that case, falling back to another heuristic like SHF_ALLOC or parsing the dynamic section may be sufficient.
>>
>> In that case, does it even matter? If there is no symtab to begin with, there is no risk of misidentifying a static one as a dynamic one, righr?
>
> Not sure if you're referring to the symtab here or the relocation section. At the moment, I believe there are three cases that are handled (I might be wrong though - I'm going off memory, as I don't have time to dig into the code):
>
> 1. Relocation sections with sh_link = 0. In this case, don't attempt to look for a symbol table.
> 2. Static relocation sections should have a sh_link pointing to a static symbol table.
> 3. Dynamic relocation sections should have a sh_link pointing to a dynamic symbol table.
>
> In the latter two cases, we can reverse the logic and say that the symbol table kind (dynamic or static) identifies the relocation section kind. However, in the former case, we don't know by looking at sh_link whether the symbol table is static or dynamic. sh_link = 0 is fine for some relocation sections: they need to have all relocation have an r_sym of 0, i.e. be relocation types that aren't relative to a symbol. We do need to still distinguish betewen whether the relocation seciton is static or dynamic, as the llvm-objcopy code for the two is different.
OK that answers my question. I wasn't sure whether the RELA sections themselves need to be treated any differently but apparently they do.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D111181/new/
https://reviews.llvm.org/D111181
More information about the llvm-commits
mailing list