[PATCH] D13055: [ELF2] Handle -m option

Rafael Espíndola via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 09:41:06 PDT 2015


You can avoid creating the low level  getElfMachineType by opening the
elf files earlier (see the attached patch).

On 23 September 2015 at 12:03, Rafael Ávila de Espíndola
<llvm-commits at lists.llvm.org> wrote:
> rafael added inline comments.
>
> ================
> Comment at: ELF/Driver.cpp:18
> @@ -17,2 +17,3 @@
>  #include "llvm/ADT/StringExtras.h"
> +#include "llvm/Object/ELF.h"
>  #include "llvm/Support/FileSystem.h"
> ----------------
> Unnecessary.
>
> ================
> Comment at: ELF/Driver.cpp:40
> @@ +39,3 @@
> +namespace {
> +using namespace ELF;
> +
> ----------------
> Replace this with a
>
> using namespace llvm::ELF;
>
> just after the existing
>
> using namespace llvm;
>
> ================
> Comment at: ELF/Driver.cpp:80
> @@ +79,3 @@
> +
> +static inline void configureTarget(ELFKind ElfKind, uint16_t EMachine) {
> +  Config->ElfKind = ElfKind;
> ----------------
> Drop the inline.
>
>
> http://reviews.llvm.org/D13055
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
-------------- next part --------------
diff --git a/ELF/InputFiles.cpp b/ELF/InputFiles.cpp
index cc5ea7a..4de4e48 100644
--- a/ELF/InputFiles.cpp
+++ b/ELF/InputFiles.cpp
@@ -82,13 +82,17 @@ typename ELFData<ELFT>::Elf_Sym_Range ELFData<ELFT>::getNonLocalSymbols() {
 }
 
 template <class ELFT>
+ObjectFile<ELFT>::ObjectFile(MemoryBufferRef M)
+    : ObjectFileBase(getStaticELFKind<ELFT>(), M) {
+  this->openELF(MB);
+}
+
+template <class ELFT>
 typename ObjectFile<ELFT>::Elf_Sym_Range ObjectFile<ELFT>::getLocalSymbols() {
   return this->getSymbolsHelper(true);
 }
 
 template <class ELFT> void elf2::ObjectFile<ELFT>::parse() {
-  this->openELF(MB);
-
   // Read section and symbol tables.
   initializeSections();
   initializeSymbols();
@@ -203,9 +207,13 @@ MemoryBufferRef ArchiveFile::getMember(const Archive::Symbol *Sym) {
   return *Ret;
 }
 
-template <class ELFT> void SharedFile<ELFT>::parse() {
+template <class ELFT>
+SharedFile<ELFT>::SharedFile(MemoryBufferRef M)
+    : SharedFileBase(getStaticELFKind<ELFT>(), M) {
   this->openELF(MB);
+}
 
+template <class ELFT> void SharedFile<ELFT>::parse() {
   for (const Elf_Shdr &Sec : this->ELFObj->sections()) {
     if (Sec.sh_type == SHT_DYNSYM) {
       this->Symtab = &Sec;
diff --git a/ELF/InputFiles.h b/ELF/InputFiles.h
index 52f4d17..e7dacc8 100644
--- a/ELF/InputFiles.h
+++ b/ELF/InputFiles.h
@@ -131,8 +131,7 @@ public:
            cast<ELFFileBase>(F)->getELFKind() == getStaticELFKind<ELFT>();
   }
 
-  explicit ObjectFile(MemoryBufferRef M)
-      : ObjectFileBase(getStaticELFKind<ELFT>(), M) {}
+  explicit ObjectFile(MemoryBufferRef M);
   void parse() override;
 
   ArrayRef<InputSection<ELFT> *> getSections() const { return Sections; }
@@ -207,8 +206,7 @@ public:
            cast<ELFFileBase>(F)->getELFKind() == getStaticELFKind<ELFT>();
   }
 
-  explicit SharedFile(MemoryBufferRef M)
-      : SharedFileBase(getStaticELFKind<ELFT>(), M) {}
+  explicit SharedFile(MemoryBufferRef M);
 
   void parse() override;
 };


More information about the llvm-commits mailing list