mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-12 02:47:10 +00:00
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);
|
||||
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;
|
||||
}
|
||||
continue;
|
||||
case SymbolAssignmentKind: {
|
||||
auto *D =
|
||||
cast<DefinedRegular<ELFT>>(Symtab<ELFT>::X->find(Cmd.Name));
|
||||
D->Value = evalExpr(Cmd.Expr, Dot);
|
||||
continue;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// 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,8 +311,9 @@ int LinkerScript<ELFT>::compareSections(StringRef A, StringRef B) {
|
||||
template <class ELFT>
|
||||
void LinkerScript<ELFT>::addScriptedSymbols() {
|
||||
for (SectionsCommand &Cmd : Opt.Commands)
|
||||
if (Cmd.Kind == SymbolAssignmentKind)
|
||||
Symtab<ELFT>::X->addAbsolute(Cmd.Name, STV_DEFAULT);
|
||||
if (Cmd.Kind == AssignmentKind)
|
||||
if (Cmd.Name != ".")
|
||||
Symtab<ELFT>::X->addAbsolute(Cmd.Name, STV_DEFAULT);
|
||||
}
|
||||
|
||||
class elf::ScriptParser : public ScriptParserBase {
|
||||
@ -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…
x
Reference in New Issue
Block a user