forked from OSchip/llvm-project
				
			Merge SymbolAssignmentKind and ExprKind.
In a linker script, `.` is a special symbol indicating a counter. Previously, we had two expression types, ExprKind and SymbolAssignmentKind for `.` and all the other symbol names, respectively. But we could merge them because the former is a special case of the latter. llvm-svn: 275527
This commit is contained in:
		
							parent
							
								
									601b07c7f5
								
							
						
					
					
						commit
						05ef4cff44
					
				| 
						 | 
				
			
			@ -227,23 +227,22 @@ void LinkerScript<ELFT>::assignAddresses(
 | 
			
		|||
  uintX_t ThreadBssOffset = 0;
 | 
			
		||||
 | 
			
		||||
  for (SectionsCommand &Cmd : Opt.Commands) {
 | 
			
		||||
    switch (Cmd.Kind) {
 | 
			
		||||
    case ExprKind:
 | 
			
		||||
      Dot = evalExpr(Cmd.Expr, Dot);
 | 
			
		||||
      continue;
 | 
			
		||||
    case SymbolAssignmentKind: {
 | 
			
		||||
      auto *D =
 | 
			
		||||
          cast<DefinedRegular<ELFT>>(Symtab<ELFT>::X->find(Cmd.Name));
 | 
			
		||||
      D->Value = evalExpr(Cmd.Expr, Dot);
 | 
			
		||||
      continue;
 | 
			
		||||
    if (Cmd.Kind == AssignmentKind) {
 | 
			
		||||
      uint64_t Val = evalExpr(Cmd.Expr, Dot);
 | 
			
		||||
 | 
			
		||||
      if (Cmd.Name == ".") {
 | 
			
		||||
        Dot = Val;
 | 
			
		||||
      } else {
 | 
			
		||||
        auto *D = cast<DefinedRegular<ELFT>>(Symtab<ELFT>::X->find(Cmd.Name));
 | 
			
		||||
        D->Value = Val;
 | 
			
		||||
      }
 | 
			
		||||
    default:
 | 
			
		||||
      break;
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Find all the sections with required name. There can be more than
 | 
			
		||||
    // ont section with such name, if the alignment, flags or type
 | 
			
		||||
    // attribute differs.
 | 
			
		||||
    assert(Cmd.Kind == SectionKind);
 | 
			
		||||
    for (OutputSectionBase<ELFT> *Sec : Sections) {
 | 
			
		||||
      if (Sec->getName() != Cmd.Name)
 | 
			
		||||
        continue;
 | 
			
		||||
| 
						 | 
				
			
			@ -312,7 +311,8 @@ int LinkerScript<ELFT>::compareSections(StringRef A, StringRef B) {
 | 
			
		|||
template <class ELFT>
 | 
			
		||||
void LinkerScript<ELFT>::addScriptedSymbols() {
 | 
			
		||||
  for (SectionsCommand &Cmd : Opt.Commands)
 | 
			
		||||
    if (Cmd.Kind == SymbolAssignmentKind)
 | 
			
		||||
    if (Cmd.Kind == AssignmentKind)
 | 
			
		||||
      if (Cmd.Name != ".")
 | 
			
		||||
        Symtab<ELFT>::X->addAbsolute(Cmd.Name, STV_DEFAULT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -525,7 +525,7 @@ void ScriptParser::readLocationCounterValue() {
 | 
			
		|||
  if (Expr.empty())
 | 
			
		||||
    error("error in location counter expression");
 | 
			
		||||
  else
 | 
			
		||||
    Opt.Commands.push_back({ExprKind, std::move(Expr), ""});
 | 
			
		||||
    Opt.Commands.push_back({AssignmentKind, std::move(Expr), "."});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ScriptParser::readOutputSectionDescription(StringRef OutSec) {
 | 
			
		||||
| 
						 | 
				
			
			@ -572,7 +572,7 @@ void ScriptParser::readSymbolAssignment(StringRef Name) {
 | 
			
		|||
  if (Expr.empty())
 | 
			
		||||
    error("error in symbol assignment expression");
 | 
			
		||||
  else
 | 
			
		||||
    Opt.Commands.push_back({SymbolAssignmentKind, std::move(Expr), Name});
 | 
			
		||||
    Opt.Commands.push_back({AssignmentKind, std::move(Expr), Name});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<StringRef> ScriptParser::readSectionsCommandExpr() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,7 +40,7 @@ struct SectionRule {
 | 
			
		|||
// This enum represents what we can observe in SECTIONS tag of script:
 | 
			
		||||
// ExprKind is a location counter change, like ". = . + 0x1000"
 | 
			
		||||
// SectionKind is a description of output section, like ".data :..."
 | 
			
		||||
enum SectionsCommandKind { ExprKind, SectionKind, SymbolAssignmentKind };
 | 
			
		||||
enum SectionsCommandKind { SectionKind, AssignmentKind };
 | 
			
		||||
 | 
			
		||||
struct SectionsCommand {
 | 
			
		||||
  SectionsCommandKind Kind;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue