Simplify symbol computation for non alloc sections.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 7 Feb 2017 20:22:04 +0000 (20:22 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 7 Feb 2017 20:22:04 +0000 (20:22 +0000)
We now just keep the address the section would have if it was
allocatable. Only the writer ignores it at the very end.

llvm-svn: 294346

lld/ELF/LinkerScript.cpp
lld/ELF/OutputSections.cpp

index fe0a3cf..7b6f449 100644 (file)
@@ -101,12 +101,8 @@ static void assignSymbol(SymbolAssignment *Cmd, typename ELFT::uint Dot = 0) {
 
   if (auto *Body = dyn_cast<DefinedSynthetic>(Cmd->Sym)) {
     Body->Section = Cmd->Expression.Section();
-    if (Body->Section) {
-      uint64_t VA = 0;
-      if (Body->Section->Flags & SHF_ALLOC)
-        VA = Body->Section->Addr;
-      Body->Value = Cmd->Expression(Dot) - VA;
-    }
+    if (Body->Section)
+      Body->Value = Cmd->Expression(Dot) - Body->Section->Addr;
     return;
   }
 
@@ -802,12 +798,9 @@ void LinkerScript<ELFT>::assignAddresses(std::vector<PhdrEntry> &Phdrs) {
   }
 
   uintX_t MinVA = std::numeric_limits<uintX_t>::max();
-  for (OutputSectionBase *Sec : *OutputSections) {
+  for (OutputSectionBase *Sec : *OutputSections)
     if (Sec->Flags & SHF_ALLOC)
       MinVA = std::min<uint64_t>(MinVA, Sec->Addr);
-    else
-      Sec->Addr = 0;
-  }
 
   allocateHeaders<ELFT>(Phdrs, *OutputSections, MinVA);
 }
index 6de3044..6a8ab55 100644 (file)
@@ -57,7 +57,7 @@ void OutputSectionBase::writeHeaderTo(typename ELFT::Shdr *Shdr) {
   Shdr->sh_flags = Flags;
   Shdr->sh_info = Info;
   Shdr->sh_link = Link;
-  Shdr->sh_addr = Addr;
+  Shdr->sh_addr = (Flags & SHF_ALLOC) ? Addr : 0;
   Shdr->sh_size = Size;
   Shdr->sh_name = ShName;
 }