[PATCH] D65909: ELF: Move sections referred to by __start_/__stop_ symbols into the main partition.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 15:21:54 PDT 2019


pcc created this revision.
pcc added reviewers: ruiu, MaskRay, peter.smith, grimar.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

In the case where C identifier sections have SHF_LINK_ORDER they will most
likely be placed in the same partition as the section that they are associated
with. But unless this happens to be the main partition, this will cause them
to be excluded from the range covered by the __start_ and __stop_ symbols,
which may lead to incorrect program behaviour. So we need to move them
all into the main partition so that they will be covered by the __start_
and __stop_ symbols.

We may want to refine this approach later and allow different __start_/__stop_
symbol values for different partitions. This would only make sense for
relocations from SHT_NOTE sections since they are duplicated into each
partition.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65909

Files:
  lld/ELF/MarkLive.cpp


Index: lld/ELF/MarkLive.cpp
===================================================================
--- lld/ELF/MarkLive.cpp
+++ lld/ELF/MarkLive.cpp
@@ -291,14 +291,31 @@
 // GOT, which means that the ifunc must be available when the main partition is
 // loaded) and TLS symbols (because we only know how to correctly process TLS
 // relocations for the main partition).
+//
+// We also need to move sections whose names are C identifiers that are referred
+// to from __start_/__stop_ symbols because there will only be one set of
+// symbols for the whole program.
 template <class ELFT> void MarkLive<ELFT>::moveToMain() {
-  for (InputFile *file : objectFiles)
-    for (Symbol *s : file->getSymbols())
+  StringSet<> startStopSymbolNames;
+  for (InputFile *file : objectFiles) {
+    for (Symbol *s : file->getSymbols()) {
       if (auto *d = dyn_cast<Defined>(s))
         if ((d->type == STT_GNU_IFUNC || d->type == STT_TLS) && d->section &&
             d->section->isLive())
           markSymbol(s);
 
+      StringRef name = s->getName();
+      if (name.startswith("__start_"))
+        startStopSymbolNames.insert(name.substr(8));
+      else if (name.startswith("__stop_"))
+        startStopSymbolNames.insert(name.substr(7));
+    }
+  }
+
+  for (InputSectionBase *sec : inputSections)
+    if (sec->isLive() && startStopSymbolNames.count(sec->name))
+      enqueue(sec, 0);
+
   mark();
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65909.214017.patch
Type: text/x-patch
Size: 1410 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190807/9d85980d/attachment.bin>


More information about the llvm-commits mailing list