forked from OSchip/llvm-project
				
			Simplify LinkerScript<ELFT>::createSections.
Previously, we were setting LayoutInputSection's OutputSection member in createSections. Because when we create LayoutInputSectinos, we don't know the output section for them, so we backfilled the member in the function. This patch moves the code to backfill it to assignOffsets. llvm-svn: 278464
This commit is contained in:
		
							parent
							
								
									ea02372059
								
							
						
					
					
						commit
						0c70d3ccb7
					
				| 
						 | 
					@ -50,10 +50,8 @@ static void addRegular(SymbolAssignment *Cmd) {
 | 
				
			||||||
  Cmd->Sym = Sym->body();
 | 
					  Cmd->Sym = Sym->body();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <class ELFT>
 | 
					template <class ELFT> static void addSynthetic(SymbolAssignment *Cmd) {
 | 
				
			||||||
static void addSynthetic(SymbolAssignment *Cmd,
 | 
					  Symbol *Sym = Symtab<ELFT>::X->addSynthetic(Cmd->Name, nullptr, 0);
 | 
				
			||||||
                         OutputSectionBase<ELFT> *Section) {
 | 
					 | 
				
			||||||
  Symbol *Sym = Symtab<ELFT>::X->addSynthetic(Cmd->Name, Section, 0);
 | 
					 | 
				
			||||||
  Sym->Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;
 | 
					  Sym->Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;
 | 
				
			||||||
  Cmd->Sym = Sym->body();
 | 
					  Cmd->Sym = Sym->body();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -224,6 +222,8 @@ LinkerScript<ELFT>::createInputSectionList(OutputSectionCommand &Cmd) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for (const std::unique_ptr<BaseCommand> &Base : Cmd.Commands) {
 | 
					  for (const std::unique_ptr<BaseCommand> &Base : Cmd.Commands) {
 | 
				
			||||||
    if (auto *Cmd = dyn_cast<SymbolAssignment>(Base.get())) {
 | 
					    if (auto *Cmd = dyn_cast<SymbolAssignment>(Base.get())) {
 | 
				
			||||||
 | 
					      if (shouldDefine<ELFT>(Cmd))
 | 
				
			||||||
 | 
					        addSynthetic<ELFT>(Cmd);
 | 
				
			||||||
      Ret.push_back(new (LAlloc.Allocate()) LayoutInputSection<ELFT>(Cmd));
 | 
					      Ret.push_back(new (LAlloc.Allocate()) LayoutInputSection<ELFT>(Cmd));
 | 
				
			||||||
      continue;
 | 
					      continue;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -258,16 +258,8 @@ void LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
 | 
				
			||||||
      std::tie(OutSec, IsNew) = Factory.create(Head, Cmd->Name);
 | 
					      std::tie(OutSec, IsNew) = Factory.create(Head, Cmd->Name);
 | 
				
			||||||
      if (IsNew)
 | 
					      if (IsNew)
 | 
				
			||||||
        OutputSections->push_back(OutSec);
 | 
					        OutputSections->push_back(OutSec);
 | 
				
			||||||
 | 
					      for (InputSectionBase<ELFT> *Sec : V)
 | 
				
			||||||
      for (InputSectionBase<ELFT> *Sec : V) {
 | 
					 | 
				
			||||||
        if (auto *L = dyn_cast<LayoutInputSection<ELFT>>(Sec)) {
 | 
					 | 
				
			||||||
          if (shouldDefine<ELFT>(L->Cmd))
 | 
					 | 
				
			||||||
            addSynthetic<ELFT>(L->Cmd, OutSec);
 | 
					 | 
				
			||||||
          else if (L->Cmd->Name != ".")
 | 
					 | 
				
			||||||
            continue;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        OutSec->addSection(Sec);
 | 
					        OutSec->addSection(Sec);
 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    } else if (auto *Cmd2 = dyn_cast<SymbolAssignment>(Base1.get())) {
 | 
					    } else if (auto *Cmd2 = dyn_cast<SymbolAssignment>(Base1.get())) {
 | 
				
			||||||
      if (shouldDefine<ELFT>(Cmd2))
 | 
					      if (shouldDefine<ELFT>(Cmd2))
 | 
				
			||||||
        addRegular<ELFT>(Cmd2);
 | 
					        addRegular<ELFT>(Cmd2);
 | 
				
			||||||
| 
						 | 
					@ -335,10 +327,13 @@ template <class ELFT> void assignOffsets(OutputSectionBase<ELFT> *Sec) {
 | 
				
			||||||
  for (InputSection<ELFT> *I : OutSec->Sections) {
 | 
					  for (InputSection<ELFT> *I : OutSec->Sections) {
 | 
				
			||||||
    if (auto *L = dyn_cast<LayoutInputSection<ELFT>>(I)) {
 | 
					    if (auto *L = dyn_cast<LayoutInputSection<ELFT>>(I)) {
 | 
				
			||||||
      uintX_t Value = L->Cmd->Expression(Sec->getVA() + Off) - Sec->getVA();
 | 
					      uintX_t Value = L->Cmd->Expression(Sec->getVA() + Off) - Sec->getVA();
 | 
				
			||||||
      if (L->Cmd->Name == ".")
 | 
					      if (L->Cmd->Name == ".") {
 | 
				
			||||||
        Off = Value;
 | 
					        Off = Value;
 | 
				
			||||||
      else
 | 
					      } else {
 | 
				
			||||||
        cast<DefinedSynthetic<ELFT>>(L->Cmd->Sym)->Value = Value;
 | 
					        auto *Sym = cast<DefinedSynthetic<ELFT>>(L->Cmd->Sym);
 | 
				
			||||||
 | 
					        Sym->Section = OutSec;
 | 
				
			||||||
 | 
					        Sym->Value = Value;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      Off = alignTo(Off, I->Alignment);
 | 
					      Off = alignTo(Off, I->Alignment);
 | 
				
			||||||
      I->OutSecOff = Off;
 | 
					      I->OutSecOff = Off;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue