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