[lld] r301833 - Add comments about how we handle mergeable sections with relocations.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon May 1 14:11:39 PDT 2017
Thanks!
Rui Ueyama via llvm-commits <llvm-commits at lists.llvm.org> writes:
> Author: ruiu
> Date: Mon May 1 15:49:09 2017
> New Revision: 301833
>
> URL: http://llvm.org/viewvc/llvm-project?rev=301833&view=rev
> Log:
> Add comments about how we handle mergeable sections with relocations.
>
> Also factored out code.
>
> Modified:
> lld/trunk/ELF/InputFiles.cpp
>
> Modified: lld/trunk/ELF/InputFiles.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=301833&r1=301832&r2=301833&view=diff
> ==============================================================================
> --- lld/trunk/ELF/InputFiles.cpp (original)
> +++ lld/trunk/ELF/InputFiles.cpp Mon May 1 15:49:09 2017
> @@ -361,6 +361,15 @@ InputSectionBase *elf::ObjectFile<ELFT>:
> return Target;
> }
>
> +// Create a regular InputSection class that has the same contents
> +// as a given section.
> +InputSectionBase *toRegularSection(MergeInputSection *Sec) {
> + auto *Ret = make<InputSection>(Sec->Flags, Sec->Type, Sec->Alignment,
> + Sec->Data, Sec->Name);
> + Ret->File = Sec->File;
> + return Ret;
> +}
> +
> template <class ELFT>
> InputSectionBase *
> elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec,
> @@ -398,12 +407,15 @@ elf::ObjectFile<ELFT>::createInputSectio
> if (Target->FirstRelocation)
> fatal(toString(this) +
> ": multiple relocation sections to one section are not supported");
> - if (isa<MergeInputSection>(Target)) {
> - this->Sections[Sec.sh_info] =
> - make<InputSection>(Target->Flags, Target->Type, Target->Alignment,
> - Target->Data, Target->Name);
> - this->Sections[Sec.sh_info]->File = Target->File;
> - Target = this->Sections[Sec.sh_info];
> +
> + // Mergeable sections with relocations are tricky because relocations
> + // need to be taken into account when comparing section contents for
> + // merging. The MergeInputSection class currently doesn't care about
> + // relocations, and it's unlikely to support it in future because such
> + // sections are rare. We simply handle such sections as non-mergeable.
> + if (auto *MS = dyn_cast<MergeInputSection>(Target)) {
> + Target = toRegularSection(MS);
> + this->Sections[Sec.sh_info] = Target;
> }
>
> size_t NumRelocations;
>
>
> _______________________________________________
> 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