[lld] r305048 - Simplify. NFC.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 9 17:39:25 PDT 2017
Thanks, that is a case where the template really helped.
Cheers,
Rafael
Rui Ueyama via llvm-commits <llvm-commits at lists.llvm.org> writes:
> Author: ruiu
> Date: Thu Jun 8 22:19:08 2017
> New Revision: 305048
>
> URL: http://llvm.org/viewvc/llvm-project?rev=305048&view=rev
> Log:
> Simplify. NFC.
>
> Modified:
> lld/trunk/ELF/InputSection.cpp
> lld/trunk/ELF/InputSection.h
>
> Modified: lld/trunk/ELF/InputSection.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=305048&r1=305047&r2=305048&view=diff
> ==============================================================================
> --- lld/trunk/ELF/InputSection.cpp (original)
> +++ lld/trunk/ELF/InputSection.cpp Thu Jun 8 22:19:08 2017
> @@ -309,23 +309,21 @@ OutputSection *InputSection::getParent()
> return cast_or_null<OutputSection>(Parent);
> }
>
> -void InputSection::copyShtGroup(uint8_t *Buf) {
> - assert(this->Type == SHT_GROUP);
> +// Copy SHT_GROUP section contents. Used only for the -r option.
> +template <class ELFT> void InputSection::copyShtGroup(uint8_t *Buf) {
> + // ELFT::Word is the 32-bit integral type in the target endianness.
> + typedef typename ELFT::Word u32;
> + ArrayRef<u32> From = getDataAs<u32>();
> + auto *To = reinterpret_cast<u32 *>(Buf);
>
> - ArrayRef<uint32_t> From = getDataAs<uint32_t>();
> - uint32_t *To = reinterpret_cast<uint32_t *>(Buf);
> -
> - // First entry is a flag word, we leave it unchanged.
> + // The first entry is not a section number but a flag.
> *To++ = From[0];
>
> - // Here we adjust indices of sections that belong to group as it
> - // might change during linking.
> + // Adjust section numbers because section numbers in an input object
> + // files are different in the output.
> ArrayRef<InputSectionBase *> Sections = this->File->getSections();
> - for (uint32_t Val : From.slice(1)) {
> - uint32_t Index = read32(&Val, Config->Endianness);
> - write32(To++, Sections[Index]->getOutputSection()->SectionIndex,
> - Config->Endianness);
> - }
> + for (uint32_t Idx : From.slice(1))
> + *To++ = Sections[Idx]->getOutputSection()->SectionIndex;
> }
>
> InputSectionBase *InputSection::getRelocatedSection() {
> @@ -713,10 +711,9 @@ template <class ELFT> void InputSection:
> return;
> }
>
> - // If -r is given, linker should keep SHT_GROUP sections. We should fixup
> - // them, see copyShtGroup().
> + // If -r is given, we may have a SHT_GROUP section.
> if (this->Type == SHT_GROUP) {
> - copyShtGroup(Buf + OutSecOff);
> + copyShtGroup<ELFT>(Buf + OutSecOff);
> return;
> }
>
>
> Modified: lld/trunk/ELF/InputSection.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=305048&r1=305047&r2=305048&view=diff
> ==============================================================================
> --- lld/trunk/ELF/InputSection.h (original)
> +++ lld/trunk/ELF/InputSection.h Thu Jun 8 22:19:08 2017
> @@ -325,7 +325,7 @@ private:
> template <class ELFT, class RelTy>
> void copyRelocations(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels);
>
> - void copyShtGroup(uint8_t *Buf);
> + template <class ELFT> void copyShtGroup(uint8_t *Buf);
> };
>
> // The list of all input sections.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list