[PATCH] D28956: [LLD][ELF] Add support for local symbols in Synthetic Sections

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 07:37:23 PST 2017


peter.smith updated this revision to Diff 85385.
peter.smith added a comment.

Removed all code in SymbolTable and rebased the patch on top of https://reviews.llvm.org/D29021.

I've added a function addSyntheticLocal which creates the symbol body and automatically adds it to the SymTab if it exists. This avoids storing the SymbolBodies in a temporary location.


https://reviews.llvm.org/D28956

Files:
  ELF/SyntheticSections.cpp
  ELF/SyntheticSections.h


Index: ELF/SyntheticSections.h
===================================================================
--- ELF/SyntheticSections.h
+++ ELF/SyntheticSections.h
@@ -685,6 +685,10 @@
 template <class ELFT> InputSection<ELFT> *createCommonSection();
 template <class ELFT> InputSection<ELFT> *createInterpSection();
 template <class ELFT> MergeInputSection<ELFT> *createCommentSection();
+template <class ELFT>
+SymbolBody *
+addSyntheticLocal(StringRef Name, uint8_t Type, typename ELFT::uint Value,
+                  typename ELFT::uint Size, InputSectionBase<ELFT> *Section);
 
 // Linker generated sections which can be used as inputs.
 template <class ELFT> struct In {
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -284,6 +284,18 @@
   return Ret;
 }
 
+template <class ELFT>
+SymbolBody *elf::addSyntheticLocal(StringRef Name, uint8_t Type,
+                                   typename ELFT::uint Value,
+                                   typename ELFT::uint Size,
+                                   InputSectionBase<ELFT> *Section) {
+  auto S = new (BAlloc) DefinedRegular<ELFT>(
+      Name, /*IsLocal*/ true, STV_DEFAULT, Type, Value, Size, Section, nullptr);
+  if (In<ELFT>::SymTab)
+    In<ELFT>::SymTab->addLocal(S);
+  return S;
+}
+
 static size_t getHashSize() {
   switch (Config->BuildId) {
   case BuildIdKind::Fast:
@@ -1875,6 +1887,19 @@
 template MergeInputSection<ELF64LE> *elf::createCommentSection();
 template MergeInputSection<ELF64BE> *elf::createCommentSection();
 
+template SymbolBody *
+elf::addSyntheticLocal<ELF32LE>(StringRef, uint8_t, ELF32LE::uint,
+                                ELF32LE::uint, InputSectionBase<ELF32LE> *);
+template SymbolBody *
+elf::addSyntheticLocal<ELF32BE>(StringRef, uint8_t, ELF32BE::uint,
+                                ELF32BE::uint, InputSectionBase<ELF32BE> *);
+template SymbolBody *
+elf::addSyntheticLocal<ELF64LE>(StringRef, uint8_t, ELF64LE::uint,
+                                ELF64LE::uint, InputSectionBase<ELF64LE> *);
+template SymbolBody *
+elf::addSyntheticLocal<ELF64BE>(StringRef, uint8_t, ELF64BE::uint,
+                                ELF64BE::uint, InputSectionBase<ELF64BE> *);
+
 template class elf::MipsAbiFlagsSection<ELF32LE>;
 template class elf::MipsAbiFlagsSection<ELF32BE>;
 template class elf::MipsAbiFlagsSection<ELF64LE>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28956.85385.patch
Type: text/x-patch
Size: 2441 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170123/8071a24a/attachment.bin>


More information about the llvm-commits mailing list