diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-10-09 03:02:35 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-10-09 03:02:35 -0400 |
commit | 1236d6bb6e19fc72ffc6bbcdeb1bfefe450e54ee (patch) | |
tree | 47da3feee8e263e8c9352c85cf518e624be3c211 /tools/objtool/elf.c | |
parent | 750b1a6894ecc9b178c6e3d0a1170122971b2036 (diff) | |
parent | 8a5776a5f49812d29fe4b2d0a2d71675c3facf3f (diff) |
Merge 4.14-rc4 into staging-next
We want the staging/iio fixes in here as well to handle merge issues.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools/objtool/elf.c')
-rw-r--r-- | tools/objtool/elf.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 6e9f980a7d26..24460155c82c 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c | |||
@@ -175,19 +175,20 @@ static int read_sections(struct elf *elf) | |||
175 | return -1; | 175 | return -1; |
176 | } | 176 | } |
177 | 177 | ||
178 | sec->data = elf_getdata(s, NULL); | 178 | if (sec->sh.sh_size != 0) { |
179 | if (!sec->data) { | 179 | sec->data = elf_getdata(s, NULL); |
180 | WARN_ELF("elf_getdata"); | 180 | if (!sec->data) { |
181 | return -1; | 181 | WARN_ELF("elf_getdata"); |
182 | } | 182 | return -1; |
183 | 183 | } | |
184 | if (sec->data->d_off != 0 || | 184 | if (sec->data->d_off != 0 || |
185 | sec->data->d_size != sec->sh.sh_size) { | 185 | sec->data->d_size != sec->sh.sh_size) { |
186 | WARN("unexpected data attributes for %s", sec->name); | 186 | WARN("unexpected data attributes for %s", |
187 | return -1; | 187 | sec->name); |
188 | return -1; | ||
189 | } | ||
188 | } | 190 | } |
189 | 191 | sec->len = sec->sh.sh_size; | |
190 | sec->len = sec->data->d_size; | ||
191 | } | 192 | } |
192 | 193 | ||
193 | /* sanity check, one more call to elf_nextscn() should return NULL */ | 194 | /* sanity check, one more call to elf_nextscn() should return NULL */ |
@@ -508,6 +509,7 @@ struct section *elf_create_rela_section(struct elf *elf, struct section *base) | |||
508 | strcat(relaname, base->name); | 509 | strcat(relaname, base->name); |
509 | 510 | ||
510 | sec = elf_create_section(elf, relaname, sizeof(GElf_Rela), 0); | 511 | sec = elf_create_section(elf, relaname, sizeof(GElf_Rela), 0); |
512 | free(relaname); | ||
511 | if (!sec) | 513 | if (!sec) |
512 | return NULL; | 514 | return NULL; |
513 | 515 | ||
@@ -561,6 +563,7 @@ int elf_write(struct elf *elf) | |||
561 | struct section *sec; | 563 | struct section *sec; |
562 | Elf_Scn *s; | 564 | Elf_Scn *s; |
563 | 565 | ||
566 | /* Update section headers for changed sections: */ | ||
564 | list_for_each_entry(sec, &elf->sections, list) { | 567 | list_for_each_entry(sec, &elf->sections, list) { |
565 | if (sec->changed) { | 568 | if (sec->changed) { |
566 | s = elf_getscn(elf->elf, sec->idx); | 569 | s = elf_getscn(elf->elf, sec->idx); |
@@ -568,13 +571,17 @@ int elf_write(struct elf *elf) | |||
568 | WARN_ELF("elf_getscn"); | 571 | WARN_ELF("elf_getscn"); |
569 | return -1; | 572 | return -1; |
570 | } | 573 | } |
571 | if (!gelf_update_shdr (s, &sec->sh)) { | 574 | if (!gelf_update_shdr(s, &sec->sh)) { |
572 | WARN_ELF("gelf_update_shdr"); | 575 | WARN_ELF("gelf_update_shdr"); |
573 | return -1; | 576 | return -1; |
574 | } | 577 | } |
575 | } | 578 | } |
576 | } | 579 | } |
577 | 580 | ||
581 | /* Make sure the new section header entries get updated properly. */ | ||
582 | elf_flagelf(elf->elf, ELF_C_SET, ELF_F_DIRTY); | ||
583 | |||
584 | /* Write all changes to the file. */ | ||
578 | if (elf_update(elf->elf, ELF_C_WRITE) < 0) { | 585 | if (elf_update(elf->elf, ELF_C_WRITE) < 0) { |
579 | WARN_ELF("elf_update"); | 586 | WARN_ELF("elf_update"); |
580 | return -1; | 587 | return -1; |