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

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 21 01:13:51 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL340257: [LLD][ELF] - Check the architecture of lazy objects earlier. (authored by grimar, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50899?vs=161451&id=161660#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50899

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


Index: lld/trunk/test/ELF/lazy-arch-conflict.s
===================================================================
--- lld/trunk/test/ELF/lazy-arch-conflict.s
+++ lld/trunk/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: lld/trunk/ELF/InputFiles.h
===================================================================
--- lld/trunk/ELF/InputFiles.h
+++ lld/trunk/ELF/InputFiles.h
@@ -272,8 +272,6 @@
   bool AddedToLink = false;
 
 private:
-  template <class ELFT> void addElfSymbols();
-
   uint64_t OffsetInArchive;
 };
 
Index: lld/trunk/ELF/InputFiles.cpp
===================================================================
--- lld/trunk/ELF/InputFiles.cpp
+++ lld/trunk/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.161660.patch
Type: text/x-patch
Size: 1775 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180821/c0ef93f9/attachment.bin>


More information about the llvm-commits mailing list