Fix alignment computation for copy relocs.
Fixes PR25798.
Thanks to Ed Maste for the bug report and suggested fix.
llvm-svn: 255307
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index ceeca164..27553a3 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -501,9 +501,10 @@
const Elf_Sym &Sym = C->Sym;
const Elf_Shdr *Sec = C->File->getSection(Sym);
uintX_t SecAlign = Sec->sh_addralign;
- uintX_t Align = Sym.st_value % SecAlign;
- if (Align == 0)
- Align = SecAlign;
+ unsigned TrailingZeros =
+ std::min(countTrailingZeros(SecAlign),
+ countTrailingZeros((uintX_t)Sym.st_value));
+ uintX_t Align = 1 << TrailingZeros;
Out<ELFT>::Bss->updateAlign(Align);
Off = RoundUpToAlignment(Off, Align);
C->OffsetInBSS = Off;