ldso: check for DYNAMIC segment in ELF files

If the DYNAMIC segment cannot be located the ELF file may be statically
linked. In this case an error is raised.

Fixes #3000
This commit is contained in:
Sebastian Sumpf 2018-09-26 13:47:04 +02:00 committed by Christian Helmuth
parent a8ed11e75b
commit 0cc87d3c85

View File

@ -183,9 +183,13 @@ struct Linker::Elf_file : File
*/
void loadable_segments(Phdr &result)
{
bool dynamic = false;
for (unsigned i = 0; i < phdr.count; i++) {
Elf::Phdr *ph = &phdr.phdr[i];
if (ph->p_type == PT_DYNAMIC)
dynamic = true;
if (ph->p_type != PT_LOAD)
continue;
@ -196,6 +200,16 @@ struct Linker::Elf_file : File
result.phdr[result.count++] = *ph;
}
/*
* Check for 'DYNAMIC' segment which should be present in all dynamic ELF
* files.
*/
if (!dynamic) {
error("LD: ELF without DYNAMIC segment appears to be statically linked ",
"(ld=\"no\")");
throw Incompatible();
}
}
bool is_rx(Elf::Phdr const &ph) {