[PATCH] D23751: [ELF] Linkerscript: define symbols outside SECTIONS

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 20 22:55:56 PDT 2016


phosek created this revision.
phosek added a reviewer: ruiu.
phosek added subscribers: llvm-commits, phosek.
phosek added a project: lld.

Symbol assignments outside of SECTIONS command need to be created even when SECTIONS command is not present.

https://reviews.llvm.org/D23751

Files:
  ELF/LinkerScript.cpp
  ELF/LinkerScript.h
  ELF/Writer.cpp

Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -246,6 +246,8 @@
   CommonInputSection<ELFT> Common(getCommonSymbols<ELFT>());
   CommonInputSection<ELFT>::X = &Common;
 
+  Script<ELFT>::X->createSymbols();
+
   Script<ELFT>::X->OutputSections = &OutputSections;
   if (ScriptConfig->HasContents)
     Script<ELFT>::X->createSections(Factory);
Index: ELF/LinkerScript.h
===================================================================
--- ELF/LinkerScript.h
+++ ELF/LinkerScript.h
@@ -115,6 +115,7 @@
 
 // ScriptConfiguration holds linker script parse results.
 struct ScriptConfiguration {
+  std::vector<std::unique_ptr<SymbolAssignment>> Assignments;
   // Used to assign addresses to sections.
   std::vector<std::unique_ptr<BaseCommand>> Commands;
 
@@ -139,6 +140,7 @@
 public:
   LinkerScript();
   ~LinkerScript();
+  void createSymbols();
   void createSections(OutputSectionFactory<ELFT> &Factory);
 
   std::vector<PhdrEntry<ELFT>> createPhdrs();
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -259,6 +259,16 @@
 }
 
 template <class ELFT>
+void LinkerScript<ELFT>::createSymbols() {
+  for (const std::unique_ptr<SymbolAssignment> &Cmd : Opt.Assignments) {
+    if (shouldDefine<ELFT>(Cmd.get()))
+      addRegular<ELFT>(Cmd.get());
+    if (Cmd->Sym)
+      cast<DefinedRegular<ELFT>>(Cmd->Sym)->Value = Cmd->Expression(0);
+  }
+}
+
+template <class ELFT>
 void LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
   for (const std::unique_ptr<BaseCommand> &Base1 : Opt.Commands) {
     if (auto *Cmd = dyn_cast<SymbolAssignment>(Base1.get())) {
@@ -657,7 +667,7 @@
     if (Handler Fn = Cmd.lookup(Tok))
       (this->*Fn)();
     else if (SymbolAssignment *Cmd = readProvideOrAssignment(Tok))
-      Opt.Commands.emplace_back(Cmd);
+      Opt.Assignments.emplace_back(Cmd);
     else
       setError("unknown directive: " + Tok);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23751.68799.patch
Type: text/x-patch
Size: 2063 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160821/32050ced/attachment.bin>


More information about the llvm-commits mailing list