[lld] r270527 - Remove Writer::ensureBss().
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Tue May 24 03:52:47 PDT 2016
Thanks!
On May 23, 2016 11:23 PM, "Rui Ueyama via llvm-commits" <
llvm-commits at lists.llvm.org> wrote:
> Author: ruiu
> Date: Mon May 23 22:16:51 2016
> New Revision: 270527
>
> URL: http://llvm.org/viewvc/llvm-project?rev=270527&view=rev
> Log:
> Remove Writer::ensureBss().
>
> Previously, we created a .bss section when needed. We had a function
> ensureBss() for that purpose. Turned out that was error-prone
> because it was easy to forget to call that function before accessing
> the .bss section.
>
> This patch always make the BSS section. The section is added to the
> output when it's not empty.
>
> Modified:
> lld/trunk/ELF/Writer.cpp
> lld/trunk/test/ELF/mips-got-and-copy.s
>
> Modified: lld/trunk/ELF/Writer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=270527&r1=270526&r2=270527&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/Writer.cpp (original)
> +++ lld/trunk/ELF/Writer.cpp Mon May 23 22:16:51 2016
> @@ -98,7 +98,6 @@ private:
> void scanRelocsForThunks(const elf::ObjectFile<ELFT> &File,
> ArrayRef<RelTy> Rels);
>
> - void ensureBss();
> void addCommonSymbols(std::vector<DefinedCommon *> &Syms);
> void addCopyRelSymbol(SharedSymbol<ELFT> *Sym);
>
> @@ -129,6 +128,7 @@ template <class ELFT> void elf::writeRes
> typedef typename ELFT::Ehdr Elf_Ehdr;
>
> // Create singleton output sections.
> + OutputSection<ELFT> Bss(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
> DynamicSection<ELFT> Dynamic(*Symtab);
> EhOutputSection<ELFT> EhFrame;
> GotSection<ELFT> Got;
> @@ -192,6 +192,7 @@ template <class ELFT> void elf::writeRes
> MipsRldMap->updateAlign(sizeof(uintX_t));
> }
>
> + Out<ELFT>::Bss = &Bss;
> Out<ELFT>::BuildId = BuildId.get();
> Out<ELFT>::DynStrTab = &DynStrTab;
> Out<ELFT>::DynSymTab = &DynSymTab;
> @@ -211,7 +212,6 @@ template <class ELFT> void elf::writeRes
> Out<ELFT>::SymTab = SymTabSec.get();
> Out<ELFT>::VerSym = &VerSym;
> Out<ELFT>::VerNeed = &VerNeed;
> - Out<ELFT>::Bss = nullptr;
> Out<ELFT>::MipsRldMap = MipsRldMap.get();
> Out<ELFT>::Opd = nullptr;
> Out<ELFT>::OpdBuf = nullptr;
> @@ -1006,17 +1006,6 @@ static bool compareSections(OutputSectio
> return false;
> }
>
> -// The .bss section does not exist if no input file has a .bss section.
> -// This function creates one if that's the case.
> -template <class ELFT> void Writer<ELFT>::ensureBss() {
> - if (Out<ELFT>::Bss)
> - return;
> - Out<ELFT>::Bss =
> - new OutputSection<ELFT>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
> - OwningSections.emplace_back(Out<ELFT>::Bss);
> - OutputSections.push_back(Out<ELFT>::Bss);
> -}
> -
> // Until this function is called, common symbols do not belong to any
> section.
> // This function adds them to end of BSS section.
> template <class ELFT>
> @@ -1030,7 +1019,6 @@ void Writer<ELFT>::addCommonSymbols(std:
> return A->Alignment > B->Alignment;
> });
>
> - ensureBss();
> uintX_t Off = Out<ELFT>::Bss->getSize();
> for (DefinedCommon *C : Syms) {
> Off = alignTo(Off, C->Alignment);
> @@ -1060,7 +1048,6 @@ void Writer<ELFT>::addCopyRelSymbol(Shar
> if (SymSize == 0)
> fatal("cannot create a copy relocation for " + SS->getName());
>
> - ensureBss();
> uintX_t Align = getAlignment(SS);
> uintX_t Off = alignTo(Out<ELFT>::Bss->getSize(), Align);
> Out<ELFT>::Bss->setSize(Off + SymSize);
> @@ -1330,9 +1317,6 @@ template <class ELFT> void Writer<ELFT>:
> }
> }
>
> - Out<ELFT>::Bss = static_cast<OutputSection<ELFT> *>(
> - Factory.lookup(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE));
> -
> // If we have a .opd section (used under PPC64 for function
> descriptors),
> // store a pointer to it here so that we can use it later when
> processing
> // relocations.
> @@ -1377,9 +1361,7 @@ template <class ELFT> void Writer<ELFT>:
>
> // Scan relocations. This must be done after every symbol is declared
> so that
> // we can correctly decide if a dynamic relocation is needed.
> - // Check size() each time to guard against .bss being created.
> - for (unsigned I = 0; I < OutputSections.size(); ++I) {
> - OutputSectionBase<ELFT> *Sec = OutputSections[I];
> + for (OutputSectionBase<ELFT> *Sec : OutputSections) {
> Sec->forEachInputSection([&](InputSectionBase<ELFT> *S) {
> if (auto *IS = dyn_cast<InputSection<ELFT>>(S)) {
> // Set OutSecOff so that scanRelocs can use it.
> @@ -1521,6 +1503,8 @@ template <class ELFT> void Writer<ELFT>:
> Add(Out<ELFT>::Plt);
> if (!Out<ELFT>::EhFrame->empty())
> Add(Out<ELFT>::EhFrameHdr);
> + if (Out<ELFT>::Bss->getSize() > 0)
> + Add(Out<ELFT>::Bss);
> }
>
> // The linker is expected to define SECNAME_start and SECNAME_end
>
> Modified: lld/trunk/test/ELF/mips-got-and-copy.s
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-got-and-copy.s?rev=270527&r1=270526&r2=270527&view=diff
>
> ==============================================================================
> --- lld/trunk/test/ELF/mips-got-and-copy.s (original)
> +++ lld/trunk/test/ELF/mips-got-and-copy.s Mon May 23 22:16:51 2016
> @@ -36,7 +36,7 @@
> # CHECK-NEXT: Initial: 0x40014
> # CHECK-NEXT: Value: 0x40014
> # CHECK-NEXT: Type: Object (0x1)
> -# CHECK-NEXT: Section: .bss (0xC)
> +# CHECK-NEXT: Section: .bss (0xD)
> # CHECK-NEXT: Name: data1@ (7)
> # CHECK-NEXT: }
> # CHECK-NEXT: ]
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160524/b9ed0d02/attachment.html>
More information about the llvm-commits
mailing list