forked from OSchip/llvm-project
				
			Split addSection into two small functions. NFCI.
addSection function was hard to read because it behaves differently depending on its arguments but what exactly it does is not clear. Now it should be better. Still, it is not clear (not what but) why it does what it does, but I'll take a look at it later. llvm-svn: 315124
This commit is contained in:
		
							parent
							
								
									ba0f4339a7
								
							
						
					
					
						commit
						edafba200f
					
				| 
						 | 
					@ -458,7 +458,7 @@ void LinkerScript::addOrphanSections(OutputSectionFactory &Factory) {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    log(toString(S) + " is being placed in '" + Name + "'");
 | 
					    log(toString(S) + " is being placed in '" + Name + "'");
 | 
				
			||||||
    if (I == End) {
 | 
					    if (I == End) {
 | 
				
			||||||
      Factory.addInputSec(S, Name);
 | 
					      Factory.addInputSec(S, Name, nullptr);
 | 
				
			||||||
      assert(S->getOutputSection()->SectionIndex == INT_MAX);
 | 
					      assert(S->getOutputSection()->SectionIndex == INT_MAX);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      OutputSection *Sec = cast<OutputSection>(*I);
 | 
					      OutputSection *Sec = cast<OutputSection>(*I);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -200,14 +200,25 @@ void elf::reportDiscarded(InputSectionBase *IS) {
 | 
				
			||||||
          IS->File->getName() + "'");
 | 
					          IS->File->getName() + "'");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static OutputSection *addSection(InputSectionBase *IS, StringRef OutsecName,
 | 
					static OutputSection *createSection(InputSectionBase *IS, StringRef OutsecName) {
 | 
				
			||||||
                                 OutputSection *Sec) {
 | 
					  OutputSection *Sec = Script->createOutputSection(OutsecName, "<internal>");
 | 
				
			||||||
  if (Sec && Sec->Live) {
 | 
					  Sec->Type = IS->Type;
 | 
				
			||||||
 | 
					  Sec->Flags = IS->Flags;
 | 
				
			||||||
 | 
					  Sec->addSection(cast<InputSection>(IS));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Script->Opt.Commands.push_back(Sec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return Sec;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void addSection(OutputSection *Sec, InputSectionBase *IS, StringRef OutsecName) {
 | 
				
			||||||
 | 
					  if (Sec->Live) {
 | 
				
			||||||
    if (getIncompatibleFlags(Sec->Flags) != getIncompatibleFlags(IS->Flags))
 | 
					    if (getIncompatibleFlags(Sec->Flags) != getIncompatibleFlags(IS->Flags))
 | 
				
			||||||
      error("incompatible section flags for " + Sec->Name + "\n>>> " +
 | 
					      error("incompatible section flags for " + Sec->Name + "\n>>> " +
 | 
				
			||||||
            toString(IS) + ": 0x" + utohexstr(IS->Flags) +
 | 
					            toString(IS) + ": 0x" + utohexstr(IS->Flags) +
 | 
				
			||||||
            "\n>>> output section " + Sec->Name + ": 0x" +
 | 
					            "\n>>> output section " + Sec->Name + ": 0x" +
 | 
				
			||||||
            utohexstr(Sec->Flags));
 | 
					            utohexstr(Sec->Flags));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (Sec->Type != IS->Type) {
 | 
					    if (Sec->Type != IS->Type) {
 | 
				
			||||||
      if (canMergeToProgbits(Sec->Type) && canMergeToProgbits(IS->Type))
 | 
					      if (canMergeToProgbits(Sec->Type) && canMergeToProgbits(IS->Type))
 | 
				
			||||||
        Sec->Type = SHT_PROGBITS;
 | 
					        Sec->Type = SHT_PROGBITS;
 | 
				
			||||||
| 
						 | 
					@ -218,18 +229,12 @@ static OutputSection *addSection(InputSectionBase *IS, StringRef OutsecName,
 | 
				
			||||||
              "\n>>> output section " + Sec->Name + ": " +
 | 
					              "\n>>> output section " + Sec->Name + ": " +
 | 
				
			||||||
              getELFSectionTypeName(Config->EMachine, Sec->Type));
 | 
					              getELFSectionTypeName(Config->EMachine, Sec->Type));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    Sec->Flags |= IS->Flags;
 | 
					 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    if (!Sec) {
 | 
					 | 
				
			||||||
      Sec = Script->createOutputSection(OutsecName, "<internal>");
 | 
					 | 
				
			||||||
      Script->Opt.Commands.push_back(Sec);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    Sec->Type = IS->Type;
 | 
					    Sec->Type = IS->Type;
 | 
				
			||||||
    Sec->Flags = IS->Flags;
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Sec->Flags |= IS->Flags;
 | 
				
			||||||
  Sec->addSection(cast<InputSection>(IS));
 | 
					  Sec->addSection(cast<InputSection>(IS));
 | 
				
			||||||
  return Sec;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void OutputSectionFactory::addInputSec(InputSectionBase *IS,
 | 
					void OutputSectionFactory::addInputSec(InputSectionBase *IS,
 | 
				
			||||||
| 
						 | 
					@ -242,7 +247,7 @@ void OutputSectionFactory::addInputSec(InputSectionBase *IS,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // If we have destination output section - use it directly.
 | 
					  // If we have destination output section - use it directly.
 | 
				
			||||||
  if (OS) {
 | 
					  if (OS) {
 | 
				
			||||||
    addSection(IS, OutsecName, OS);
 | 
					    addSection(OS, IS, OutsecName);
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -254,7 +259,7 @@ void OutputSectionFactory::addInputSec(InputSectionBase *IS,
 | 
				
			||||||
  // as-is because adding/removing members or merging them with other groups
 | 
					  // as-is because adding/removing members or merging them with other groups
 | 
				
			||||||
  // change their semantics.
 | 
					  // change their semantics.
 | 
				
			||||||
  if (IS->Type == SHT_GROUP || (IS->Flags & SHF_GROUP)) {
 | 
					  if (IS->Type == SHT_GROUP || (IS->Flags & SHF_GROUP)) {
 | 
				
			||||||
    addSection(IS, OutsecName, nullptr);
 | 
					    createSection(IS, OutsecName);
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -268,13 +273,20 @@ void OutputSectionFactory::addInputSec(InputSectionBase *IS,
 | 
				
			||||||
      (IS->Type == SHT_REL || IS->Type == SHT_RELA)) {
 | 
					      (IS->Type == SHT_REL || IS->Type == SHT_RELA)) {
 | 
				
			||||||
    auto *Sec = cast<InputSection>(IS);
 | 
					    auto *Sec = cast<InputSection>(IS);
 | 
				
			||||||
    OutputSection *Out = Sec->getRelocatedSection()->getOutputSection();
 | 
					    OutputSection *Out = Sec->getRelocatedSection()->getOutputSection();
 | 
				
			||||||
    Out->RelocationSection = addSection(IS, OutsecName, Out->RelocationSection);
 | 
					
 | 
				
			||||||
 | 
					    if (Out->RelocationSection)
 | 
				
			||||||
 | 
					      addSection(Out->RelocationSection, IS, OutsecName);
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      Out->RelocationSection = createSection(IS, OutsecName);
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  SectionKey Key = createKey(IS, OutsecName);
 | 
					  SectionKey Key = createKey(IS, OutsecName);
 | 
				
			||||||
  OutputSection *&Sec = Map[Key];
 | 
					  OutputSection *&Sec = Map[Key];
 | 
				
			||||||
  Sec = addSection(IS, OutsecName, Sec);
 | 
					  if (Sec)
 | 
				
			||||||
 | 
					    addSection(Sec, IS, OutsecName);
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    Sec = createSection(IS, OutsecName);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
OutputSectionFactory::~OutputSectionFactory() {}
 | 
					OutputSectionFactory::~OutputSectionFactory() {}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -165,7 +165,7 @@ public:
 | 
				
			||||||
  ~OutputSectionFactory();
 | 
					  ~OutputSectionFactory();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void addInputSec(InputSectionBase *IS, StringRef OutsecName,
 | 
					  void addInputSec(InputSectionBase *IS, StringRef OutsecName,
 | 
				
			||||||
                   OutputSection *OS = nullptr);
 | 
					                   OutputSection *OS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
  llvm::SmallDenseMap<SectionKey, OutputSection *> Map;
 | 
					  llvm::SmallDenseMap<SectionKey, OutputSection *> Map;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -880,7 +880,7 @@ template <class ELFT> void Writer<ELFT>::createSections() {
 | 
				
			||||||
  Script->Opt.Commands.clear();
 | 
					  Script->Opt.Commands.clear();
 | 
				
			||||||
  for (InputSectionBase *IS : InputSections)
 | 
					  for (InputSectionBase *IS : InputSections)
 | 
				
			||||||
    if (IS)
 | 
					    if (IS)
 | 
				
			||||||
      Factory.addInputSec(IS, getOutputSectionName(IS->Name));
 | 
					      Factory.addInputSec(IS, getOutputSectionName(IS->Name), nullptr);
 | 
				
			||||||
  Script->Opt.Commands.insert(Script->Opt.Commands.end(), Old.begin(),
 | 
					  Script->Opt.Commands.insert(Script->Opt.Commands.end(), Old.begin(),
 | 
				
			||||||
                              Old.end());
 | 
					                              Old.end());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue