Skip to content

[linker-script] Error when dot assignment exceeds UINT32_MAX#1116

Open
deepakshirkem wants to merge 1 commit into
qualcomm:mainfrom
deepakshirkem:fix/dot-assignment-overflow-386-v2
Open

[linker-script] Error when dot assignment exceeds UINT32_MAX#1116
deepakshirkem wants to merge 1 commit into
qualcomm:mainfrom
deepakshirkem:fix/dot-assignment-overflow-386-v2

Conversation

@deepakshirkem
Copy link
Copy Markdown
Contributor

Problem

Fixes #386

ELD assigns incorrect addresses when the padding due to dot assignment is greater than UINT32_MAX. When a linker script uses: . = . + 0x400000000;

Fix

Added validation in Assignment::assign() to error out when dot assignment creates padding that exceeds UINT32_MAX
as such large padding values are not meaningful.

Testing

Added test DotAssignmentOverflow that verifies ELD emits a clear error when dot assignment value exceeds UINT32_MAX.

cc @quic-seaswara @parth-07

@parth-07
Copy link
Copy Markdown
Contributor

parth-07 commented May 6, 2026

Hi @deepakshirkem,

Thank you for the pull-request. The original issue does not state that we should error-out if the padding due to dot assignment is greater than UINT32_MAX, instead it is about the symbol values being incorrect when there is a huge padding. Erroring out when there is a huge padding is a workaround and not a fix for this issue. The huge padding in the original issue can be replaced by any other huge-content that takes up space in the image layout and we will still see the same issue.

@deepakshirkem
Copy link
Copy Markdown
Contributor Author

Hi @parth-07,
I have implemented the root cause fix in PR #1108 by changing uint32_t → uint64_t for Fragment::UnalignedOffset to correctly handle 64-bit offsets. Could you please confirm if this approach is correct? If so, I can implement that fix into this PR.

Copy link
Copy Markdown
Contributor

@parth-07 parth-07 left a comment

Choose a reason for hiding this comment

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

I have implemented the root cause fix in PR #1108 by changing uint32_t → uint64_t for Fragment::UnalignedOffset

PR #1108 has the right approach but we cannot implement that because of the memory overhead that it may cause. In a large build, there are a LOT of fragments. Increasing the offset size from 4 bytes to 8 bytes does not offer much benefits to justify the memory overhead. @quic-seaswara Do you think we should report error if the dot assignment causes padding greater than UINT32_MAX as this PR is doing?

Comment thread lib/Script/Assignment.cpp
if (isDot() && Section) {
LDSymbol *DotSym = CurModule.getNamePool().findSymbol(".");
if (DotSym && ExpressionValue > DotSym->value()) {
uint64_t Padding = ExpressionValue - DotSym->value();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will not report the error if ExpressionValue < DotSym->value() but the difference between the two is still greater than UINT32_MAX.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will reproduce this issue and update the check.

ELD was silently truncating dot assignment values greater
than UINT32_MAX causing incorrect section addresses.

Added error when dot assignment creates padding that exceeds
UINT32_MAX as such large padding values are not valid.

Fixes qualcomm#386

Signed-off-by: deepakshirkem <deepakshirke509@gmail.com>
@deepakshirkem deepakshirkem force-pushed the fix/dot-assignment-overflow-386-v2 branch from 9d8f4c3 to 5a3bee1 Compare May 14, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect address when the padding due to dot assignment is greater than UINT_MAX

2 participants