[lld] r246796 - Add a helper function for getting the first object file.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 3 12:13:14 PDT 2015
Author: rafael
Date: Thu Sep 3 14:13:13 2015
New Revision: 246796
URL: http://llvm.org/viewvc/llvm-project?rev=246796&view=rev
Log:
Add a helper function for getting the first object file.
Also preparation for shared objects. It will become the first ELF file.
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/SymbolTable.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=246796&r1=246795&r2=246796&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Sep 3 14:13:13 2015
@@ -98,7 +98,7 @@ void LinkerDriver::link(ArrayRef<const c
Symtab.reportRemainingUndefines();
// Write the result.
- ObjectFileBase &FirstObj = *Symtab.getObjectFiles()[0];
+ ObjectFileBase &FirstObj = *Symtab.getFirstObject();
switch (FirstObj.getELFKind()) {
case ELF32LEKind:
writeResult<object::ELF32LE>(&Symtab);
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=246796&r1=246795&r2=246796&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Thu Sep 3 14:13:13 2015
@@ -33,10 +33,9 @@ template <class ELFT> void SymbolTable::
}
void SymbolTable::addObject(ObjectFileBase *File) {
- if (!ObjectFiles.empty()) {
- ObjectFileBase &Old = *ObjectFiles[0];
- if (!Old.isCompatibleWith(*File))
- error(Twine(Old.getName() + " is incompatible with " + File->getName()));
+ if (const ObjectFileBase *Old = getFirstObject()) {
+ if (!Old->isCompatibleWith(*File))
+ error(Twine(Old->getName() + " is incompatible with " + File->getName()));
} else {
switch (File->getELFKind()) {
case ELF32LEKind:
Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=246796&r1=246795&r2=246796&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Thu Sep 3 14:13:13 2015
@@ -34,6 +34,12 @@ public:
void addFile(std::unique_ptr<InputFile> File);
+ ObjectFileBase *getFirstObject() const {
+ if (!ObjectFiles.empty())
+ return ObjectFiles[0].get();
+ return nullptr;
+ }
+
// Print an error message on undefined symbols.
void reportRemainingUndefines();
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=246796&r1=246795&r2=246796&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Sep 3 14:13:13 2015
@@ -543,7 +543,7 @@ template <class ELFT> void Writer<ELFT>:
EHdr->e_type = ET_EXEC;
const SymbolTable &Symtab = SymTable.getSymTable();
- auto &FirstObj = cast<ObjectFile<ELFT>>(*Symtab.getObjectFiles()[0]);
+ auto &FirstObj = cast<ObjectFile<ELFT>>(*Symtab.getFirstObject());
EHdr->e_machine = FirstObj.getObj()->getHeader()->e_machine;
EHdr->e_version = EV_CURRENT;
EHdr->e_entry = 0x401000;
More information about the llvm-commits
mailing list