[PATCH] D13385: [ELF2] Add -init and -fini switches

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 10:51:20 PDT 2015


ruiu accepted this revision.
ruiu added a comment.
This revision is now accepted and ready to land.

What happens if the symbol given by -fini is in an archive? Does linker have to resolve the symbol by extracting and parsing the object file from the archive?


================
Comment at: ELF/OutputSections.cpp:221-232
@@ -219,2 +220,14 @@
 
+  auto LookupForBody = [&](StringRef Name) {
+    ELFSymbolBody<ELFT> *Body = nullptr;
+    if (Symbol *Sym = SymTab.getSymbols().lookup(Name))
+      Body = dyn_cast<ELFSymbolBody<ELFT>>(Sym->Body);
+    return Body;
+  };
+
+  if ((InitSymbolBody = LookupForBody(Config->Init)))
+    ++NumEntries; // DT_INIT
+  if ((FiniSymbolBody = LookupForBody(Config->Fini)))
+    ++NumEntries; // DT_FINI
+
   ++NumEntries; // DT_NULL
----------------
Lambda doesn't seem to help improve readability here. This would be better.

  if (Symbol *S = Symtab.getSymbols().lookup(Config->Init)))
    InitSym = dyn_cast<ELFSymbolBody<ELFT>>(S->Body);
  if (Symbol *S = Symtab.getSymbols().lookup(Config->Fini)))
    FiniSym = dyn_cast<ELFSymbolBody<ELFT>>(S->Body);

  if (InitSym)
    ++NumEntries; // DT_FINI
  if (FiniSym)
    ++NumEntries; // DT_INIT

================
Comment at: ELF/OutputSections.h:334-335
@@ -331,2 +333,4 @@
   SymbolTable &SymTab;
+  const ELFSymbolBody<ELFT> *InitSymbolBody = nullptr;
+  const ELFSymbolBody<ELFT> *FiniSymbolBody = nullptr;
 };
----------------
InitSymbolBody -> InitSym
Likewise Fini.

================
Comment at: ELF/OutputSections.h:334-335
@@ -331,2 +333,4 @@
   SymbolTable &SymTab;
+  const ELFSymbolBody<ELFT> *InitSymbolBody = nullptr;
+  const ELFSymbolBody<ELFT> *FiniSymbolBody = nullptr;
 };
----------------
ruiu wrote:
> InitSymbolBody -> InitSym
> Likewise Fini.
These symbols type should be Defined<ELFT>, no? They can't be Undefined<ELFT> which is a subclass of ELFSymbolBody<ELFT>


http://reviews.llvm.org/D13385





More information about the llvm-commits mailing list