Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -665,7 +665,8 @@ bool GotSection::empty() const { // If we have a relocation that is relative to GOT (such as GOTOFFREL), // we need to emit a GOT even if it's empty. - return NumEntries == 0 && !HasGotOffRel; + // Do the same if we have reference to _GLOBAL_OFFSET_TABLE_ symbol. + return NumEntries == 0 && !HasGotOffRel && !ElfSym::GlobalOffsetTable; } void GotSection::writeTo(uint8_t *Buf) { Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -1198,8 +1198,6 @@ OutputSection *OS = SS->getParent(); if (!SS->empty() || !OS) continue; - if ((SS == InX::Got || SS == InX::MipsGot) && ElfSym::GlobalOffsetTable) - continue; std::vector::iterator Empty = OS->Commands.end(); for (auto I = OS->Commands.begin(), E = OS->Commands.end(); I != E; ++I) {