Skip to content

[lld] Only report "unable to move location counter backward" error for the last run to assignAddresses #66840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions lld/ELF/LinkerScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ void LinkerScript::expandOutputSection(uint64_t size) {
void LinkerScript::setDot(Expr e, const Twine &loc, bool inSec) {
uint64_t val = e().getValue();
if (val < dot && inSec)
error(loc + ": unable to move location counter backward for: " +
state->outSec->name);
lastSectionWithBackwardsCounter = state->outSec;

// Update to location counter means update to section size.
if (inSec)
Expand Down Expand Up @@ -1327,6 +1326,7 @@ LinkerScript::AddressState::AddressState() {
// Returns a symbol that has changed its section or value, or nullptr if no
// symbol has changed.
const Defined *LinkerScript::assignAddresses() {
lastSectionWithBackwardsCounter = nullptr;
if (script->hasSectionsCommand) {
// With a linker script, assignment of addresses to headers is covered by
// allocateHeaders().
Expand Down
4 changes: 4 additions & 0 deletions lld/ELF/LinkerScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ class LinkerScript final {

// Sections that will be warned/errored by --orphan-handling.
SmallVector<const InputSectionBase *, 0> orphanSections;

// If assignAddress() at any point caused the location counter to move
// backwards, this will point to the section where this occured.
OutputSection *lastSectionWithBackwardsCounter = nullptr;
};

LLVM_LIBRARY_VISIBILITY extern std::unique_ptr<LinkerScript> script;
Expand Down
7 changes: 7 additions & 0 deletions lld/ELF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,13 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
}
}
}

if (script->lastSectionWithBackwardsCounter) {
error(script->lastSectionWithBackwardsCounter->location +
": unable to move location counter backward for: " +
script->lastSectionWithBackwardsCounter->name);
}

if (!config->relocatable && config->emachine == EM_RISCV)
riscvFinalizeRelax(pass);

Expand Down