This is an archive of the discontinued LLVM Phabricator instance.

[Object/ELF] - Do section header sh_offset/sh_size values check once during object loading.
AbandonedPublic

Authored by grimar on Oct 6 2016, 5:19 AM.

Details

Reviewers
davide
rafael
Summary

This helps to keep client code cleaner.
For example we have next code in LLD:

auto *Begin =
    reinterpret_cast<const Elf_Dyn *>(Obj.base() + DynamicSec->sh_offset);
const Elf_Dyn *End = Begin + DynamicSec->sh_size / sizeof(Elf_Dyn);

sh_offset and/or sh_size may be broken here and the same situation can be found for some other sections.
Instead of placing multiple checks in LLD, I suggest this change to check object once during loading.

Diff Detail

Event Timeline

grimar updated this revision to Diff 73769.Oct 6 2016, 5:19 AM
grimar retitled this revision from to [Object/ELF] - Do section header sh_offset/sh_size values check once during object loading..
grimar updated this object.
grimar added reviewers: rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.
rafael requested changes to this revision.Oct 6 2016, 5:35 AM
rafael edited edge metadata.

I don't think we should do this. Eagerly checking for errors means that a program would be unable to look at the file even if it is not hitting that particular corruption.

For example, at some point llvm-readobj should be able to just report a broken section offset and keep going. This makes it impossible.

Looks like what is needed is a dyns() function that return a Elf_Dyn range. Maybe implement it with a template so that rels() relas() can share the code?

This revision now requires changes to proceed.Oct 6 2016, 5:35 AM
grimar abandoned this revision.Oct 6 2016, 8:13 AM

D25327 solves the problem of dynamic section size instead.