[lld] r272724 - Don't include --start-lib/--end-lib files twice.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 14 14:56:37 PDT 2016
Author: rafael
Date: Tue Jun 14 16:56:36 2016
New Revision: 272724
URL: http://llvm.org/viewvc/llvm-project?rev=272724&view=rev
Log:
Don't include --start-lib/--end-lib files twice.
This should never happen with correct programs, but it is trivial
write a testcase where lld would crash or report duplicated
symbols. We now behave like when an archive is used and include the
file only once.
Added:
lld/trunk/test/ELF/Inputs/start-lib-comdat.s
lld/trunk/test/ELF/start-lib-comdat.s
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputFiles.h
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/SymbolTable.h
lld/trunk/ELF/Symbols.cpp
lld/trunk/ELF/Symbols.h
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=272724&r1=272723&r2=272724&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Tue Jun 14 16:56:36 2016
@@ -691,10 +691,17 @@ std::unique_ptr<InputFile> elf::createSh
return createELFFile<SharedFile>(MB);
}
+MemoryBufferRef LazyObjectFile::getBuffer() {
+ if (Seen)
+ return MemoryBufferRef();
+ Seen = true;
+ return MB;
+}
+
template <class ELFT>
void LazyObjectFile::parse() {
for (StringRef Sym : getSymbols())
- Symtab<ELFT>::X->addLazyObject(Sym, this->MB);
+ Symtab<ELFT>::X->addLazyObject(Sym, *this);
}
template <class ELFT> std::vector<StringRef> LazyObjectFile::getElfSymbols() {
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=272724&r1=272723&r2=272724&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Tue Jun 14 16:56:36 2016
@@ -190,6 +190,7 @@ public:
}
template <class ELFT> void parse();
+ MemoryBufferRef getBuffer();
private:
std::vector<StringRef> getSymbols();
@@ -198,6 +199,7 @@ private:
llvm::BumpPtrAllocator Alloc;
llvm::StringSaver Saver{Alloc};
+ bool Seen = false;
};
// An ArchiveFile object represents a .a file.
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=272724&r1=272723&r2=272724&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue Jun 14 16:56:36 2016
@@ -457,22 +457,25 @@ void SymbolTable<ELFT>::addLazyArchive(
}
template <class ELFT>
-void SymbolTable<ELFT>::addLazyObject(StringRef Name, MemoryBufferRef MBRef) {
+void SymbolTable<ELFT>::addLazyObject(StringRef Name, LazyObjectFile &Obj) {
Symbol *S;
bool WasInserted;
std::tie(S, WasInserted) = insert(Name);
if (WasInserted) {
- replaceBody<LazyObject>(S, Name, MBRef, SymbolBody::UnknownType);
+ replaceBody<LazyObject>(S, Name, Obj, SymbolBody::UnknownType);
return;
}
if (!S->body()->isUndefined())
return;
// See comment for addLazyArchive above.
- if (S->isWeak())
- replaceBody<LazyObject>(S, Name, MBRef, S->body()->Type);
- else
- addFile(createObjectFile(MBRef));
+ if (S->isWeak()) {
+ replaceBody<LazyObject>(S, Name, Obj, S->body()->Type);
+ } else {
+ MemoryBufferRef MBRef = Obj.getBuffer();
+ if (!MBRef.getBuffer().empty())
+ addFile(createObjectFile(MBRef));
+ }
}
// Process undefined (-u) flags by loading lazy symbols named by those flags.
Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=272724&r1=272723&r2=272724&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Tue Jun 14 16:56:36 2016
@@ -70,7 +70,7 @@ public:
const typename ELFT::Verdef *Verdef);
void addLazyArchive(ArchiveFile *F, const llvm::object::Archive::Symbol S);
- void addLazyObject(StringRef Name, MemoryBufferRef MBRef);
+ void addLazyObject(StringRef Name, LazyObjectFile &Obj);
Symbol *addBitcode(StringRef Name, bool IsWeak, uint8_t StOther, uint8_t Type,
bool CanOmitFromDynSym, BitcodeFile *File);
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=272724&r1=272723&r2=272724&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Tue Jun 14 16:56:36 2016
@@ -231,6 +231,9 @@ std::unique_ptr<InputFile> LazyArchive::
}
std::unique_ptr<InputFile> LazyObject::getFile() {
+ MemoryBufferRef MBRef = File.getBuffer();
+ if (MBRef.getBuffer().empty())
+ return std::unique_ptr<InputFile>(nullptr);
return createObjectFile(MBRef);
}
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=272724&r1=272723&r2=272724&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Tue Jun 14 16:56:36 2016
@@ -28,6 +28,7 @@ namespace elf {
class ArchiveFile;
class BitcodeFile;
class InputFile;
+class LazyObjectFile;
class SymbolBody;
template <class ELFT> class ObjectFile;
template <class ELFT> class OutputSection;
@@ -351,8 +352,8 @@ private:
// --start-lib and --end-lib options.
class LazyObject : public Lazy {
public:
- LazyObject(StringRef Name, MemoryBufferRef M, uint8_t Type)
- : Lazy(LazyObjectKind, Name, Type), MBRef(M) {}
+ LazyObject(StringRef Name, LazyObjectFile &File, uint8_t Type)
+ : Lazy(LazyObjectKind, Name, Type), File(File) {}
static bool classof(const SymbolBody *S) {
return S->kind() == LazyObjectKind;
@@ -361,7 +362,7 @@ public:
std::unique_ptr<InputFile> getFile();
private:
- MemoryBufferRef MBRef;
+ LazyObjectFile &File;
};
// Some linker-generated symbols need to be created as
Added: lld/trunk/test/ELF/Inputs/start-lib-comdat.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/start-lib-comdat.s?rev=272724&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/start-lib-comdat.s (added)
+++ lld/trunk/test/ELF/Inputs/start-lib-comdat.s Tue Jun 14 16:56:36 2016
@@ -0,0 +1,5 @@
+ .global bar
+bar:
+ .section .sec,"aG", at progbits,zed,comdat
+ .global zed
+zed:
Added: lld/trunk/test/ELF/start-lib-comdat.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/start-lib-comdat.s?rev=272724&view=auto
==============================================================================
--- lld/trunk/test/ELF/start-lib-comdat.s (added)
+++ lld/trunk/test/ELF/start-lib-comdat.s Tue Jun 14 16:56:36 2016
@@ -0,0 +1,23 @@
+// REQUIRES: x86
+
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux \
+// RUN: %p/Inputs/start-lib-comdat.s -o %t2.o
+// RUN: ld.lld -shared -o %t3 %t1.o --start-lib %t2.o --end-lib
+// RUN: llvm-readobj -t %t3 | FileCheck %s
+// RUN: ld.lld -shared -o %t3 --start-lib %t2.o --end-lib %t1.o
+// RUN: llvm-readobj -t %t3 | FileCheck %s
+
+// CHECK: Name: zed
+// CHECK-NEXT: Value:
+// CHECK-NEXT: Size:
+// CHECK-NEXT: Binding: Global
+// CHECK-NEXT: Type:
+// CHECK-NEXT: Other:
+// CHECK-NEXT: Section: Undefined
+
+ call bar at plt
+// The other file also has a section in the zed comdat, but it defines the
+// symbol zed. That means that we will have a lazy symbol zed, but when adding
+// the actual file zed will be undefined.
+ .section .sec,"aG", at progbits,zed,comdat
More information about the llvm-commits
mailing list