Commit 356e4b2f authored by Josh Poimboeuf's avatar Josh Poimboeuf
Browse files

objtool: Fix data alignment in elf_add_data()

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: dd590d4d ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Link: https://patch.msgid.link/d962fc0ca24fa0825cca8dad71932dccdd9312a9.1772681234.git.jpoimboe@kernel.org


Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@kernel.org>
parent 32234049
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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;