[llvm-commits] Patch to add a convenience function in ELF.h

Michael Spencer bigcheesegs at gmail.com
Wed Nov 7 10:49:43 PST 2012


On Wed, Nov 7, 2012 at 10:20 AM, Shankar Easwaran
<shankare at codeaurora.org> wrote:
> Hi Mike, Eric,
>
> Attached is the diff with the appropriate changes as per comments.
>
> Ok to commit ?
>
> Thanks
>
> Shankar Easwaran


+
+  bool operator ==(const Elf_Sym_Impl<target_endianness, is64Bits>
&rhs) const {
+    if ((this->st_name == rhs.st_name) &&
+        (this->st_info == rhs.st_info) &&
+        (this->st_other == rhs.st_other) &&
+        (this->st_shndx == rhs.st_shndx) &&
+        (this->st_value == rhs.st_value) &&
+        (this->st_size == rhs.st_size))
+      return true;	
+    return false;
+  }

This is no longer needed.

With that removed you can commit it.

>
> On 11/5/2012 9:28 AM, Shankar Easwaran wrote:
>>
>> Hi,
>>
>> Nice!, I will change it to the version thats mentioned below.
>>
>> Thanks Mike for the nice approach.
>>
>> Shankar Easwaran
>>
>> On 11/2/2012 6:09 PM, Michael Spencer wrote:
>>>
>>> On Thu, Nov 1, 2012 at 7:26 AM, Shankar Easwaran
>>> <shankare at codeaurora.org> wrote:
>>>>
>>>> Hi,
>>>>
>>>> This is a patch to add a convenience function in ELF.h to add support
>>>> for
>>>> getting to the symbol table index given a Elf_Sym.
>>>>
>>>> Thanks
>>>>
>>>> Shankar Easwaran
>>>>
>>>> --
>>>> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
>>>> hosted by
>>>> the Linux Foundation
>>>>
>>> There's no need to use a loop to get the index.
>>>
>>> @@ -604,6 +604,10 @@ public:
>>>     error_code      getSymbolName(const Elf_Shdr *section,
>>>                                   const Elf_Sym *Symb,
>>>                                   StringRef &Res) const;
>>> +
>>> +  /// \brief Get the symbol table index for the given symbol.
>>> +  uint64_t        getSymbolIndex(const Elf_Sym *Symb) const;
>>> +
>>>     error_code      getSectionName(const Elf_Shdr *section,
>>>                                    StringRef &Res) const;
>>>     const Elf_Dyn  *getDyn(DataRefImpl DynData) const;
>>> @@ -2490,6 +2494,20 @@ error_code ELFObjectFile<target_endianness,
>>> is64Bits>
>>>   }
>>>
>>>   template<support::endianness target_endianness, bool is64Bits>
>>> +uint64_t ELFObjectFile<target_endianness, is64Bits>
>>> +                      ::getSymbolIndex(const Elf_Sym *Sym) const {
>>> +  assert(SymbolTableSections.size() == 1 && "Only one symbol table
>>> supported!");
>>> +  const Elf_Shdr *SymTab = *SymbolTableSections.begin();
>>> +  uintptr_t SymLoc = uintptr_t(Sym);
>>> +  uintptr_t SymTabLoc = uintptr_t(base() + SymTab->sh_offset);
>>> +  assert(SymLoc > SymTabLoc && "Symbol not in symbol table!");
>>> +  uint64_t SymOffset = SymLoc - SymTabLoc;
>>> +  assert(SymOffset % SymTab->sh_entsize == 0 &&
>>> +         "Symbol not multiple of symbol size!");
>>> +  return SymOffset / SymTab->sh_entsize;
>>> +}
>>> +
>>> +template<support::endianness target_endianness, bool is64Bits>
>>>   error_code ELFObjectFile<target_endianness, is64Bits>
>>>                           ::getSectionName(const Elf_Shdr *section,
>>>                                           StringRef &Result) const {
>>>
>>>
>>> - Michael Spencer
>>>
>>
>>
>
>
> --
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by
> the Linux Foundation
>



More information about the llvm-commits mailing list