On Tue, Feb 17, 2026 at 11:14:17AM -0500, Joe Lawrence wrote:
> On Tue, Feb 17, 2026 at 11:06:32AM -0500, Joe Lawrence wrote:
> > When adding data to an SHF_MERGE section, set the Elf_Data d_align to
> > the section's sh_addralign so libelf aligns entries within the section.
> > This ensures that entry offsets are consistent with previously calculated
> > relocation addends.
> >
> > Fixes: 431dbabf2d9d ("objtool: Add elf_create_data()")
> > Signed-off-by: Joe Lawrence <[email protected]>
> > ---
> > tools/objtool/elf.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
> > index 2c02c7b49265..bd6502e7bdc0 100644
> > --- a/tools/objtool/elf.c
> > +++ b/tools/objtool/elf.c
> > @@ -1375,7 +1375,7 @@ void *elf_add_data(struct elf *elf, struct section
> > *sec, const void *data, size_
> > memcpy(sec->data->d_buf, data, size);
> >
> > sec->data->d_size = size;
> > - sec->data->d_align = 1;
> > + sec->data->d_align = (sec->sh.sh_flags & SHF_MERGE) ?
> > sec->sh.sh_addralign : 1;
> >
> > offset = ALIGN(sec->sh.sh_size, sec->sh.sh_addralign);
> > sec->sh.sh_size = offset + size;
> > --
> > 2.53.0
> >
> >
>
> This one stretches my ELF internals knowledge a bit, is ^^ true or
> should we rely on the section ".str1.8" suffix to indicate internal
> alignment?
I hit the same issue in my testing for the klp-build arm64 port, I think
it can be simplified to the below?
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
@@ -1375,7 +1382,7 @@ void *elf_add_data(struct elf *elf, struct section *sec,
const void *data, size_
memcpy(sec->data->d_buf, data, size);
sec->data->d_size = size;
- sec->data->d_align = 1;
+ sec->data->d_align = sec->sh.sh_addralign;
offset = ALIGN(sec->sh.sh_size, sec->sh.sh_addralign);
sec->sh.sh_size = offset + size;