Lines Matching +full:invert +full:- +full:ext

1 //===- ScriptParser.cpp ---------------------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file contains a recursive-descendent parser for linker scripts.
12 //===----------------------------------------------------------------------===//
53 if (config->sysroot == "")
57 if (!sys::fs::equivalent(config->sysroot, path))
138 // True if a script being read is in the --sysroot directory.
152 return s.substr(1, s.size() - 2);
162 script->recordError(
174 return a.getValue() - b.getValue();
175 return {a.sec, false, a.getSectionOffset() - b.getValue(), a.loc};
181 (a.getValue() & b.getValue()) - a.getSecAddr(), a.loc};
187 (a.getValue() ^ b.getValue()) - a.getSecAddr(), a.loc};
193 (a.getValue() | b.getValue()) - a.getSecAddr(), a.loc};
208 setError("\"local:\" scope not supported in --dynamic-list");
213 config->dynamicList.push_back(v);
289 script->sectionCommands.push_back(cmd);
304 script->sectionCommands.push_back(cmd);
315 script->noCrossRefs.push_back(std::move(cmd));
321 StringRef path = (config->sysroot + s).toStringRef(pathData);
325 setError("cannot find " + s + " inside " + config->sysroot);
334 if (config->sysroot.empty())
337 ctx.driver.addFile(saver().save(config->sysroot + "/" + s.substr(1)),
339 } else if (s.starts_with("-l")) {
369 bool orig = config->asNeeded;
370 config->asNeeded = true;
373 config->asNeeded = orig;
377 // -e <symbol> takes predecence over ENTRY(<symbol>).
380 if (config->entry.empty())
381 config->entry = unquote(tok);
388 config->undefined.push_back(unquote(next()));
427 // -o <file> takes predecence over OUTPUT(<file>).
430 if (config->outputFile.empty())
431 config->outputFile = unquote(tok);
444 .Case("elf32-i386", {ELF32LEKind, EM_386})
445 .Case("elf32-avr", {ELF32LEKind, EM_AVR})
446 .Case("elf32-iamcu", {ELF32LEKind, EM_IAMCU})
447 .Case("elf32-littlearm", {ELF32LEKind, EM_ARM})
448 .Case("elf32-bigarm", {ELF32BEKind, EM_ARM})
449 .Case("elf32-x86-64", {ELF32LEKind, EM_X86_64})
450 .Case("elf64-aarch64", {ELF64LEKind, EM_AARCH64})
451 .Case("elf64-littleaarch64", {ELF64LEKind, EM_AARCH64})
452 .Case("elf64-bigaarch64", {ELF64BEKind, EM_AARCH64})
453 .Case("elf32-powerpc", {ELF32BEKind, EM_PPC})
454 .Case("elf32-powerpcle", {ELF32LEKind, EM_PPC})
455 .Case("elf64-powerpc", {ELF64BEKind, EM_PPC64})
456 .Case("elf64-powerpcle", {ELF64LEKind, EM_PPC64})
457 .Case("elf64-x86-64", {ELF64LEKind, EM_X86_64})
458 .Cases("elf32-tradbigmips", "elf32-bigmips", {ELF32BEKind, EM_MIPS})
459 .Case("elf32-ntradbigmips", {ELF32BEKind, EM_MIPS})
460 .Case("elf32-tradlittlemips", {ELF32LEKind, EM_MIPS})
461 .Case("elf32-ntradlittlemips", {ELF32LEKind, EM_MIPS})
462 .Case("elf64-tradbigmips", {ELF64BEKind, EM_MIPS})
463 .Case("elf64-tradlittlemips", {ELF64LEKind, EM_MIPS})
464 .Case("elf32-littleriscv", {ELF32LEKind, EM_RISCV})
465 .Case("elf64-littleriscv", {ELF64LEKind, EM_RISCV})
466 .Case("elf64-sparc", {ELF64BEKind, EM_SPARCV9})
467 .Case("elf32-msp430", {ELF32LEKind, EM_MSP430})
468 .Case("elf32-loongarch", {ELF32LEKind, EM_LOONGARCH})
469 .Case("elf64-loongarch", {ELF64LEKind, EM_LOONGARCH})
470 .Case("elf64-s390", {ELF64BEKind, EM_S390})
471 .Cases("elf32-hexagon", "elf32-littlehexagon", {ELF32LEKind, EM_HEXAGON})
476 // big if -EB is specified, little if -EL is specified, or default if neither is
485 if (config->optEB)
489 if (config->optEL)
494 if (!config->bfdname.empty())
496 config->bfdname = s;
499 config->oFormatBinary = true;
503 if (s.consume_back("-freebsd"))
504 config->osabi = ELFOSABI_FREEBSD;
506 std::tie(config->ekind, config->emachine) = parseBfdName(s);
507 if (config->emachine == EM_NONE)
508 setError("unknown output format name: " + config->bfdname);
509 if (s == "elf32-ntradlittlemips" || s == "elf32-ntradbigmips")
510 config->mipsN32Abi = true;
511 if (config->emachine == EM_MSP430)
512 config->osabi = ELFOSABI_STANDALONE;
536 script->phdrsCommands.push_back(cmd);
547 if (script->memoryRegions.count(alias))
549 if (!script->memoryRegions.count(name))
551 script->memoryRegions.insert({alias, script->memoryRegions[name]});
557 if (!config->nostdlib)
558 config->searchPaths.push_back(unquote(tok));
565 // https://sourceware.org/binutils/docs/ld/Overlay-Description.html#Overlay-Description
569 addrExpr = [] { return script->getDot(); };
574 // When AT is omitted, LMA should equal VMA. script->getDot() when evaluating
577 consume("AT") ? readParenExpr() : [] { return script->getDot(); };
586 osd->osec.addrExpr = addrExpr;
588 osd->osec.lmaExpr = [=] { return prev->getLMA() + prev->size; };
590 osd->osec.lmaExpr = lmaExpr;
593 osd->osec.usedInExpression = true;
594 addrExpr = [=]() -> ExprValue { return {&osd->osec, false, 0, ""}; };
597 prev = &osd->osec;
607 max = std::max(max, cast<OutputDesc>(cmd)->osec.size);
617 script->overwriteSections.push_back(readOutputSectionDescription(next()));
642 if (!script->seenRelroEnd)
645 osd->osec.relro = false;
647 script->sectionCommands.insert(script->sectionCommands.end(), v.begin(),
651 script->hasSectionsCommand = true;
664 names.push_back(os->osec.name);
666 script->insertCommands.push_back({std::move(names), isAfter, where});
670 // TARGET(foo) is an alias for "--format foo". Unlike GNU linkers,
672 // for --format. We recognize only /^elf/ and "binary" in the linker
679 config->formatBinary = false;
681 config->formatBinary = true;
689 .Cases("+", "-", 10)
699 .Default(-1);
730 // <elem> ::= <exclude>? <glob-pattern>
731 // <exclude> ::= "EXCLUDE_FILE" "(" <glob-pattern>+ ")"
755 // Detect common mistakes when certain non-wildcard meta characters are
778 // <patterns> ::= <section-list>
779 // | <sort> "(" <section-list> ")"
780 // | <sort> "(" <sort> "(" <section-list> ")" ")"
785 // <section-list> is parsed by readInputSectionsList().
817 std::move(v.begin(), v.end(), std::back_inserter(cmd->sectionPatterns));
825 // https://sourceware.org/binutils/docs/ld/Input-Section-Keep.html#Input-Section-Keep
835 script->keptSections.push_back(cmd);
861 return script->getDot();
882 cmd->type = SHT_NOBITS;
883 cmd->typeIsSet = true;
890 cmd->type = it->second;
896 cmd->type = readExpr()().getValue();
898 cmd->typeIsSet = true;
901 cmd->nonAlloc = true;
916 // https://sourceware.org/binutils/docs/ld/Output-Section-Address.html
917 // https://sourceware.org/binutils/docs/ld/Output-Section-Type.html
924 cmd->addrExpr = readExpr();
927 cmd->addrExpr = readExpr();
950 OutputDesc *osd = script->createOutputSection(next(), getCurrentLocation());
951 osd->osec.inOverlay = true;
958 osd->osec.commands.push_back(
961 osd->osec.phdrs = readOutputSectionPhdrs();
967 script->createOutputSection(unquote(outSec), getCurrentLocation());
968 OutputSection *osec = &cmd->osec;
970 osec->relro = script->seenDataAlign && !script->seenRelroEnd;
972 size_t symbolsReferenced = script->referencedSymbols.size();
980 osec->lmaExpr = readParenExpr();
982 osec->alignExpr = checkAlignment(readParenExpr(), location);
984 osec->subalignExpr = checkAlignment(readParenExpr(), location);
988 osec->constraint = ConstraintKind::ReadOnly;
990 osec->constraint = ConstraintKind::ReadWrite;
998 osec->commands.push_back(assign);
1000 osec->commands.push_back(data);
1008 // https://sourceware.org/binutils/docs/ld/Output-Section-Data.html
1011 osec->filler = readFill();
1019 osec->commands.push_back(readInputSectionDescription(tok));
1028 isd->sectionPatterns.push_back({{}, StringMatcher("*")});
1029 osec->commands.push_back(isd);
1034 osec->memoryRegionName = std::string(next());
1038 osec->lmaRegionName = std::string(next());
1041 if (osec->lmaExpr && !osec->lmaRegionName.empty())
1044 osec->phdrs = readOutputSectionPhdrs();
1049 osec->filler = readFill();
1056 if (script->referencedSymbols.size() > symbolsReferenced)
1057 osec->expressionsUseSymbols = true;
1061 // Reads a `=<fillexp>` expression and returns its value as a big-endian number.
1062 // https://sourceware.org/binutils/docs/ld/Output-Section-Fill.html
1066 // size, while ld.gold always handles it as a 32-bit big-endian number.
1074 setError("filler expression result does not fit 32-bit: 0x" +
1095 cmd->provide = provide;
1096 cmd->hidden = hidden;
1108 bool savedSeenRelroEnd = script->seenRelroEnd;
1114 } else if ((op.size() == 2 && op[1] == '=' && strchr("*/+-&^|", op[0])) ||
1129 cmd->dataSegmentRelroEnd = !savedSeenRelroEnd && script->seenRelroEnd;
1130 cmd->commandString =
1141 assert(op == "=" || op == "*=" || op == "/=" || op == "+=" || op == "-=" ||
1147 e = [=, c = op[0]]() -> ExprValue {
1148 ExprValue lhs = script->getSymbolValue(name, loc);
1159 case '-':
1180 // This is an operator-precedence parser to parse a linker
1183 // Our lexer is context-aware. Set the in-expression bit so that
1193 if (op == "-")
1199 return [=]() -> uint64_t {
1208 return [=]() -> uint64_t {
1244 // This is a part of the operator-precedence parser. This function
1275 return [=]() -> uint64_t {
1277 return config->commonPageSize;
1288 return [] { return config->maxPageSize; };
1332 .Default(-1);
1333 if (size == -1)
1412 if (osec.location.empty() && script->errorOnMissingSection)
1413 script->recordError(location + ": undefined section " + osec.name);
1435 if (consume("-")) {
1437 return [=] { return -e().getValue(); };
1443 // Built-in functions are parsed here.
1444 // https://sourceware.org/binutils/docs/ld/Builtin-Functions.html.
1455 OutputSection *osec = &script->getOrCreateOutputSection(name)->osec;
1456 osec->usedInExpression = true;
1457 return [=]() -> ExprValue {
1467 return [=] { return alignToPowerOf2(script->getDot(), e().getValue()); };
1480 OutputSection *osec = &script->getOrCreateOutputSection(name)->osec;
1483 return osec->addralign;
1496 script->seenDataAlign = true;
1499 return (script->getDot() + align - 1) & -align;
1506 return [] { return script->getDot(); };
1517 script->seenRelroEnd = true;
1518 return [=] { return alignToPowerOf2(script->getDot(), config->maxPageSize); };
1527 return s && s->isDefined() && ctx.scriptSymOrder.lookup(s) < order ? 1
1533 if (script->memoryRegions.count(name) == 0) {
1537 return script->memoryRegions[name]->length;
1541 OutputSection *osec = &script->getOrCreateOutputSection(name)->osec;
1542 osec->usedInExpression = true;
1545 return osec->getLMA();
1569 if (script->memoryRegions.count(name) == 0) {
1573 return script->memoryRegions[name]->origin;
1585 OutputSection *cmd = &script->getOrCreateOutputSection(name)->osec;
1589 return [=] { return cmd->size; };
1596 return [=] { return script->getSymbolValue(tok, location); };
1608 script->provideMap[*activeProvideSym].push_back(tok);
1610 script->referencedSymbols.push_back(tok);
1611 return [=] { return script->getSymbolValue(tok, location); };
1661 .Default(-1);
1663 if (ret == (unsigned)-1) {
1676 config->versionDefinitions[VER_NDX_LOCAL].localPatterns.push_back(pat);
1678 config->versionDefinitions[VER_NDX_GLOBAL].nonLocalPatterns.push_back(pat);
1683 // Reads a non-anonymous version definition,
1696 ver.id = config->versionDefinitions.size();
1697 config->versionDefinitions.push_back(ver);
1732 SmallVector<SymbolVersion, 0> ext = readVersionExtern();
1733 v->insert(v->end(), ext.begin(), ext.end());
1736 v->push_back({unquote(tok), false, hasWildcard(tok)});
1809 if (!script->memoryRegions.insert({tok, mr}).second)
1820 bool invert = false;
1824 invert = !invert;
1841 if (invert) {