Skip to content

[lld][Xtensa] Apply the in-place addend for R_XTENSA_32#130

Open
MabezDev wants to merge 1 commit into
espressif:release/esp_21.xfrom
MabezDev:xtensa-r32-inplace-addend
Open

[lld][Xtensa] Apply the in-place addend for R_XTENSA_32#130
MabezDev wants to merge 1 commit into
espressif:release/esp_21.xfrom
MabezDev:xtensa-r32-inplace-addend

Conversation

@MabezDev
Copy link
Copy Markdown

R_XTENSA_32 is a partial_inplace relocation — the GNU Xtensa assembler stores the addend in the relocated word and leaves the RELA addend at 0. LLD's write32le(loc, val) dropped it, so every R_XTENSA_32 with a nonzero addend resolved wrong.

This surfaced linking the precompiled Espressif Wi-Fi blobs: ppTask's switch jump table is 30 R_XTENSA_32 relocations against the .wifi0iram.8 section symbol with the addends stored in-place. LLD collapsed all 30 to the section base, so the wifi task jumped into a literal pool and hit an illegal instruction on first dispatch; GNU ld links the same objects fine.

Adding the in-place contents back fixes it (verified by relinking — the jump table now holds the correct in-section targets and the device boots wifi). Objects from the LLVM Xtensa backend keep the addend in the RELA entry and zero the field, so this is a no-op for them.

R_XTENSA_32 is a partial_inplace relocation: the GNU Xtensa assembler
stores the addend in the relocated word and leaves the RELA addend at 0.
A plain write32le(loc, val) dropped that addend, miscomputing every
R_XTENSA_32 with a nonzero addend -- e.g. the switch jump tables in the
precompiled Espressif Wi-Fi blobs, which collapsed to a section base and
crashed at runtime. GNU ld links the same objects correctly.

Add the existing contents back. Objects from the LLVM Xtensa backend keep
the addend in the RELA entry and zero the field, so this adds 0 for them.
@gerekon
Copy link
Copy Markdown
Collaborator

gerekon commented May 18, 2026

There is upstream PR for fixing relocations problems in llvm-dwarfdump. If I am not wrong it implements more generic solution as it is done for other archs (like RISCV). https://github.com/llvm/llvm-project/pull/96311/changes#diff-6e0a2b728c59243bf6f8529874b37e676b6a2f6eca89407e2a6cf3078e82ed05R329.

Could you try that? If it works for you I think we can pickup it and ping the author if he is going to finish with it.
cc @andreisfr @sstefan1

@sstefan1
Copy link
Copy Markdown
Collaborator

There is upstream PR for fixing relocations problems in llvm-dwarfdump. If I am not wrong it implements more generic solution as it is done for other archs (like RISCV). https://github.com/llvm/llvm-project/pull/96311/changes#diff-6e0a2b728c59243bf6f8529874b37e676b6a2f6eca89407e2a6cf3078e82ed05R329.

Could you try that? If it works for you I think we can pickup it and ping the author if he is going to finish with it. cc @andreisfr @sstefan1

Agreed.

@MabezDev
Copy link
Copy Markdown
Author

Not sure when I can get to this, I'll likely use this patch until I can test the upstream one.

@gerekon
Copy link
Copy Markdown
Collaborator

gerekon commented May 21, 2026

Not sure when I can get to this, I'll likely use this patch until I can test the upstream one.

Ok. We will ping the author or maybe try to finish it ourselves

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.

3 participants