Skip to content

Ensure builtin binaries are aligned to ibf_header #13073

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

Conversation

Gelbpunkt
Copy link

@Gelbpunkt Gelbpunkt commented Apr 5, 2025

The builtin_binary buffers are cast to ibf_header later, but may not be aligned to the necessary boundaries. In particular, Ruby was crashing for me on ARMv7 + musl with LLVM 19.1.7 because it was not aligned to the 4-byte boundary, resulting in SIGBUS when dereferencing the header.

https://godbolt.org/z/ss8WeE88c

The `builtin_binary` buffers are cast to `ibf_header` later, but may not
be aligned to the necessary boundaries (in this case, 4 bytes).

Signed-off-by: Jens Reidel <adrian@travitia.xyz>
static const unsigned char <%= feature %>_bin[] = {
#include "compile.h"

static const unsigned char <%= feature %>_bin[] __attribute__((aligned(alignof(struct ibf_header)))) = {
Copy link
Member

Choose a reason for hiding this comment

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

This is non-portable clearly.

Copy link
Author

Choose a reason for hiding this comment

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

It works with GCC and Clang. It doesn't with MSVC, I guess I can come up with a way that will also work with MSVC. Is there any other compiler I need to be aware of?

@nobu
Copy link
Member

nobu commented Apr 6, 2025

IBF dump string size should be multiple of 4 always.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants