[lld] r248226 - Rename Chunks.(h|cpp) to InputSection.(h|cpp). NFC.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 21 17:01:40 PDT 2015
Author: rafael
Date: Mon Sep 21 19:01:39 2015
New Revision: 248226
URL: http://llvm.org/viewvc/llvm-project?rev=248226&view=rev
Log:
Rename Chunks.(h|cpp) to InputSection.(h|cpp). NFC.
Added:
lld/trunk/ELF/InputSection.cpp
- copied, changed from r248225, lld/trunk/ELF/Chunks.cpp
lld/trunk/ELF/InputSection.h
- copied, changed from r248225, lld/trunk/ELF/Chunks.h
Removed:
lld/trunk/ELF/Chunks.cpp
lld/trunk/ELF/Chunks.h
Modified:
lld/trunk/ELF/CMakeLists.txt
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputFiles.h
lld/trunk/ELF/Symbols.cpp
lld/trunk/ELF/Symbols.h
Modified: lld/trunk/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/CMakeLists.txt?rev=248226&r1=248225&r2=248226&view=diff
==============================================================================
--- lld/trunk/ELF/CMakeLists.txt (original)
+++ lld/trunk/ELF/CMakeLists.txt Mon Sep 21 19:01:39 2015
@@ -3,11 +3,11 @@ tablegen(LLVM Options.inc -gen-opt-parse
add_public_tablegen_target(ELFOptionsTableGen)
add_llvm_library(lldELF2
- Chunks.cpp
Driver.cpp
DriverUtils.cpp
Error.cpp
InputFiles.cpp
+ InputSection.cpp
OutputSections.cpp
SymbolTable.cpp
Symbols.cpp
Removed: lld/trunk/ELF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Chunks.cpp?rev=248225&view=auto
==============================================================================
--- lld/trunk/ELF/Chunks.cpp (original)
+++ lld/trunk/ELF/Chunks.cpp (removed)
@@ -1,171 +0,0 @@
-//===- Chunks.cpp ---------------------------------------------------------===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "Chunks.h"
-#include "Error.h"
-#include "InputFiles.h"
-#include "OutputSections.h"
-
-#include "llvm/Support/raw_ostream.h"
-
-using namespace llvm;
-using namespace llvm::ELF;
-using namespace llvm::object;
-
-using namespace lld;
-using namespace lld::elf2;
-
-template <class ELFT>
-InputSection<ELFT>::InputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header)
- : File(F), Header(Header) {}
-
-template <class ELFT>
-void InputSection<ELFT>::relocateOne(uint8_t *Buf, const Elf_Rel &Rel,
- uint32_t Type, uintX_t BaseAddr,
- uintX_t SymVA) {
- uintX_t Offset = Rel.r_offset;
- uint8_t *Location = Buf + Offset;
- switch (Type) {
- case R_386_32:
- support::endian::write32le(Location, SymVA);
- break;
- default:
- llvm::errs() << Twine("unrecognized reloc ") + Twine(Type) << '\n';
- break;
- }
-}
-
-template <class ELFT>
-void InputSection<ELFT>::relocateOne(uint8_t *Buf, const Elf_Rela &Rel,
- uint32_t Type, uintX_t BaseAddr,
- uintX_t SymVA) {
- uintX_t Offset = Rel.r_offset;
- uint8_t *Location = Buf + Offset;
- switch (Type) {
- case R_X86_64_PC32:
- support::endian::write32le(Location,
- SymVA + (Rel.r_addend - (BaseAddr + Offset)));
- break;
- case R_X86_64_64:
- support::endian::write64le(Location, SymVA + Rel.r_addend);
- break;
- case R_X86_64_32: {
- case R_X86_64_32S:
- uint64_t VA = SymVA + Rel.r_addend;
- if (Type == R_X86_64_32 && !isUInt<32>(VA))
- error("R_X86_64_32 out of range");
- else if (!isInt<32>(VA))
- error("R_X86_64_32S out of range");
-
- support::endian::write32le(Location, VA);
- break;
- }
- default:
- llvm::errs() << Twine("unrecognized reloc ") + Twine(Type) << '\n';
- break;
- }
-}
-
-template <class ELFT>
-template <bool isRela>
-void InputSection<ELFT>::relocate(
- uint8_t *Buf, iterator_range<const Elf_Rel_Impl<ELFT, isRela> *> Rels,
- const ObjectFile<ELFT> &File, uintX_t BaseAddr,
- const PltSection<ELFT> &PltSec, const GotSection<ELFT> &GotSec) {
- typedef Elf_Rel_Impl<ELFT, isRela> RelType;
- bool IsMips64EL = File.getObj()->isMips64EL();
- for (const RelType &RI : Rels) {
- uint32_t SymIndex = RI.getSymbol(IsMips64EL);
- uint32_t Type = RI.getType(IsMips64EL);
- uintX_t SymVA;
-
- // Handle relocations for local symbols -- they never get
- // resolved so we don't allocate a SymbolBody.
- const Elf_Shdr *SymTab = File.getSymbolTable();
- if (SymIndex < SymTab->sh_info) {
- const Elf_Sym *Sym = File.getObj()->getRelocationSymbol(&RI, SymTab);
- if (!Sym)
- continue;
- SymVA = getLocalSymVA(Sym, File);
- } else {
- const SymbolBody *Body = File.getSymbolBody(SymIndex);
- if (!Body)
- continue;
- switch (Body->kind()) {
- case SymbolBody::DefinedRegularKind:
- SymVA = getSymVA<ELFT>(cast<DefinedRegular<ELFT>>(Body));
- break;
- case SymbolBody::DefinedAbsoluteKind:
- SymVA = cast<DefinedAbsolute<ELFT>>(Body)->Sym.st_value;
- break;
- case SymbolBody::DefinedCommonKind: {
- auto *DC = cast<DefinedCommon<ELFT>>(Body);
- SymVA = DC->OutputSec->getVA() + DC->OffsetInBSS;
- break;
- }
- case SymbolBody::SharedKind:
- if (relocNeedsPLT(Type)) {
- SymVA = PltSec.getEntryAddr(*Body);
- Type = R_X86_64_PC32;
- } else if (relocNeedsGOT(Type)) {
- SymVA = GotSec.getEntryAddr(*Body);
- Type = R_X86_64_PC32;
- } else {
- continue;
- }
- break;
- case SymbolBody::UndefinedKind:
- assert(Body->isWeak() && "Undefined symbol reached writer");
- SymVA = 0;
- break;
- case SymbolBody::LazyKind:
- llvm_unreachable("Lazy symbol reached writer");
- }
- }
-
- relocateOne(Buf, RI, Type, BaseAddr, SymVA);
- }
-}
-
-template <class ELFT>
-void InputSection<ELFT>::writeTo(uint8_t *Buf, const PltSection<ELFT> &PltSec,
- const GotSection<ELFT> &GotSec) {
- if (Header->sh_type == SHT_NOBITS)
- return;
- // Copy section contents from source object file to output file.
- ArrayRef<uint8_t> Data = *File->getObj()->getSectionContents(Header);
- memcpy(Buf + OutputSectionOff, Data.data(), Data.size());
-
- const ObjectFile<ELFT> *File = getFile();
- ELFFile<ELFT> *EObj = File->getObj();
- uint8_t *Base = Buf + getOutputSectionOff();
- uintX_t BaseAddr = Out->getVA() + getOutputSectionOff();
- // Iterate over all relocation sections that apply to this section.
- for (const Elf_Shdr *RelSec : RelocSections) {
- if (RelSec->sh_type == SHT_RELA)
- relocate(Base, EObj->relas(RelSec), *File, BaseAddr, PltSec, GotSec);
- else
- relocate(Base, EObj->rels(RelSec), *File, BaseAddr, PltSec, GotSec);
- }
-}
-
-template <class ELFT> StringRef InputSection<ELFT>::getSectionName() const {
- ErrorOr<StringRef> Name = File->getObj()->getSectionName(Header);
- error(Name);
- return *Name;
-}
-
-namespace lld {
-namespace elf2 {
-template class InputSection<object::ELF32LE>;
-template class InputSection<object::ELF32BE>;
-template class InputSection<object::ELF64LE>;
-template class InputSection<object::ELF64BE>;
-}
-}
Removed: lld/trunk/ELF/Chunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Chunks.h?rev=248225&view=auto
==============================================================================
--- lld/trunk/ELF/Chunks.h (original)
+++ lld/trunk/ELF/Chunks.h (removed)
@@ -1,90 +0,0 @@
-//===- Chunks.h -------------------------------------------------*- C++ -*-===//
-//
-// The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_ELF_CHUNKS_H
-#define LLD_ELF_CHUNKS_H
-
-#include "lld/Core/LLVM.h"
-#include "llvm/Object/ELF.h"
-
-namespace lld {
-namespace elf2 {
-
-template <class ELFT> class ObjectFile;
-template <class ELFT> class OutputSection;
-template <class ELFT> class PltSection;
-template <class ELFT> class GotSection;
-
-// A chunk corresponding a section of an input file.
-template <class ELFT> class InputSection {
- typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
- typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela;
- typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel;
- typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
- typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
-
-public:
- InputSection(ObjectFile<ELFT> *F, const Elf_Shdr *Header);
-
- // Returns the size of this chunk (even if this is a common or BSS.)
- size_t getSize() const { return Header->sh_size; }
-
- // Write this chunk to a mmap'ed file, assuming Buf is pointing to
- // beginning of the output section.
- void writeTo(uint8_t *Buf, const PltSection<ELFT> &PltSec,
- const GotSection<ELFT> &GotSec);
-
- StringRef getSectionName() const;
- const Elf_Shdr *getSectionHdr() const { return Header; }
- const ObjectFile<ELFT> *getFile() const { return File; }
-
- // The writer sets and uses the addresses.
- uintX_t getOutputSectionOff() const { return OutputSectionOff; }
- uintX_t getAlign() {
- // The ELF spec states that a value of 0 means the section has no alignment
- // constraits.
- return std::max<uintX_t>(Header->sh_addralign, 1);
- }
- void setOutputSectionOff(uint64_t V) { OutputSectionOff = V; }
-
- void setOutputSection(OutputSection<ELFT> *O) { Out = O; }
- OutputSection<ELFT> *getOutputSection() const { return Out; }
-
- // Relocation sections that refer to this one.
- SmallVector<const Elf_Shdr *, 1> RelocSections;
-
-private:
- void relocateOne(uint8_t *Buf, const Elf_Rela &Rel, uint32_t Type,
- uintX_t BaseAddr, uintX_t SymVA);
- void relocateOne(uint8_t *Buf, const Elf_Rel &Rel, uint32_t Type,
- uintX_t BaseAddr, uintX_t SymVA);
-
- template <bool isRela>
- void relocate(uint8_t *Buf,
- llvm::iterator_range<
- const llvm::object::Elf_Rel_Impl<ELFT, isRela> *> Rels,
- const ObjectFile<ELFT> &File, uintX_t BaseAddr,
- const PltSection<ELFT> &PltSec, const GotSection<ELFT> &GotSec);
-
- // The offset from beginning of the output sections this chunk was assigned
- // to. The writer sets a value.
- uint64_t OutputSectionOff = 0;
-
- // The file this chunk was created from.
- ObjectFile<ELFT> *File;
-
- OutputSection<ELFT> *Out = nullptr;
-
- const Elf_Shdr *Header;
-};
-
-} // namespace elf2
-} // namespace lld
-
-#endif
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=248226&r1=248225&r2=248226&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Mon Sep 21 19:01:39 2015
@@ -8,7 +8,7 @@
//===----------------------------------------------------------------------===//
#include "InputFiles.h"
-#include "Chunks.h"
+#include "InputSection.h"
#include "Error.h"
#include "Symbols.h"
#include "llvm/ADT/STLExtras.h"
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=248226&r1=248225&r2=248226&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Mon Sep 21 19:01:39 2015
@@ -10,7 +10,7 @@
#ifndef LLD_ELF_INPUT_FILES_H
#define LLD_ELF_INPUT_FILES_H
-#include "Chunks.h"
+#include "InputSection.h"
#include "Error.h"
#include "Symbols.h"
Copied: lld/trunk/ELF/InputSection.cpp (from r248225, lld/trunk/ELF/Chunks.cpp)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?p2=lld/trunk/ELF/InputSection.cpp&p1=lld/trunk/ELF/Chunks.cpp&r1=248225&r2=248226&rev=248226&view=diff
==============================================================================
--- lld/trunk/ELF/Chunks.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Mon Sep 21 19:01:39 2015
@@ -1,4 +1,4 @@
-//===- Chunks.cpp ---------------------------------------------------------===//
+//===- InputSection.cpp ---------------------------------------------------===//
//
// The LLVM Linker
//
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
-#include "Chunks.h"
+#include "InputSection.h"
#include "Error.h"
#include "InputFiles.h"
#include "OutputSections.h"
Copied: lld/trunk/ELF/InputSection.h (from r248225, lld/trunk/ELF/Chunks.h)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?p2=lld/trunk/ELF/InputSection.h&p1=lld/trunk/ELF/Chunks.h&r1=248225&r2=248226&rev=248226&view=diff
==============================================================================
--- lld/trunk/ELF/Chunks.h (original)
+++ lld/trunk/ELF/InputSection.h Mon Sep 21 19:01:39 2015
@@ -1,4 +1,4 @@
-//===- Chunks.h -------------------------------------------------*- C++ -*-===//
+//===- InputSection.h -------------------------------------------*- C++ -*-===//
//
// The LLVM Linker
//
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLD_ELF_CHUNKS_H
-#define LLD_ELF_CHUNKS_H
+#ifndef LLD_ELF_INPUT_SECTION_H
+#define LLD_ELF_INPUT_SECTION_H
#include "lld/Core/LLVM.h"
#include "llvm/Object/ELF.h"
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=248226&r1=248225&r2=248226&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Mon Sep 21 19:01:39 2015
@@ -8,7 +8,7 @@
//===----------------------------------------------------------------------===//
#include "Symbols.h"
-#include "Chunks.h"
+#include "InputSection.h"
#include "Error.h"
#include "InputFiles.h"
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=248226&r1=248225&r2=248226&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Mon Sep 21 19:01:39 2015
@@ -10,7 +10,7 @@
#ifndef LLD_ELF_SYMBOLS_H
#define LLD_ELF_SYMBOLS_H
-#include "Chunks.h"
+#include "InputSection.h"
#include "lld/Core/LLVM.h"
#include "llvm/Object/Archive.h"
More information about the llvm-commits
mailing list