Any data added to a section needs to be aligned in accordance with the
section's sh_addralign value.  Particularly strings added to a .str1.8
section.  Otherwise you may get some funky strings.

Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing 
object files")
Signed-off-by: Josh Poimboeuf <[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..3da90686350d 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_addralign;
 
        offset = ALIGN(sec->sh.sh_size, sec->sh.sh_addralign);
        sec->sh.sh_size = offset + size;
-- 
2.53.0


Reply via email to