Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/eld/Script/Expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ class Symbol : public Expression {
Expression *getRightExpression() const override { return nullptr; }

mutable LDSymbol *ThisSymbol = nullptr;
const Assignment *SourceAssignment = nullptr;
};

//===----------------------------------------------------------------------===//
Expand Down
14 changes: 14 additions & 0 deletions include/eld/Target/GNULDBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "eld/Readers/ELFSection.h"
#include "eld/Readers/SymDefReader.h"
#include "eld/Script/Assignment.h"
#include "eld/Script/Expression.h"
#include "eld/Script/VersionScript.h"
#include "eld/SymbolResolver/ResolveInfo.h"
#include "eld/Target/ELFSegment.h"
Expand Down Expand Up @@ -824,6 +825,17 @@ class GNULDBackend {

const ResolveInfo *findAbsolutePLT(ResolveInfo *I) const;

const Assignment *getLatestAssignment(llvm::StringRef SymName) {
auto it = SymbolNameToLatestAssignment.find(SymName);
if (it != SymbolNameToLatestAssignment.end())
return it->getValue();
return nullptr;
}

void updateLatestAssignment(llvm::StringRef SymName, const Assignment *A) {
SymbolNameToLatestAssignment[SymName] = A;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why backend ? can we store this in LinkerScript ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are used during the layout computation. Currently, the entire logic for layout computation is in GNULDBackend.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest assignment would then become PROVIDE which will not be provided because of the preceding assignment ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment::assign for a PROVIDE assignment is only called if the assignment is indeed provided.


protected:
virtual int numReservedSegments() const { return m_NumReservedSegments; }

Expand Down Expand Up @@ -1132,6 +1144,8 @@ class GNULDBackend {
bool m_NeedEhdr = false;

bool m_NeedPhdr = false;

llvm::StringMap<const Assignment *> SymbolNameToLatestAssignment;
};

} // namespace eld
Expand Down
1 change: 1 addition & 0 deletions lib/Object/ObjectLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,7 @@ bool ObjectLinker::addScriptSymbols() {
// If there is a relocation to this symbol, the symbols contained in the
// assignment also need to be considered as part of the list of symbols
// that will be live.
// FIXME: Duplicate redundant addAssignment!
if (Symbol)
ThisModule->addAssignment(Symbol->resolveInfo()->name(), AssignCmd);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Script/Assignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ bool Assignment::assign(Module &CurModule, const ELFSection *Section) {
ThisSymbol->setScriptValueDefined();
}

auto &Backend = CurModule.getBackend();
Backend.updateLatestAssignment(Name, this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wont this cause issues if the symbol assignment is PROVIDE ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this does not change how PROVIDE assignments are evaluated. Why do you think it would cause issues with PROVIDE?


if (CurModule.getPrinter()->traceAssignments())
trace(llvm::outs());
return true;
Expand Down
14 changes: 13 additions & 1 deletion lib/Script/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "eld/Core/LinkerScript.h"
#include "eld/Core/Module.h"
#include "eld/Readers/ELFSection.h"
#include "eld/Script/Assignment.h"
#include "eld/Script/ScriptFile.h"
#include "eld/Support/MsgHandling.h"
#include "eld/Support/Utils.h"
Expand Down Expand Up @@ -133,10 +134,17 @@ bool Symbol::hasDot() const {
}

eld::Expected<uint64_t> Symbol::evalImpl() {

if (!ThisSymbol)
ThisSymbol = ThisModule.getNamePool().findSymbol(Name);

if (!SourceAssignment && ThisSymbol->resolveInfo()->isAbsolute()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be isScriptDefined() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think isScriptDefined would work as well. Is there any case where an absolute symbol may not be script defined?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use assembly using .set

auto &Backend = ThisModule.getBackend();
const auto *A = Backend.getLatestAssignment(Name);
if (!A)
A = ThisModule.getAssignmentForSymbol(Name);
SourceAssignment = A;
}

if (!ThisSymbol || ThisSymbol->resolveInfo()->isUndef() ||
ThisSymbol->resolveInfo()->isBitCode())
return std::make_unique<plugin::DiagnosticEntry>(
Expand All @@ -152,6 +160,10 @@ eld::Expected<uint64_t> Symbol::evalImpl() {
"using a symbol that points to a non allocatable section!");
return Section->addr() + FragRef->getOutputOffset(ThisModule);
}
if (hasDot())
return ThisSymbol->value();
if (SourceAssignment)
return SourceAssignment->value();
return ThisSymbol->value();
}

Expand Down
1 change: 1 addition & 0 deletions lib/Target/GNULDBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3100,6 +3100,7 @@ bool GNULDBackend::layout() {
return false;
}

// FIXME: Adding more symbols this late can cause layout issues.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic symbols are defined before layout, why would this cause issue ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are defining these symbols after the layout is performed, right? The layout is performed above this, at line 3079, in the relax function call.

{
eld::RegisterTimer T("Define Magic Symbols", "Establish Layout",
m_Module.getConfig().options().printTimingStats());
Expand Down
Loading