[PATCH] D50899: [LLD][ELF] - Check the architecture of lazy objects earlier.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 20 02:24:06 PDT 2018


grimar updated this revision to Diff 161451.
grimar marked 2 inline comments as done.
grimar added a comment.

- Addressed review comments.


https://reviews.llvm.org/D50899

Files:
  ELF/InputFiles.cpp
  ELF/InputFiles.h
  test/ELF/lazy-arch-conflict.s


Index: test/ELF/lazy-arch-conflict.s
===================================================================
--- test/ELF/lazy-arch-conflict.s
+++ test/ELF/lazy-arch-conflict.s
@@ -0,0 +1,7 @@
+# REQUIRES: x86
+
+# RUN: echo '.globl foo; .weak foo; .quad foo;' | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -o %t64.o
+# RUN: echo '.globl foo; foo:' | llvm-mc -filetype=obj -triple=i686-pc-linux - -o %t32.o
+# RUN: not ld.lld %t64.o --start-lib %t32.o --end-lib -o /dev/null 2>&1 | Filecheck %s
+
+# CHECK: error: incompatible file: {{.*}}32.o
Index: ELF/InputFiles.h
===================================================================
--- ELF/InputFiles.h
+++ ELF/InputFiles.h
@@ -272,7 +272,6 @@
   bool AddedToLink = false;
 
 private:
-  template <class ELFT> void addElfSymbols();
 
   uint64_t OffsetInArchive;
 };
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -1261,25 +1261,11 @@
     return;
   }
 
-  switch (getELFKind(this->MB)) {
-  case ELF32LEKind:
-    addElfSymbols<ELF32LE>();
-    return;
-  case ELF32BEKind:
-    addElfSymbols<ELF32BE>();
-    return;
-  case ELF64LEKind:
-    addElfSymbols<ELF64LE>();
+  if (getELFKind(this->MB) != Config->EKind) {
+    error("incompatible file: " + this->MB.getBufferIdentifier());
     return;
-  case ELF64BEKind:
-    addElfSymbols<ELF64BE>();
-    return;
-  default:
-    llvm_unreachable("getELFKind");
   }
-}
 
-template <class ELFT> void LazyObjFile::addElfSymbols() {
   ELFFile<ELFT> Obj = check(ELFFile<ELFT>::create(MB.getBuffer()));
   ArrayRef<typename ELFT::Shdr> Sections = CHECK(Obj.sections(), this);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50899.161451.patch
Type: text/x-patch
Size: 1683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180820/0188523a/attachment.bin>


More information about the llvm-commits mailing list