Skip to content

Commit df968c9

Browse files
petrvandrovecIngo Molnar
authored andcommitted
objtool: Do not retrieve data from empty sections
Binutils 2.29-9 in Debian return an error when elf_getdata is invoked on empty section (.note.GNU-stack in all kernel files), causing immediate failure of kernel build with: elf_getdata: can't manipulate null section As nothing is done with sections that have zero size, just do not retrieve their data at all. Signed-off-by: Petr Vandrovec <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/2ce30a44349065b70d0f00e71e286dc0cbe745e6.1505459652.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar <[email protected]>
1 parent 0998b7a commit df968c9

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

tools/objtool/elf.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,20 @@ static int read_sections(struct elf *elf)
175175
return -1;
176176
}
177177

178-
sec->data = elf_getdata(s, NULL);
179-
if (!sec->data) {
180-
WARN_ELF("elf_getdata");
181-
return -1;
182-
}
183-
184-
if (sec->data->d_off != 0 ||
185-
sec->data->d_size != sec->sh.sh_size) {
186-
WARN("unexpected data attributes for %s", sec->name);
187-
return -1;
178+
if (sec->sh.sh_size != 0) {
179+
sec->data = elf_getdata(s, NULL);
180+
if (!sec->data) {
181+
WARN_ELF("elf_getdata");
182+
return -1;
183+
}
184+
if (sec->data->d_off != 0 ||
185+
sec->data->d_size != sec->sh.sh_size) {
186+
WARN("unexpected data attributes for %s",
187+
sec->name);
188+
return -1;
189+
}
188190
}
189-
190-
sec->len = sec->data->d_size;
191+
sec->len = sec->sh.sh_size;
191192
}
192193

193194
/* sanity check, one more call to elf_nextscn() should return NULL */

0 commit comments

Comments
 (0)