Skip to content

[NFC] Fix undefined behavior with misaligned write#920

Merged
quic-seaswara merged 2 commits intoqualcomm:mainfrom
namikukr-qc:misaligned_ubsan
Mar 16, 2026
Merged

[NFC] Fix undefined behavior with misaligned write#920
quic-seaswara merged 2 commits intoqualcomm:mainfrom
namikukr-qc:misaligned_ubsan

Conversation

@namikukr-qc
Copy link
Copy Markdown
Contributor

@namikukr-qc namikukr-qc commented Mar 6, 2026

in emitGroup, there's an integer-sized write that triggers a sanitizer error (writing to an int-sized slot that isn't 4-byte aligned). This patch removes that and uses memcpy instead, to avoid the strict aliasing violation.

The pointer is shifted by Index * sizeof(llvm::ELF::Elf32_Word), which should make sure nothing changes functionally.

Comment thread lib/Writers/ELFObjectWriter.cpp Outdated
Copy link
Copy Markdown
Member

@lenary lenary left a comment

Choose a reason for hiding this comment

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

LGTM

in emitGroup, there's an integer-sized write that triggers
a sanitizer error (writing to an int-sized slot that isn't
4-byte aligned). This patch hacks around the warning by copying to
a uint8_t *, not considered misaligned.

The pointer is shifted by Index * sizeof(uint32_t), which should
make sure nothing changes functionally.

Signed-off-by: Namish Kukreja <namikukr@qti.qualcomm.com>
Signed-off-by: Namish Kukreja <namikukr@qti.qualcomm.com>
@quic-seaswara quic-seaswara merged commit f499b10 into qualcomm:main Mar 16, 2026
3 checks passed
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