[lld] r256993 - Define align() and use that instead of RoundUpToAlignment().
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 13 14:38:44 PST 2016
On Wed, Jan 6, 2016 at 3:25 PM, Rui Ueyama via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: ruiu
> Date: Wed Jan 6 17:25:42 2016
> New Revision: 256993
>
> URL: http://llvm.org/viewvc/llvm-project?rev=256993&view=rev
> Log:
> Define align() and use that instead of RoundUpToAlignment().
>
> The name "RoundUpToAlignment" is too long compared to what it does.
>
Should we remove/replace RoundUpToAlignment, then? Rather than introducing
another name for the same thing? (if I'm reading this patch correctly)
>
> Modified:
> lld/trunk/ELF/OutputSections.cpp
> lld/trunk/ELF/OutputSections.h
> lld/trunk/ELF/Writer.cpp
>
> Modified: lld/trunk/ELF/OutputSections.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=256993&r1=256992&r2=256993&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/OutputSections.cpp (original)
> +++ lld/trunk/ELF/OutputSections.cpp Wed Jan 6 17:25:42 2016
> @@ -770,7 +770,7 @@ void OutputSection<ELFT>::addSection(Inp
> this->Header.sh_addralign = Align;
>
> uintX_t Off = this->Header.sh_size;
> - Off = RoundUpToAlignment(Off, Align);
> + Off = align(Off, Align);
> S->OutSecOff = Off;
> Off += S->getSize();
> this->Header.sh_size = Off;
> @@ -971,7 +971,7 @@ void EHOutputSection<ELFT>::addSectionAu
> auto P = CieMap.insert(std::make_pair(CieInfo, Cies.size()));
> if (P.second) {
> Cies.push_back(C);
> - this->Header.sh_size += RoundUpToAlignment(Length,
> sizeof(uintX_t));
> + this->Header.sh_size += align(Length, sizeof(uintX_t));
> }
> OffsetToIndex[Offset] = P.first->second;
> } else {
> @@ -984,7 +984,7 @@ void EHOutputSection<ELFT>::addSectionAu
> if (I == OffsetToIndex.end())
> error("Invalid CIE reference");
> Cies[I->second].Fdes.push_back(EHRegion<ELFT>(S, Index));
> - this->Header.sh_size += RoundUpToAlignment(Length,
> sizeof(uintX_t));
> + this->Header.sh_size += align(Length, sizeof(uintX_t));
> }
> }
>
> @@ -1037,7 +1037,7 @@ static typename ELFFile<ELFT>::uintX_t w
> uint8_t *Buf)
> {
> typedef typename ELFFile<ELFT>::uintX_t uintX_t;
> const endianness E = ELFT::TargetEndianness;
> - uint64_t Len = RoundUpToAlignment(Data.size(), sizeof(uintX_t));
> + uint64_t Len = align(Data.size(), sizeof(uintX_t));
> write32<E>(Buf, Len - 4);
> memcpy(Buf + 4, Data.data() + 4, Data.size() - 4);
> return Len;
>
> Modified: lld/trunk/ELF/OutputSections.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=256993&r1=256992&r2=256993&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/OutputSections.h (original)
> +++ lld/trunk/ELF/OutputSections.h Wed Jan 6 17:25:42 2016
> @@ -432,6 +432,10 @@ private:
> uint32_t GprMask = 0;
> };
>
> +inline uint64_t align(uint64_t Value, uint64_t Align) {
> + return (Value + Align - 1) & ~(Align - 1);
> +}
> +
> // All output sections that are hadnled by the linker specially are
> // globally accessible. Writer initializes them, so don't use them
> // until Writer is initialized.
>
> Modified: lld/trunk/ELF/Writer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=256993&r1=256992&r2=256993&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/Writer.cpp (original)
> +++ lld/trunk/ELF/Writer.cpp Wed Jan 6 17:25:42 2016
> @@ -491,7 +491,7 @@ void Writer<ELFT>::addCommonSymbols(std:
> uintX_t Off = getBss()->getSize();
> for (DefinedCommon *C : Syms) {
> uintX_t Align = C->MaxAlignment;
> - Off = RoundUpToAlignment(Off, Align);
> + Off = align(Off, Align);
> C->OffsetInBss = Off;
> Off += C->Size;
> }
> @@ -514,7 +514,7 @@ void Writer<ELFT>::addCopyRelSymbols(std
> countTrailingZeros((uintX_t)Sym.st_value));
> uintX_t Align = 1 << TrailingZeros;
> Out<ELFT>::Bss->updateAlign(Align);
> - Off = RoundUpToAlignment(Off, Align);
> + Off = align(Off, Align);
> C->OffsetInBss = Off;
> Off += Sym.st_size;
> }
> @@ -1024,8 +1024,8 @@ template <class ELFT> void Writer<ELFT>:
> bool InRelRo = Config->ZRelro && (Flags & PF_W) &&
> isRelroSection(Sec);
> bool FirstNonRelRo = GnuRelroPhdr.p_type && !InRelRo &&
> !RelroAligned;
> if (FirstNonRelRo || PH->p_flags != Flags) {
> - VA = RoundUpToAlignment(VA, Target->getPageSize());
> - FileOff = RoundUpToAlignment(FileOff, Target->getPageSize());
> + VA = align(VA, Target->getPageSize());
> + FileOff = align(FileOff, Target->getPageSize());
> if (FirstNonRelRo)
> RelroAligned = true;
> }
> @@ -1040,8 +1040,8 @@ template <class ELFT> void Writer<ELFT>:
> if (!TlsPhdr.p_vaddr)
> setPhdr(&TlsPhdr, PT_TLS, PF_R, FileOff, VA, 0,
> Sec->getAlign());
> if (Sec->getType() != SHT_NOBITS)
> - VA = RoundUpToAlignment(VA, Sec->getAlign());
> - uintX_t TVA = RoundUpToAlignment(VA + ThreadBssOffset,
> Sec->getAlign());
> + VA = align(VA, Sec->getAlign());
> + uintX_t TVA = align(VA + ThreadBssOffset, Sec->getAlign());
> Sec->setVA(TVA);
> TlsPhdr.p_memsz += Sec->getSize();
> if (Sec->getType() == SHT_NOBITS) {
> @@ -1052,7 +1052,7 @@ template <class ELFT> void Writer<ELFT>:
> }
> TlsPhdr.p_align = std::max<uintX_t>(TlsPhdr.p_align,
> Sec->getAlign());
> } else {
> - VA = RoundUpToAlignment(VA, Sec->getAlign());
> + VA = align(VA, Sec->getAlign());
> Sec->setVA(VA);
> VA += Sec->getSize();
> if (InRelRo)
> @@ -1060,7 +1060,7 @@ template <class ELFT> void Writer<ELFT>:
> }
> }
>
> - FileOff = RoundUpToAlignment(FileOff, Sec->getAlign());
> + FileOff = align(FileOff, Sec->getAlign());
> Sec->setFileOffset(FileOff);
> if (Sec->getType() != SHT_NOBITS)
> FileOff += Sec->getSize();
> @@ -1073,7 +1073,7 @@ template <class ELFT> void Writer<ELFT>:
> if (TlsPhdr.p_vaddr) {
> // The TLS pointer goes after PT_TLS. At least glibc will align it,
> // so round up the size to make sure the offsets are correct.
> - TlsPhdr.p_memsz = RoundUpToAlignment(TlsPhdr.p_memsz,
> TlsPhdr.p_align);
> + TlsPhdr.p_memsz = align(TlsPhdr.p_memsz, TlsPhdr.p_align);
> Phdrs[++PhdrIdx] = TlsPhdr;
> Out<ELFT>::TlsPhdr = &Phdrs[PhdrIdx];
> }
> @@ -1105,7 +1105,7 @@ template <class ELFT> void Writer<ELFT>:
> }
>
> // Add space for section headers.
> - SectionHeaderOff = RoundUpToAlignment(FileOff, ELFT::Is64Bits ? 8 : 4);
> + SectionHeaderOff = align(FileOff, ELFT::Is64Bits ? 8 : 4);
> FileSize = SectionHeaderOff + getNumSections() * sizeof(Elf_Shdr);
>
> // Update "_end" and "end" symbols so that they
>
>
> _______________________________________________
> 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/20160113/9cc4ab4f/attachment.html>
More information about the llvm-commits
mailing list